Neil Lindquist neillindquist5@gmail.com writes:
Hello,
I recently noticed that uiop's DIRECTORY-FILES does not ensure that the path is always interpreted as a directory. On sbcl (and presumably other implementations), if the path does not have a trailing slash, the files in the parent directory are instead returned. This does not appear to be the indented behavior, given that SUBDIRECTORIES ensures that the path is a directory.
May as well also do that for uiop:with-current-directory. I've attached a diff, and have a test case below
Test case: (uiop:with-current-directory ("/home/user") (run-program "ls" :output t))
Behaviour is simiar to DIRECTORY-FILES. ;=> Current: lists my /home dir ;=> With diff: lists my /home/user dir
~~~~~~~~~~ DIFF ~~~~~~~~~~~~~
498c498 < `(call-with-current-directory ,dir #'(lambda () ,@body)))) ---
`(call-with-current-directory (ensure-directory-pathname ,dir) #'(lambda
() ,@body))))
Coleslaw has been using a similar version of the above for awhile.
A patch for this new behavior and current/proposed results are below. ## Patch ## --- a/uiop/filesystem.lisp +++ b/uiop/filesystem.lisp @@ -209,7 +209,7 @@ Subdirectories should NOT be returned. override the default at your own risk. DIRECTORY-FILES tries NOT to resolve symlinks if the implementation permits this, but the behavior in presence of symlinks is not portable. Use IOlib to handle such situations."
- (let ((dir (pathname directory)))
- (let ((dir (ensure-directory-pathname directory)))) (when (logical-pathname-p dir) ;; Because of the filtering we do below, ;; logical pathnames have restrictions on wild patterns.
-- Spenser Truex usenet@spensertruex.com https://spensertruex.com/ San Francisco, USA