Opened 10 years ago

Closed 10 years ago

#52 closed defect (fixed)

##sys#expand-home-path bug on OS X

Reported by: Jim Ursetto Owned by: felix winkelmann
Priority: minor Milestone:
Component: core libraries Version: 4.0.x
Keywords: Cc:
Estimated difficulty:

Description

Plain tilde does not work properly. Did not check any other platform yet. Pretty sure this has been present forever.

#;2> (##sys#expand-home-path "~/tmp")
"/Users/jim/tmp"
#;3> (##sys#expand-home-path "~/")
"/Users/jim/"
#;4> (##sys#expand-home-path "~")
"/home/"

Also affects derived procedures e.g.

#;3> (change-directory "~/tmp")
#;4> (change-directory "~")
Error: (change-directory) cannot change current directory - No such file or directory: "~"

Attachments (1)

tilde-expander.diff.txt (5.9 KB) - added by Jim Ursetto 10 years ago.
patch to svn trunk

Download all attachments as: .zip

Change History (5)

comment:1 Changed 10 years ago by Jim Ursetto

OK, I see this is done to support ~user -> /home/user, which can't be done reliably without getpwnam(3).

I would be satisfied with the simple fix of "~" -> (getenv "HOME"), while leaving "~user" broken, in ##sys#expand-home-path. As you probably wish to avoid a getpwnam call in library.scm.

However, the posix unit should really have its own expansion code used by change-directory etc., which uses getpwnam / getpwuid for tilde expansion.

I could produce a patch if you are interested.

comment:2 Changed 10 years ago by Jim Ursetto

Attached an attempt at fixing this. Creates a new parameter ##sys#tilde-expander used by ##sys#expand-home-path which, by default, just checks $HOME, but when the posixunix unit is loaded, will use either $HOME or user-information. posixwin currently uses the default behavior. Also if tilde-expansion fails the original unexpanded text will be used. [Currently it will do ~/tmp -> /tmp if $HOME is unset].

I did not touch canonical-path, which is also broken (worse). It is a bit hairy but could piggyback on this.

expand-home-path fix example

$ echo $HOME
/Users/jim
$ csi
#;1> (##sys#expand-home-path "~")
"/Users/jim"
#;2> (##sys#expand-home-path "~jim")
"/home/jim"
#;3> (##sys#expand-home-path "~root")
"/home/root"
#;3> (##sys#expand-home-path "~/tmp")
"/Users/jim/tmp"
#;4> (use posix)
; loading library posix ...
#;5> (##sys#expand-home-path "~")
"/Users/jim"
#;6> (##sys#expand-home-path "~jim")
"/Users/jim"
#;7> (##sys#expand-home-path "~/tmp")
"/Users/jim/tmp"
#;10> (##sys#expand-home-path "~root")
"/var/root"
#;11> (##sys#expand-home-path "~dummy")
"~dummy"
#;12> (unsetenv "HOME")
#;13> (##sys#expand-home-path "~")
"/Users/jim"
#;14> (setenv "HOME" "/dummy")
#;15> (##sys#expand-home-path "~/tmp")
"/dummy/tmp"

$ unset HOME; csi
#;1> (##sys#expand-home-path "~")
"~"
#;1> (##sys#expand-home-path "~/tmp")
"~/tmp"

Broken canonical-path example

#;2> (use posix)
#;3> (canonical-path "~")
"/Users/jim/~"
#;4> (canonical-path "~/")
"/Users/jim/"
#;8> (canonical-path "~jim")
"/Users/jim/~jim"
#;9> (canonical-path "~/tmp")
"/Users/jim/tmp"

Changed 10 years ago by Jim Ursetto

Attachment: tilde-expander.diff.txt added

patch to svn trunk

comment:3 Changed 10 years ago by felix winkelmann

Owner: set to felix winkelmann
Status: newassigned

comment:4 Changed 10 years ago by felix winkelmann

Resolution: fixed
Status: assignedclosed

"~user" was never officially supported - I can't remember, whether I added the "/home/" brokenness or not.

I will simply remove this feature - an initial "~" will expand into $HOME.
canonical-path will be folded into normalize-pathname and simplified later.

See commit r15118

Note: See TracTickets for help on using tickets.