Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: `cd .` in non-existent directory leads into weird corner case



Richard Hartmann wrote on Tue, Mar 27, 2012 at 02:56:23 +0200:
> Hi all,
> 
> maybe I am misunderstanding zsh's intentions here, but this behaviour
> seems to be quite useless/counter-intuitive and potentially harmful:
> 
> richih@adamantium  ~ % zsh -f
> adamantium% PS1="%~ %# "
> ~ % mkdir testdir
> ~ % cd testdir
> ~/testdir % rmdir ~/testdir
> ~/testdir % cd .
> . % ls
> . % pwd
> .
> . % cd ..
> . % pwd
> .
> . %
> 
> Wouldn't it be better if zsh threw an error as soon as the user tries to `cd .`?
> 

FWIW:

stat64(".", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
chdir("/tmp/d")                 = -1 ENOENT (No such file or directory)
stat64(".", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
chdir(".")                              = 0
stat64("/tmp/d", 0xbf9b00ec)    = -1 ENOENT (No such file or directory)
stat64(".", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
rt_sigprocmask(SIG_BLOCK, [INT], [CHLD], 8) = 0
stat64("..", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0
open("..", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 3

which tells me two things: that there is an initial chdir() call which
fails (re your suggestion to propagate that), and that the behaviour
might be even weirder if you remove the parent directory as well.
('cd /tmp/d/e && rm -rf /tmp/d') 

> 
> Thanks,
> Richard



Messages sorted by: Reverse Date, Date, Thread, Author