delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/05/07/18:00:47

Sender: rich AT phekda DOT freeserve DOT co DOT uk
Message-ID: <3AF70A71.94C33963@phekda.freeserve.co.uk>
Date: Mon, 07 May 2001 21:49:53 +0100
From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.17 i586)
X-Accept-Language: de,fr
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: ANNOUNCE: Fileutils 4.0 beta 2
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1010429092632 DOT 26520B-100000 AT is>
Reply-To: djgpp-workers AT delorie DOT com

Hello.

Eli Zaretskii wrote:
> I think I found a bug in this port.  Put a floppy into drive A: and
> then try this:
> 
>      C:\> mkdir a:\foo
>      C:\> cd a:\
>      C:\> rm -rf a:/foo
>      c:/djgpp/bin/ls: a:/foo: Resource busy (EBUSY)

Eli, it looks like there's been a cut'n'paste error here. Should there be
some lines between the last two? Or is the last line incorrect?

> On plain DOS, this fails with EBUSY, even though the `cd' command
> above makes sure a:\foo is _not_ the current working directory on A:,
> and the directory is not removed.

Here's what happens recursively:

...
remove_dir (...) {
   save current working directory;
   change into directory being removed;
   remove all files in directory being removed - which will call
remove_dir() on subdirectories;
   restore working directory;
   remove directory being removed;
}

(There are actually two code paths - the other one is for removing a
subdirectory of the current directory specified as a relative path, e.g.
"foo" - then it does not save the directory - it just uses chdir("..") to
return to the original directory.)

So first time round the working directory is saved as c:/. Second time
round it is saved as a:/foo. So when it comes to remove a:/foo, a:/foo is
the working directory on a:. Hence the failure. If you ran 'rm -rf' from
the a: drive, it would have worked.

Actually there were two bugs:

* 'rm -r' did not understand drives - a:foo was considered to be a
subdirectory of the current directory, rather than a directory on a:. This
is now fixed.

* I had not made 'rm -r' aware of multiple working directories, one per
drive. If you use a drive specifier, 'rm -r' now saves the current drive's
and the directory's drive's working directory. This fixes the problem you
encountered.

I've put a fixed version of rm here:

    http://www.phekda.freeserve.co.uk/richdawe/djgpp/fileutils/

The file is rm.exe.gz.

> On Windows, `rm' succeeds to remove the directory (evidently because
> Windows doesn't have problems with removing CWD), but then you have this
> problem:
> 
>      C:\> ls a:
>      c:/djgpp/bin/ls: a:: No such file or directory (ENOENT)

This error is a manifestation of the bug in __set_need_fake_dot_dotdot(),
I think.

Thanks, bye, Rich =]

-- 
Richard Dawe
http://www.phekda.freeserve.co.uk/richdawe/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019