DIRECTORY loses when *DEFAULT-PATHNAME-DEFAULTS* has a non-NIL name, type.

Bug #1740563 reported by Richard M Kreuter on 2017-12-30
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

DIRECTORY loses in various ways when *DEFAULT-PATHNAME-DEFAULTS* is a pathname whose name or type field is not NIL. Here are some examples:

$ sh ./ --no-userinit --no-sysinit
(running SBCL from: .)
This is SBCL, an implementation of ANSI Common Lisp.
More information about SBCL is available at <>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (ensure-directories-exist "/tmp/dir/" :verbose t)

creating directory: /tmp/dir/
* (close (open "/tmp/dir/a.txt" :if-does-not-exist :create))

* (close (open "/tmp/dir/b.lisp" :if-does-not-exist :create))

* (directory "/tmp/dir/*.*")

(#P"/private/tmp/dir/a.txt" #P"/private/tmp/dir/b.lisp") ;so far, so good
* (setq *default-pathname-defaults* #p"/tmp/dir/a.txt") ;here comes trouble

* (directory #p"/tmp/dir/*.*")

* (setq *default-pathname-defaults* (make-pathname :name nil :defaults #p"/tmp/dir/a.txt"))

#<PATHNAME (with no namestring)
           :HOST #<SB-IMPL::UNIX-HOST {10000F4C53}>
           :DEVICE NIL
           :DIRECTORY (:ABSOLUTE "tmp" "dir")
           :NAME NIL
           :TYPE "txt"
           :VERSION :NEWEST>
* (directory #p"/tmp/dir/*.*")

debugger invoked on a SB-KERNEL:NO-NATIVE-NAMESTRING-ERROR in thread
#<THREAD "main thread" RUNNING {1001968083}>:
  The pathname
  #<PATHNAME (with no namestring)
             :HOST #<SB-IMPL::UNIX-HOST {10000F4C53}>
             :DEVICE NIL
             :DIRECTORY (:ABSOLUTE "tmp" "dir")
             :NAME NIL
             :TYPE "txt"
             :VERSION :NEWEST>
  does not have a native namestring because
  there is a :TYPE component but no :NAME component

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit debugger, returning to top level.

(SB-KERNEL:NO-NATIVE-NAMESTRING-ERROR #<PATHNAME (with no namestring) :HOST #<SB-IMPL::UNIX-HOST {10000F4C53}> :DEVICE NIL :DIRECTORY (:ABSOLUTE "tmp" "dir") :NAME NIL :TYPE "txt" :VERSION :NEWEST> "there is a ~S component but no ~S component" :TYPE :NAME)
0] :abort

* (setq *default-pathname-defaults* (make-pathname :type nil :defaults #p"/tmp/dir/a.txt"))

* (directory #p"/tmp/dir/*.*")


I expected DIRECTORY to return the same list of two pathnames in all cases.

One way of looking at the problem is that the internals of DIRECTORY parses directories into pathnames in "as-directory" form (i.e., the form where the name, type, and version are NIL), and so any operation that merges those directories when *DEFAULT-PATHNAME-DEFAULTS* isn't in as-directory form will pick up the default pathname's name and type. The attached patch does some surgery on those internals so that DIRECTORY's accesses to the file system bypass merging, and adds a regression test for such cases. (This isn't the most elegant way to solve this problem, but I think it's the minimal change that'll do it. I find the implementation of DIRECTORY a hard to grok in the details.)

Other requested info:

$ uname -a
Darwin m5.localdomain 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64

* *features*


Jan Moringen (scymtym) on 2017-12-31
Changed in sbcl:
assignee: nobody → Jan Moringen (scymtym)
status: New → Confirmed
importance: Undecided → Medium
Jan Moringen (scymtym) on 2017-12-31
Changed in sbcl:
status: Confirmed → Fix Committed
assignee: Jan Moringen (scymtym) → nobody
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers