sh-realpath icon indicating copy to clipboard operation
sh-realpath copied to clipboard

Canonicalize missing directories

Open rrva opened this issue 10 years ago • 2 comments

realpath does not offer emulation for the equivalent of readlink -m. Running realpath on a non-existent directory returns an empty string.

From http://www.gnu.org/software/coreutils/manual/html_node/readlink-invocation.html#readlink-invocation

‘-m’ ‘--canonicalize-missing’ Activate canonicalize mode. If any component is missing or unavailable, readlink treats it as a directory.

rrva avatar Nov 27 '15 09:11 rrva

Test suite:

http://www.delorie.com/gnu//dl/ftp.gnu.org/coreutils/coreutils-8.2.tar.gz/coreutils-8.2/tests/readlink/can-m

rrva avatar Nov 27 '15 11:11 rrva

:+1: here, this is what I came here expecting!

Specifically, it'd be nice if the realpath mode (and specifically canonicalize_path) handled missing paths. At the moment, the behaviour is … rather strange:

$ _canonicalize_file_path blah
/current/working/directory/blah
$ _canonicalize_file_path /blah
//blah
$ _canonicalize_file_path /blah/wtf
<erroneous exit code: 1>

ELLIOTTCABLE avatar Mar 29 '16 11:03 ELLIOTTCABLE