[TUHS] moving directories in svr2

Chet Ramey chet.ramey at case.edu
Sat Jan 1 04:56:51 AEST 2022


On 12/30/21 7:43 PM, Bakul Shah wrote:

> Without the ".." entry you can't map a dir inode back to a path.
> Note that something similar can happen even today:
> 
> $ mkdir ~/a; cd ~/a; rm -rf ~/a; cd ..
> cd: no such file or directory: ..
> 
> $ mkdir -p ~/a/b; ln -s ~/a/b b; cd b; mv ~/a/b ~/a/c; cd ../b
> ls: ../b: No such file or directory

Modern POSIX shells attempt to disguise this for cd and pwd, using $PWD and
a canonicalization algorithm that essentially backs up one component when
it encounters `..' and removes `.' (with verification at each step and
error handling of various quality). It's the default behavior; the
traditional physical behavior is available with -P. It's a variant of the
ksh schme that Rob's lexical names paper explores.

It has the usual weaknesses: what works for cd doesn't work for, say, ls
or any other utilities that don't understand this particular scheme.

It produces the expected behavior for the first case above, but can be
fooled by file system changes that invalidate $PWD, as in the second case.
(I assume the `ls' error message was either a typo or an artifact of a
function or alias for `cd').

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet at case.edu    http://tiswww.cwru.edu/~chet/


More information about the TUHS mailing list