uiop:directory-files doesn't behave on paths without a trailing slash

Spenser Truex web at spensertruex.com
Tue Jun 25 05:26:11 UTC 2019


Neil Lindquist <neillindquist5 at 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 () , at body))))
---
>     `(call-with-current-directory (ensure-directory-pathname ,dir) #'(lambda
> () , at 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 at spensertruex.com
https://spensertruex.com/
San Francisco, USA



More information about the asdf-devel mailing list