"cd .." behaves wrong if last element in pwd is a symlink
Open3570244fffffffffffffffffffffffffffffffffCreated 14 years agoUpdated 44 days ago
Descriptionplain2012-09-20 21:26:59
If the last element of a the current path (pwd) is a symbolic link with a trailing slash the command cd .. does not change into the parent directory but stays in the current directory. In addition, when the link target is a relative path containing ".." or "." the pwd after "cd .." may require normalization. Related / possible duplicate of "cd .. from link in Windows confuses Tcl - ID: 3183016" bash> pwd /tmp/test bash> mkdir /tmp/dir bash> ln -sf /tmp/dir link_abs bash> tclsh % cd link_abs % pwd /tmp/test/link_abs % cd .. % pwd ;# ok we are in /tmp (/tmp/test would be also plausible) /tmp % exit bash> ln -sf /tmp/dir/ link_abs_trailing_slash bash> tclsh % cd link_abs_trailing_slash % pwd /tmp/test/link_abs_trailing_slash % cd .. ;# should cd to /tmp (or /tmp/test) % pwd ;# surprise: we stay in same effective directory /tmp/dir % exit bash> ln -sf /tmp/dir link_rel bash> tclsh % cd link_rel % pwd /tmp/test/link_rel % cd .. % pwd ;# ok, but should be normalized /tmp/test/.. % file normalize [pwd] /tmp % exit bash> ln -sf ../dir/ link_rel_trailing_slash bash> tclsh % cd link_rel_trailing_slash % pwd /tmp/test/link_rel_trailing_slash % cd .. % pwd ;# surprise /tmp/dir % exit bash> ln -sf ./link_abs link2link bash> tclsh % cd link2link % pwd /tmp/test/link2link % cd .. ;# now we are in /tmp/test (also ok) % pwd ;# but should be normalized /tmp/test/. % file normalize [pwd] /tmp % puts "$::tcl_patchLevel, $::tcl_platform(os) $::tcl_platform(osVersion)" 8.5.11, Linux 3.2.0-30-generic % exit
Referenced by2
36b590b922Ticket [3577801fff] Issue with [file normalize] on Linux with symlink wtih ".." status still Open with 4 other changes ticket2026-10-19 18:44:30854be12c0aFix [3577801fff], [3570244fff], [3183016fff] and [3099612fff]: on Unix, [file normalize] and [cd ..] used the target of a link literally when ".." followed it, so "..", "." or a trailing "/" in the target or a chain of links gave a wrong path. Normalize the target first, as realpath() does. On Windows, resolve ".." lexically, as the system does, so that [pwd], [glob] and native paths agree after [cd ..] from a junction or a symbolic link. Potential incompatibility on Windows: [file normalize junction/..] is now the parent of the junction, not of its target. check-in2026-10-19 18:37:17
dkfplain2012-09-21 14:50:50
Whatever is going on, it's a feature of the file system engine and not the [cd] command itself. I suspect that it depends on what normalization does, and I know that Don Porter has been doing work in that area relatively recently. Is it possible to retest with 8.5.12 or 8.6b3?
wastl-nagelplain2012-09-21 18:56:51
Both 8.5.12 and 8.6b3 are affected as well
serhiy.storchakawiki2026-10-19 18:44:30
Still present in 8.6, 9.0 and 9.1. As dkf suspected, the cause is in normalization: when ".." follows a link, the link target is used literally ([3577801fff]). Proposed fix in branch normalize-dotdot-after-link: on Unix [cd ..] now goes to the parent of the link target in all five cases of the report, as cd -P .. does. Test filesystem-1.56.
Log in (anonymous is fine) to add a comment.