pathlispcommon-lisp

make-pathname and pathname-directory - drive information loss in windows


I have a question, whether this is intended by the language or whether this is kind of an unexpected/unwanted behavior/ BUG in Common Lisp.

However, I observed it in both: CLISP and SBCL:

I thought,

(make-pathname :directory (pathname-directory my-directory-path))

is/should be complimentary in all OS.

In Linux and MacOS it is.

But in Windows, you loose the information about the drive letter:

(pathname-directory #P"C:/Users/me/test/")
;;=> (:ABSOLUTE "Users" "me" "test")   ;;=> Drive letter "c:" is lost!

Whereas, if you use ~, you can keep it.

(pathname-directory #P"~/test/")
;;=> (:ABSOLUTE :HOME "test")
(make-pathname :directory (pathname-directory #P"~/test/"))
;;=> #P"~/test/"   ;; no information loss!

(make-pathname :directory (pathname-directory #P"c:/Users/me/test/"))
;;=> #P"/Users/me/test/" ;;=> information loss - and not only that
;; it became an invalid path now, since the drive letter is lost!

Isn't this actually a bug in the language specification? (Because Windows was not existent or such?).


Solution

  • Unix doesn't have anything analogous to drive letters, so it doesn't make sense to say that this is retained on Unix.

    I'd expect the driver letter to correspond to the device field in CL pathnames. So you need to copy that as well:

    (MAKE-PATHNAME :directory (pathname-directory my-directory-path)
                   :device (pathname-device my-directory-path))