[gambit-list] checking for dangling symlink without raising an exception

Marc Feeley feeley at iro.umontreal.ca
Wed Jan 11 16:28:15 EST 2006


On 11-Jan-06, at 2:16 PM, Thomas Hafner wrote:

> Is it possible to check for a symlink without raising an exception,
> even if the symling is dangling?
>
> I think not, because:
> - file-exists? cannot be used to check, because it evaluates to #f in
>   case of a dangling symlink.
> - file-info cannot be used to check, because it raises an exception,
>   if there's nothing.
>
> Here's an example:
>
> (create-symbolic-link "/doesnotexist" "~/dangling")
> ;; worked, the symlink has been created.
>
> (file-exists? "~/dangling")
> ;; evaluates to #f.
>
> (create-symbolic-link "/anotherplace" "~/dangling")
> ;; ERROR: File exists.
>
> (file-info "~/dangling")
> ;; ERROR: No such file or directory.
>
> (file-info "~/dangling" #f)
> ;; Ok, informs about the symlink.
>
> (delete-file "~/dangling")
> (file-info "~/dangling" #f)
> ;; ERROR: No such file or directory.
>
> I think it would be nice, if file-exists? had also an optional
> parameter ``CHASE?'' like file-info has.

Not impossible because you could catch the exception from file-info.   
Inconvenient yes, so I have added a chase? optional parameter to file- 
exists? .

Marc




More information about the Gambit-list mailing list