[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [off-topic] rm -r on a used directory



Is there some version difference? I, too, could not reproduce
Adrians reported behavior:

Fabrizio:> 

> On 14 Jan, Adrian Bridgett wrote:
> > At work on AIX, if I do this:
> > 
> >   mkdir foo
> >   mkdir foo/bar
> >   cd foo/bar
> >   rm -r ../../foo
> > 
> > the last command fails as it is my current directory. This works without a
> > problem on Linux - it just leaves me in a non-existant dir.
> 
> Are you sure that it works without a problem?
> 
> 	$ rm -r ../../foo ; echo $?
> 	rm: ../../foo: No such file or directory
> 	rm: ../../foo: No such file or directory
> 	1
> 
> it failed, as you can see ...

me, too, but see below

> 
> 	$ ls .          
> 	/bin/ls: .: No such file or directory
> 
> ... and leaves you in troubles ...
> 
> 	$ ls -lA /tmp/a/b/c/
> 	total 1
> 	drwxr-xr-x   2 fab      fab          1024 Jan 15 11:12 foo
> 
> without having removed the requested dir
> 
> I think that AIX behaviour is better.
> Are you sure that Posix doesn't require that . should always exist?
> A lot of programs require that (find, for example).

there are a lot of ways you can be left without . and an easy 
way to recover (btw, do you mean that $CWD must always be non
empty, or if $CWD is non empty then it must refer to an existing
directory within current shell namespace and name expansion rules
or that when system file fuctions are given '.' as file name
always some meaningful results are given back?)

here is the tes once again, slightly expanded:
[in ~/ i.e. /home/astala at present]
bash-2.01$ mkdir zfoo
bash-2.01$ cd zfoo
bash-2.01$ mkdir zbar
bash-2.01$ touch zfoo1
bash-2.01$ cd zbar/
bash-2.01$ touch zbar1
bash-2.01$ ls -laR ../../z*
total 4
drwxr-xr-x   3 astala   astala       1024 Jan 16 10:30 .
drwxrwxr-x  34 astala   astala       2048 Jan 16 10:30 ..
drwxr-xr-x   2 astala   astala       1024 Jan 16 10:31 zbar
-rw-r--r--   1 astala   astala          0 Jan 16 10:30 zfoo1

../../zfoo/zbar:
total 2
drwxr-xr-x   2 astala   astala       1024 Jan 16 10:31 .
drwxr-xr-x   3 astala   astala       1024 Jan 16 10:30 ..
-rw-r--r--   1 astala   astala          0 Jan 16 10:31 zbar1
bash-2.01$ pwd
/home/astala/zfoo/zbar
bash-2.01$ rm -r ../../z*
rm: ../../zfoo/zfoo1: No such file or directory
rm: ../../zfoo: No such file or directory
bash-2.01$ pwd
/home/astala/zfoo/zbar
bash-2.01$ ls
ls: .: No such file or directory
bash-2.01$ ls -laR ~/z*
total 3
drwxr-xr-x   2 astala   astala       1024 Jan 16 10:32 .
drwxrwxr-x  34 astala   astala       2048 Jan 16 10:30 ..
-rw-r--r--   1 astala   astala          0 Jan 16 10:30 zfoo1
bash-2.01$ cd
bash-2.01$ rm -r z*
bash-2.01$ ls -laR ~/z*
ls: /home/astala/z*: No such file or directory
bash-2.01$ mkdir zfoo
bash-2.01$ cd zfoo
bash-2.01$ touch zfoo1
bash-2.01$ touch zfoo1
bash-2.01$ mkdir zbar
bash-2.01$ cd zbar/
bash-2.01$ touch zbar1
bash-2.01$ ls -laR ../../z*
total 4
drwxr-xr-x   3 astala   astala       1024 Jan 16 10:51 .
drwxrwxr-x  34 astala   astala       2048 Jan 16 10:50 ..
drwxr-xr-x   2 astala   astala       1024 Jan 16 10:51 zbar
-rw-r--r--   1 astala   astala          0 Jan 16 10:51 zfoo1

../../zfoo/zbar:
total 2
drwxr-xr-x   2 astala   astala       1024 Jan 16 10:51 .
drwxr-xr-x   3 astala   astala       1024 Jan 16 10:51 ..
-rw-r--r--   1 astala   astala          0 Jan 16 10:51 zbar1
bash-2.01$ rm -r ~/z*
bash-2.01$ pwd
/home/astala/zfoo/zbar
bash-2.01$ ls
ls: .: No such file or directory
bash-2.01$ ls -laR ~/z*
ls: /home/astala/z*: No such file or directory

so, it seems that rm also needs . or cwd when referring to relative
paths

with 
  rm -r ../../z* 
when it had descended into cwd (../../zfoo/zbar)
and after emptying it ascended into ../../zfoo and deleted
../../zfoo/zbar so cwd no longer pointed to an existing directory

then it complained about
  rm: ../../zfoo/zfoo1: No such file or directory
  rm: ../../zfoo: No such file or directory
since it (or some system call?) was unable to follow relative paths

but repeating exercise with absolute paths worked (I did not check
return value)

t.aa
-- 
WARNING! [...] The use of non-Intel processors can lead to performance
inconsistencies [...] and is therefore not recommended.
from ad of Tiny <www.tinycomp.co.uk>


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-devel-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: