From: Andreas F. <as...@bo...> - 2004-05-13 01:08:50
|
Hi, piso brought this up on #lisp: When deleting an empty directory with SBCL, it only gives an error message (the same that unlink("the/directory") would yield when done in C). It would make sense to delete the directory anyway, especially given that reasoning: <piso> PROBE-FILE in sbcl returns the truename of the directory, if you feed it the directory's pathname <piso> "probe-file returns false if there is no file named pathspec, and otherwise returns the truename of pathspec." <piso> since it returns true, there must be a file named pathspec <piso> so DELETE-FILE should work on that file, no? Of course, we can interpret the weasel words in DELETE-FILE's Exceptional Situations section such that we don't need to delete the directory, because deleting a directory is bound to fail; but I think we would be a bit more consistent that way. In the following patch, I assumed that we only want to delete the directory if what we were passed is a specifier for a directory (not a file). If that's a bad assumption, it should be pretty easy to change. Here's the patch (sans test case): --- orig/package-data-list.lisp-expr +++ mod/package-data-list.lisp-expr @@ -1835,6 +1835,7 @@ "UNIX-STAT" "UNIX-UID" "UNIX-UNLINK" "UNIX-WRITE" "WINSIZE" "WRITEGRP" "WRITEOTH" "WRITEOWN" "WS-COL" "WS-ROW" "WS-XPIXEL" "WS-YPIXEL" "WNOHANG" "WSTOPPED" "WUNTRACED" "W_OK" "X_OK" + "UNIX-RMDIR" ;; signals "SIGALRM" "SIGBUS" "SIGCHLD" "SIGCONT" "SIGEMT" "SIGFPE" --- orig/src/code/filesys.lisp +++ mod/src/code/filesys.lisp @@ -767,7 +767,11 @@ :pathname file :format-control "~S doesn't exist." :format-arguments (list file))) - (multiple-value-bind (res err) (sb!unix:unix-unlink namestring) + (multiple-value-bind (res err) + (funcall (if (null (pathname-name file)) + #'sb!unix:unix-rmdir + #'sb!unix:unix-unlink) + namestring) (unless res (simple-file-perror "couldn't delete ~A" namestring err)))) t) --- orig/src/code/unix.lisp +++ mod/src/code/unix.lisp @@ -383,6 +383,11 @@ (declare (type unix-pathname name)) (void-syscall ("unlink" c-string) name)) +;;; UNIX-RMDIR deletes a directory, which must be empty. +(defun unix-rmdir (name) + (declare (type unix-pathname name)) + (void-syscall ("rmdir" c-string) name)) + ;;; Return the name of the host machine as a string. (defun unix-gethostname () (with-alien ((buf (array char 256))) Good night, -- Andreas Fuchs, <as...@bo...>, as...@ja..., antifuchs |
From: Christophe R. <cs...@ca...> - 2004-05-20 11:21:38
|
Andreas Fuchs <as...@bo...> writes: > piso brought this up on #lisp: > > When deleting an empty directory with SBCL, it only gives an error > message (the same that unlink("the/directory") would yield when done > in C). It would make sense to delete the directory anyway, especially > given that reasoning: > > <piso> PROBE-FILE in sbcl returns the truename of the directory, if > you feed it the directory's pathname > <piso> "probe-file returns false if there is no file named pathspec, > and otherwise returns the truename of pathspec." > <piso> since it returns true, there must be a file named pathspec > <piso> so DELETE-FILE should work on that file, no? > > Of course, we can interpret the weasel words in DELETE-FILE's > Exceptional Situations section such that we don't need to delete the > directory, because deleting a directory is bound to fail; but I think > we would be a bit more consistent that way. That's at least plausible, yes. (This probably wants to be documented somewhere in the manual either way). > In the following patch, I assumed that we only want to delete the > directory if what we were passed is a specifier for a directory (not a > file). If that's a bad assumption, it should be pretty easy to change. So you say that (delete-file "/tmp") should try to delete the file, but (delete-file "/tmp/") should try to delete the directory? I suppose that's as plausible an interpretation as any. I say go for it, plus documentation. (and maybe a test case :-) Cheers, Christophe -- http://www-jcsu.jesus.cam.ac.uk/~csr21/ +44 1223 510 299/+44 7729 383 757 (set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b))) (defvar b "~&Just another Lisp hacker~%") (pprint #36rJesusCollegeCambridge) |
From: Nikodemus S. <tsi...@cc...> - 2004-05-20 12:16:05
|
On Thu, 20 May 2004, Christophe Rhodes wrote: > That's at least plausible, yes. (This probably wants to be documented > somewhere in the manual either way). I agree with the plausibility, but... > So you say that (delete-file "/tmp") should try to delete the file, > but (delete-file "/tmp/") should try to delete the directory? I > suppose that's as plausible an interpretation as any. Isn't that annoingly inconsistent with the way (truename "/tmp") returns #p"/tmp/"? I'd think that either (truenane "/tmp") should return the file #p"/tmp" (if one exists, of course) or (delete-file "/tmp") should try to delete the directory. The latter would be a smaller change and less likely to break tons of user code... but OTOH it seems that next release is a candidate for "The SBCL release most likely to break your code" award anyways, given the sb-grovel alienization. ;-) Cheers, -- Nikodemus |
From: Christophe R. <cs...@ca...> - 2004-05-20 13:14:11
|
Nikodemus Siivola <tsi...@cc...> writes: > On Thu, 20 May 2004, Christophe Rhodes wrote: > >> That's at least plausible, yes. (This probably wants to be documented >> somewhere in the manual either way). > > I agree with the plausibility, but... > >> So you say that (delete-file "/tmp") should try to delete the file, >> but (delete-file "/tmp/") should try to delete the directory? I >> suppose that's as plausible an interpretation as any. > > Isn't that annoingly inconsistent with the way (truename "/tmp") returns > #p"/tmp/"? I don't think so. I don't think delete-file should operate on the truename, because otherwise there's no way to remove symbolic links (or more generally any file whose truename is not itself). Of course, now someone is going to come along and say this is contrary to the specification... Cheers, Christophe -- http://www-jcsu.jesus.cam.ac.uk/~csr21/ +44 1223 510 299/+44 7729 383 757 (set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b))) (defvar b "~&Just another Lisp hacker~%") (pprint #36rJesusCollegeCambridge) |