public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
@ 2001-09-08 10:28 John William
  0 siblings, 0 replies; 18+ messages in thread
From: John William @ 2001-09-08 10:28 UTC (permalink / raw)
  To: rrschulz, rick_rankin, cygwin

Actually, I'm a little confused about exactly what the standard says. It 
seems that SuS doesn't really say (but seems to imply that it should work). 
POSIX also implies that it should work as long as the directory is empty and 
I have permissions to delete it.

Isn't the basic philosophy that "it works unless something says it won't"? 
The only *requirement* I can find is that the directory be empty before 
rmdir() can succeed.

I understand this may be a limitation of Windows but it is not a limitation 
of the UN*X systems I've used (I don't have access to an IRIX machine). I do 
know that this difference broke the first three programs I tried porting 
from "true UN*X" to Cygwin.

- John

>From: Randall R Schulz <rrschulz@cris.com>
>To: Rick Rankin <rick_rankin@yahoo.com>, John William <jw2357@hotmail.com>, 
>   cygwin@cygwin.com
>Subject: Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
>Date: Sat, 08 Sep 2001 07:53:01 -0700
>
>Rick,
>
>You should try it. On many Unix systems it will work just fine. After the
>rmdir call, no call that uses a relative file name will work, however,
>since the directory must have been empty to be removed and in doing so the
>.. link would have been removed.
>
>This applies to "classic" implementations on the Unix file system. Chris
>has pointed out that IRIX does not behave this way. Since those details are
>not part of the API specifications, the implementers get to do what they
>please. That's what it's all about when it comes to writing specifications
>(saying everything you mean and are willing to commit to and nothing you
>are not).
>
>Randall Schulz
>Mountain View, CA USA
>
>
>At 22:48 2001-09-07, Rick Rankin wrote:
>>Hmm. It looks to me like this should fail, even under Unix. Once you've
>>chdir'd
>>into test, it no longer exists at the current directory level. Shouldn't 
>>the
>>sequence be
>>
>>mkdir("test");
>>chdir("test");
>>rmdir("../test");
>>
>>Of course, even this will fail under Windows because Windows won't allow 
>>the
>>current directory to be deleted if it's in use by any process.
>>
>>--Rick
>


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
  2001-09-09 16:40       ` Christopher Faylor
@ 2001-09-10 10:47         ` James Youngman
  0 siblings, 0 replies; 18+ messages in thread
From: James Youngman @ 2001-09-10 10:47 UTC (permalink / raw)
  To: cygwin

Christopher Faylor <cgf@redhat.com> writes:

> >My reading of this is that if you have a directory open by virtue of
> >it being your working directory, then it is valid for rmdir() to fail.
> >If however it is open via opendir(), then the rmdir() must succeed.  
> 
> Hmm.  I read "open" as also being "open as the current working
> directory".

Me too.  Perhaps I was unclear.

> In any event, cygwin/windows will fail for both of these situations, I
> think.

I'm not surprised.  So Cygwin will not pass a Unix certification
test.  BFD, it's very useful nonetheless. 

-- 
James Youngman
Manchester, UK.  +44 161 226 7339
PGP (GPG) key ID for <jay@gnu.org> is 64A95EE5 (F1B83152).

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
  2001-09-09 16:07     ` James Youngman
@ 2001-09-09 16:40       ` Christopher Faylor
  2001-09-10 10:47         ` James Youngman
  0 siblings, 1 reply; 18+ messages in thread
From: Christopher Faylor @ 2001-09-09 16:40 UTC (permalink / raw)
  To: cygwin

On Sun, Sep 09, 2001 at 01:29:55PM +0100, James Youngman wrote:
>Randall R Schulz <rrschulz@cris.com> writes:
>
>> You should try it. On many Unix systems it will work just
>> fine. After the rmdir call, no call that uses a relative file name
>> will work, however, since the directory must have been empty to be
>> removed and in doing so the .. link would have been removed.
>> 
>> This applies to "classic" implementations on the Unix file
>> system. Chris has pointed out that IRIX does not behave this
>> way. Since those details are not part of the API specifications, the
>> implementers get to do what they please.
>
>The (POSIX)|(X/Open) spec currenly says (about rmdir()) :-
>
>(38292 ff.)
>
>> The rmdir( ) function shall remove a directory whose name is given
>> by path. The directory shall be removed only if it is an empty
>> directory.  If the directory is the root directory or the current
>> working directory of any process, it is unspecified whether the
>> function succeeds, or whether it shall fail and set errno to
>> [EBUSY].  If path names a symbolic link, then rmdir( ) shall fail
>> and set errno to [ENOTDIR].
>> 
>> If the directory's link count becomes 0 and no process has the
>> directory open, the space occupied by the directory shall be freed
>> and the directory shall no longer be accessible. If one or more
>> processes have the directory open when the last link is removed, the
>> dot and dot-dot entries, if present, shall be removed before rmdir(
>> ) returns and no new entries may be created in the directory, but
>> the directory shall not be removed until all references to the
>> directory are closed.  If the directory is not an empty directory,
>> rmdir( ) shall fail and set errno to [EEXIST] or [ENOTEMPTY].
>
>My reading of this is that if you have a directory open by virtue of
>it being your working directory, then it is valid for rmdir() to fail.
>If however it is open via opendir(), then the rmdir() must succeed.  

Hmm.  I read "open" as also being "open as the current working
directory".

In any event, cygwin/windows will fail for both of these situations, I
think.

cgf

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
  2001-09-08  7:53   ` Randall R Schulz
  2001-09-09  8:49     ` Rick Rankin
@ 2001-09-09 16:07     ` James Youngman
  2001-09-09 16:40       ` Christopher Faylor
  1 sibling, 1 reply; 18+ messages in thread
From: James Youngman @ 2001-09-09 16:07 UTC (permalink / raw)
  To: Randall R Schulz; +Cc: Rick Rankin, John William, cygwin

Randall R Schulz <rrschulz@cris.com> writes:

> You should try it. On many Unix systems it will work just
> fine. After the rmdir call, no call that uses a relative file name
> will work, however, since the directory must have been empty to be
> removed and in doing so the .. link would have been removed.
> 
> This applies to "classic" implementations on the Unix file
> system. Chris has pointed out that IRIX does not behave this
> way. Since those details are not part of the API specifications, the
> implementers get to do what they please.

The (POSIX)|(X/Open) spec currenly says (about rmdir()) :-

(38292 ff.)

> The rmdir( ) function shall remove a directory whose name is given
> by path. The directory shall be removed only if it is an empty
> directory.  If the directory is the root directory or the current
> working directory of any process, it is unspecified whether the
> function succeeds, or whether it shall fail and set errno to
> [EBUSY].  If path names a symbolic link, then rmdir( ) shall fail
> and set errno to [ENOTDIR].
> 
> If the directory's link count becomes 0 and no process has the
> directory open, the space occupied by the directory shall be freed
> and the directory shall no longer be accessible. If one or more
> processes have the directory open when the last link is removed, the
> dot and dot-dot entries, if present, shall be removed before rmdir(
> ) returns and no new entries may be created in the directory, but
> the directory shall not be removed until all references to the
> directory are closed.  If the directory is not an empty directory,
> rmdir( ) shall fail and set errno to [EEXIST] or [ENOTEMPTY].

My reading of this is that if you have a directory open by virtue of
it being your working directory, then it is valid for rmdir() to fail.
If however it is open via opendir(), then the rmdir() must succeed.  


-- 
James Youngman
Manchester, UK.  +44 161 226 7339
PGP (GPG) key ID for <jay@gnu.org> is 64A95EE5 (F1B83152).

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
  2001-09-08  7:53   ` Randall R Schulz
@ 2001-09-09  8:49     ` Rick Rankin
  2001-09-09 16:07     ` James Youngman
  1 sibling, 0 replies; 18+ messages in thread
From: Rick Rankin @ 2001-09-09  8:49 UTC (permalink / raw)
  To: Randall R Schulz, cygwin

But there's no way the original code can work. If you'll recall, it was

mkdir("test");
chdir("test");
rmdir("test");

After the chdir("test") line, there is no longer a directory called "test" at
the current level of the directory hierarchy. How then can rmdir("test") work?
If it works on *any* system, my contention would be that it's a bug. That's why
I suggested

rmdir("../test");

which may well work on some systems. In fact, I seem to recall having seen it
work on some systems, AIX and Solaris in particular.

--Rick

--- Randall R Schulz <rrschulz@cris.com> wrote:
> Rick,
> 
> You should try it. On many Unix systems it will work just fine. After the 
> rmdir call, no call that uses a relative file name will work, however, 
> since the directory must have been empty to be removed and in doing so the 
> .. link would have been removed.
> 
> This applies to "classic" implementations on the Unix file system. Chris 
> has pointed out that IRIX does not behave this way. Since those details are 
> not part of the API specifications, the implementers get to do what they 
> please. That's what it's all about when it comes to writing specifications 
> (saying everything you mean and are willing to commit to and nothing you 
> are not).
> 
> Randall Schulz
> Mountain View, CA USA
> 
> 
> At 22:48 2001-09-07, Rick Rankin wrote:
> >Hmm. It looks to me like this should fail, even under Unix. Once you've 
> >chdir'd
> >into test, it no longer exists at the current directory level. Shouldn't the
> >sequence be
> >
> >mkdir("test");
> >chdir("test");
> >rmdir("../test");
> >
> >Of course, even this will fail under Windows because Windows won't allow the
> >current directory to be deleted if it's in use by any process.
> >
> >--Rick
> 


__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* RE: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
  2001-09-08  6:53     ` Robert Collins
@ 2001-09-09  6:14       ` Ronald Landheer
  0 siblings, 0 replies; 18+ messages in thread
From: Ronald Landheer @ 2001-09-09  6:14 UTC (permalink / raw)
  To: Robert Collins; +Cc: cygwin

Ah.. OK.. I hadn't thought about NT vs. 9x..
I am running 9x here, as you will have guessed. (Seems I've been away 
from NT too long..)
It seems this is just a thing not to do, then..

Greetz!

Ronald

-----Original Message-----
From: cygwin-owner@sources.redhat.com
[ mailto:cygwin-owner@sources.redhat.com]On Behalf Of Robert Collins
Sent: Saturday, September 08, 2001 3:54 PM
To: Ronald Landheer
Cc: cygwin@cygwin.com
Subject: RE: 1.3.2 rmdir fails if CWD is in the directory to be deleted?


On Sat, 2001-09-08 at 22:59, Ronald Landheer wrote:
> Hm.. This should work.. I can easily delete the current dir in CygWin with the M$ Explorer, 
> but do get a "permission denied" when I try it in cygwin. (If I do >
this:
> $ cd
> $ mkdir test
> $ cd test
> In explorer, delete p:\cygwin\home\RonaldLandheer\test
> $ cd ..
> I end up in ~/test/..
> 
> It would seem the _current_ process can't kill its own directory..
> Would it be possible to fork, go a dir lower and destroy it from there? (Haven't tried it yet, but I'd expect the same results)

No.

> Greetz!
> 
> Ronald

Try this to see whats going on:

open up a cmd or command prompt. (No cygwin).

mkdir foo
cd foo
no, from start|run, start up explorer
now navigate to foo, and try to delete it.

It might work on 9x, it won't on NT - ever.

Rob 


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
  2001-09-07 22:48 John William
  2001-09-08  7:53 ` Randall R Schulz
@ 2001-09-08 10:41 ` Christopher Faylor
  1 sibling, 0 replies; 18+ messages in thread
From: Christopher Faylor @ 2001-09-08 10:41 UTC (permalink / raw)
  To: cygwin; +Cc: jw2357

On Sat, Sep 08, 2001 at 05:48:21AM +0000, John William wrote:
>Ok, if this is a fundamental limitation of Windows, I can accept that. But 
>there must be a workaround -- after all, DJGPP works.

It sounds like you have three options, then:

1) Use DJGPP.

2) Submit a patch to Cygwin to fix this behavior since you seem to think
   it is relatively trivial.  I can't say that I agree but I'll certainly
   inspect any patch that you provide.

3) Modify your code.

As I mentioned, since this sequence even fails on some UNIX systems I
don't think that it is a priority for attempting some kind of
complicated work-around in cygwin code.

However, if you do think that this is crucial, then you probably should
investigate the issue further and provide a patch.

Good Luck,
cgf

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
@ 2001-09-08 10:20 John William
  0 siblings, 0 replies; 18+ messages in thread
From: John William @ 2001-09-08 10:20 UTC (permalink / raw)
  To: cygwin

Sorry. I'm really not the idiot I appear to be :-)

I meant:

mkdir("test");
chdir("test");
rmdir("../test");

on my second example.

- John

>From: Corinna Vinschen <cygwin@cygwin.com>
>To: cygwin@cygwin.com
>CC: John William <jw2357@hotmail.com>
>Subject: Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
>Date: Sat, 8 Sep 2001 11:45:32 +0200
>
>On Sat, Sep 08, 2001 at 01:01:37AM -0400, Christopher Faylor wrote:
> > On Sat, Sep 08, 2001 at 04:45:24AM +0000, John William wrote:
> > >I just installed Cygwin and am having the following problem with 
>rmdir() --
> > >it fails if the CWD is set to the directory to be deleted.
> > >
> > >main()
> > >{
> > > mkdir("test");
> > > rmdir("test"); <-- succeeds
> > >
> > > mkdir("test");
> > > chdir("test");
> > > rmdir("test"); <-- fails
> > >}
>
>BTW, the above can't work on _any_ system.  After creating a dir `test'
>and then chdir'ing into that directory, it's very unlikely that there's
>another subdirectory `test' in `test'...
>
>Corinna
>
> > >
> > >This is different than standard UN*X. It appears to me that POSIX only
> > >requires that the directory be empty, it doesn't say that the CWD can't 
>be
> > >set to the directory to be deleted.
> > >
> > >Is this a known issue? It is causing problems with some programs I'm 
>trying
> > >to compile (they work fine under RH Linux, DJGPP and FreeBSD). Please 
>e-mail
> > >any reponses, as I am not subscribed to the mailing list. Thanks!
> >
> > Welcome to Windows.  If Windows can't delete a directory while it is the
> > current directory of some process then there is no way that Cygwin can
> > do this either.
> >
> > The Single Unix Specification does seem to imply that deleting the 
>current
> > working directory should succeed but there are some UNIX systems out 
>there
> > that don't adhere to this.  For instance, I just tried this on IRIX 5.3
> > and it failed to rmdir a directory if I was cd'ed to it.
> >
> > cgf
> >
> > --
> > Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> > Bug reporting:         http://cygwin.com/bugs.html
> > Documentation:         http://cygwin.com/docs.html
> > FAQ:                   http://cygwin.com/faq/
>
>--
>Corinna Vinschen                  Please, send mails regarding Cygwin to
>Cygwin Developer                                mailto:cygwin@cygwin.com
>Red Hat, Inc.


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
  2001-09-07 22:48 John William
@ 2001-09-08  7:53 ` Randall R Schulz
  2001-09-08 10:41 ` Christopher Faylor
  1 sibling, 0 replies; 18+ messages in thread
From: Randall R Schulz @ 2001-09-08  7:53 UTC (permalink / raw)
  To: John William, cygwin

John,

Surely you're not suggesting that the side-effect of changing directory to 
the root be an inevitable consequence of removing a directory.

Clearly, if this work-around works for you, then you should wrap the rmdir 
call in one of your own that applies this "fix."

As Chris pointed out, there are Unixes out there where your code will not 
work, so it would seem you're relying on undocumented details. As far as I 
can recall, I've never seen the details I outlined of how removing things 
work mentioned as part of a Unix system call description.

This is a classic reliance on undocumented details and it has bitten you. 
Nothing new about that, either.

Randy



At 22:48 2001-09-07, John William wrote:
>Ok, if this is a fundamental limitation of Windows, I can accept that. But 
>there must be a workaround -- after all, DJGPP works. I tried modifying my 
>code such that:
>
>rmdir_workaround(dir)
>  char *dir;
>{
>  chdir("/");
>  return(rmdir(dir));
>}
>
>...and that seems to work just fine.
>
>Yes, it's a cheap hack, but maybe DJGPP does something similar. This code 
>will, of course, fail if the program relies on chdir("..") always working, 
>so this isn't a complete fix, but it's better than not having the program 
>work at all. The "real" fix would probably be to have an internal path, 
>separate from the Windows path, so chdir("..") would work and Windows 
>wouldn't have to know that the CWD was invalid before the chdir(".."). 
>Just a thought.
>
>Anyhow, thanks for the help and info!
>
>- John


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
  2001-09-07 22:48 ` Rick Rankin
  2001-09-08  6:12   ` Ronald Landheer
@ 2001-09-08  7:53   ` Randall R Schulz
  2001-09-09  8:49     ` Rick Rankin
  2001-09-09 16:07     ` James Youngman
  1 sibling, 2 replies; 18+ messages in thread
From: Randall R Schulz @ 2001-09-08  7:53 UTC (permalink / raw)
  To: Rick Rankin, John William, cygwin

Rick,

You should try it. On many Unix systems it will work just fine. After the 
rmdir call, no call that uses a relative file name will work, however, 
since the directory must have been empty to be removed and in doing so the 
.. link would have been removed.

This applies to "classic" implementations on the Unix file system. Chris 
has pointed out that IRIX does not behave this way. Since those details are 
not part of the API specifications, the implementers get to do what they 
please. That's what it's all about when it comes to writing specifications 
(saying everything you mean and are willing to commit to and nothing you 
are not).

Randall Schulz
Mountain View, CA USA


At 22:48 2001-09-07, Rick Rankin wrote:
>Hmm. It looks to me like this should fail, even under Unix. Once you've 
>chdir'd
>into test, it no longer exists at the current directory level. Shouldn't the
>sequence be
>
>mkdir("test");
>chdir("test");
>rmdir("../test");
>
>Of course, even this will fail under Windows because Windows won't allow the
>current directory to be deleted if it's in use by any process.
>
>--Rick


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* RE: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
  2001-09-08  6:12   ` Ronald Landheer
@ 2001-09-08  6:53     ` Robert Collins
  2001-09-09  6:14       ` Ronald Landheer
  0 siblings, 1 reply; 18+ messages in thread
From: Robert Collins @ 2001-09-08  6:53 UTC (permalink / raw)
  To: Ronald Landheer; +Cc: cygwin

On Sat, 2001-09-08 at 22:59, Ronald Landheer wrote:
> Hm.. This should work.. I can easily delete the current dir in CygWin with the M$ Explorer, 
> but do get a "permission denied" when I try it in cygwin. (If I do >
this:
> $ cd
> $ mkdir test
> $ cd test
> In explorer, delete p:\cygwin\home\RonaldLandheer\test
> $ cd ..
> I end up in ~/test/..
> 
> It would seem the _current_ process can't kill its own directory..
> Would it be possible to fork, go a dir lower and destroy it from there? (Haven't tried it yet, but I'd expect the same results)

No.

> Greetz!
> 
> Ronald

Try this to see whats going on:

open up a cmd or command prompt. (No cygwin).

mkdir foo
cd foo
no, from start|run, start up explorer
now navigate to foo, and try to delete it.

It might work on 9x, it won't on NT - ever.

Rob 


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* RE: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
  2001-09-07 22:48 ` Rick Rankin
@ 2001-09-08  6:12   ` Ronald Landheer
  2001-09-08  6:53     ` Robert Collins
  2001-09-08  7:53   ` Randall R Schulz
  1 sibling, 1 reply; 18+ messages in thread
From: Ronald Landheer @ 2001-09-08  6:12 UTC (permalink / raw)
  To: Rick Rankin, John William, cygwin

Hm.. This should work.. I can easily delete the current dir in CygWin with the M$ Explorer, but do get a "permission denied" when I try it in cygwin. (If I do this:
$ cd
$ mkdir test
$ cd test
In explorer, delete p:\cygwin\home\RonaldLandheer\test
$ cd ..
I end up in ~/test/..

It would seem the _current_ process can't kill its own directory..
Would it be possible to fork, go a dir lower and destroy it from there? (Haven't tried it yet, but I'd expect the same results)

Greetz!

Ronald

-----Original Message-----
From: cygwin-owner@sources.redhat.com
[ mailto:cygwin-owner@sources.redhat.com]On Behalf Of Rick Rankin
Sent: Saturday, September 08, 2001 7:49 AM
To: John William; cygwin@cygwin.com
Subject: Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?


Hmm. It looks to me like this should fail, even under Unix. Once you've chdir'd
into test, it no longer exists at the current directory level. Shouldn't the
sequence be

mkdir("test");
chdir("test");
rmdir("../test");

Of course, even this will fail under Windows because Windows won't allow the
current directory to be deleted if it's in use by any process.

--Rick

--- John William <jw2357@hotmail.com> wrote:
> I just installed Cygwin and am having the following problem with rmdir() -- 
> it fails if the CWD is set to the directory to be deleted.
> 
> main()
> {
>   mkdir("test");
>   rmdir("test"); <-- succeeds
> 
>   mkdir("test");
>   chdir("test");
>   rmdir("test"); <-- fails
> }
> 
> This is different than standard UN*X. It appears to me that POSIX only 
> requires that the directory be empty, it doesn't say that the CWD can't be 
> set to the directory to be deleted.
> 
> Is this a known issue? It is causing problems with some programs I'm trying 
> to compile (they work fine under RH Linux, DJGPP and FreeBSD). Please e-mail 
> any reponses, as I am not subscribed to the mailing list. Thanks!
> 
> - John
> 
> 
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
> 
> 
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Bug reporting:         http://cygwin.com/bugs.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/
> 


__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
  2001-09-07 22:01 ` Christopher Faylor
@ 2001-09-08  4:07   ` Corinna Vinschen
  0 siblings, 0 replies; 18+ messages in thread
From: Corinna Vinschen @ 2001-09-08  4:07 UTC (permalink / raw)
  To: cygwin; +Cc: John William

On Sat, Sep 08, 2001 at 01:01:37AM -0400, Christopher Faylor wrote:
> On Sat, Sep 08, 2001 at 04:45:24AM +0000, John William wrote:
> >I just installed Cygwin and am having the following problem with rmdir() -- 
> >it fails if the CWD is set to the directory to be deleted.
> >
> >main()
> >{
> > mkdir("test");
> > rmdir("test"); <-- succeeds
> >
> > mkdir("test");
> > chdir("test");
> > rmdir("test"); <-- fails
> >}

BTW, the above can't work on _any_ system.  After creating a dir `test'
and then chdir'ing into that directory, it's very unlikely that there's
another subdirectory `test' in `test'...

Corinna

> >
> >This is different than standard UN*X. It appears to me that POSIX only 
> >requires that the directory be empty, it doesn't say that the CWD can't be 
> >set to the directory to be deleted.
> >
> >Is this a known issue? It is causing problems with some programs I'm trying 
> >to compile (they work fine under RH Linux, DJGPP and FreeBSD). Please e-mail 
> >any reponses, as I am not subscribed to the mailing list. Thanks!
> 
> Welcome to Windows.  If Windows can't delete a directory while it is the
> current directory of some process then there is no way that Cygwin can
> do this either.
> 
> The Single Unix Specification does seem to imply that deleting the current
> working directory should succeed but there are some UNIX systems out there
> that don't adhere to this.  For instance, I just tried this on IRIX 5.3
> and it failed to rmdir a directory if I was cd'ed to it.
> 
> cgf
> 
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Bug reporting:         http://cygwin.com/bugs.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                                mailto:cygwin@cygwin.com
Red Hat, Inc.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
  2001-09-07 21:45 John William
  2001-09-07 22:01 ` Christopher Faylor
  2001-09-07 22:06 ` Randall R Schulz
@ 2001-09-07 22:48 ` Rick Rankin
  2001-09-08  6:12   ` Ronald Landheer
  2001-09-08  7:53   ` Randall R Schulz
  2 siblings, 2 replies; 18+ messages in thread
From: Rick Rankin @ 2001-09-07 22:48 UTC (permalink / raw)
  To: John William, cygwin

Hmm. It looks to me like this should fail, even under Unix. Once you've chdir'd
into test, it no longer exists at the current directory level. Shouldn't the
sequence be

mkdir("test");
chdir("test");
rmdir("../test");

Of course, even this will fail under Windows because Windows won't allow the
current directory to be deleted if it's in use by any process.

--Rick

--- John William <jw2357@hotmail.com> wrote:
> I just installed Cygwin and am having the following problem with rmdir() -- 
> it fails if the CWD is set to the directory to be deleted.
> 
> main()
> {
>   mkdir("test");
>   rmdir("test"); <-- succeeds
> 
>   mkdir("test");
>   chdir("test");
>   rmdir("test"); <-- fails
> }
> 
> This is different than standard UN*X. It appears to me that POSIX only 
> requires that the directory be empty, it doesn't say that the CWD can't be 
> set to the directory to be deleted.
> 
> Is this a known issue? It is causing problems with some programs I'm trying 
> to compile (they work fine under RH Linux, DJGPP and FreeBSD). Please e-mail 
> any reponses, as I am not subscribed to the mailing list. Thanks!
> 
> - John
> 
> 
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
> 
> 
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Bug reporting:         http://cygwin.com/bugs.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/
> 


__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
@ 2001-09-07 22:48 John William
  2001-09-08  7:53 ` Randall R Schulz
  2001-09-08 10:41 ` Christopher Faylor
  0 siblings, 2 replies; 18+ messages in thread
From: John William @ 2001-09-07 22:48 UTC (permalink / raw)
  To: rrschulz, cygwin

Ok, if this is a fundamental limitation of Windows, I can accept that. But 
there must be a workaround -- after all, DJGPP works. I tried modifying my 
code such that:

rmdir_workaround(dir)
  char *dir;
{
  chdir("/");
  return(rmdir(dir));
}

...and that seems to work just fine.

Yes, it's a cheap hack, but maybe DJGPP does something similar. This code 
will, of course, fail if the program relies on chdir("..") always working, 
so this isn't a complete fix, but it's better than not having the program 
work at all. The "real" fix would probably be to have an internal path, 
separate from the Windows path, so chdir("..") would work and Windows 
wouldn't have to know that the CWD was invalid before the chdir(".."). Just 
a thought.

Anyhow, thanks for the help and info!

- John

>From: Randall R Schulz <rrschulz@cris.com>
>To: "John William" <jw2357@hotmail.com>, cygwin@cygwin.com
>Subject: Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
>Date: Fri, 07 Sep 2001 22:06:18 -0700
>
>John,
>
>I'm not sure I'd call it an "issue" since I don't think it's likely ever to
>be "resolved."
>
>This reflects a restriction imposed by Windows that no file system entity
>that is in use (open file, program being executed, directory that is a
>current working directory, etc.) can be deleted.
>
>Unix can accomplish this sort of thing (deletion of in-use file system
>entities) because of the strong distinction and separation between the name
>of a thing (a directory entry) and the thing itself (an inode, whether
>internal or on disk). "Real" Unix systems use internal reference counting
>(multiple levels of it, in fact) to defer actions like the removal of a
>file or directory (inode) independent of the removal of the entity's last
>referencing directory entry (which is the direct consequence of an unlink
>or rmdir call).
>
>Simulating this in Cygwin would presumably require herculean hoop-jumping
>and major slight-of-hand and I tend to doubt the principals would consider
>it worth the effort.
>
>In short, "Cygwin is not Unix" and this is one place where the distinction
>is manifest as a difference in operation.
>
>Randall Schulz
>Mountain View, CA USA
>
>
>At 21:45 2001-09-07, John William wrote:
>>I just installed Cygwin and am having the following problem with rmdir()
>>-- it fails if the CWD is set to the directory to be deleted.
>>
>>main()
>>{
>>  mkdir("test");
>>  rmdir("test"); <-- succeeds
>>
>>  mkdir("test");
>>  chdir("test");
>>  rmdir("test"); <-- fails
>>}
>>
>>This is different than standard UN*X. It appears to me that POSIX only
>>requires that the directory be empty, it doesn't say that the CWD can't be
>>set to the directory to be deleted.
>>
>>Is this a known issue? It is causing problems with some programs I'm
>>trying to compile (they work fine under RH Linux, DJGPP and FreeBSD).
>>Please e-mail any reponses, as I am not subscribed to the mailing list. 
>>Thanks!
>>
>>- John
>


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
  2001-09-07 21:45 John William
  2001-09-07 22:01 ` Christopher Faylor
@ 2001-09-07 22:06 ` Randall R Schulz
  2001-09-07 22:48 ` Rick Rankin
  2 siblings, 0 replies; 18+ messages in thread
From: Randall R Schulz @ 2001-09-07 22:06 UTC (permalink / raw)
  To: John William, cygwin

John,

I'm not sure I'd call it an "issue" since I don't think it's likely ever to 
be "resolved."

This reflects a restriction imposed by Windows that no file system entity 
that is in use (open file, program being executed, directory that is a 
current working directory, etc.) can be deleted.

Unix can accomplish this sort of thing (deletion of in-use file system 
entities) because of the strong distinction and separation between the name 
of a thing (a directory entry) and the thing itself (an inode, whether 
internal or on disk). "Real" Unix systems use internal reference counting 
(multiple levels of it, in fact) to defer actions like the removal of a 
file or directory (inode) independent of the removal of the entity's last 
referencing directory entry (which is the direct consequence of an unlink 
or rmdir call).

Simulating this in Cygwin would presumably require herculean hoop-jumping 
and major slight-of-hand and I tend to doubt the principals would consider 
it worth the effort.

In short, "Cygwin is not Unix" and this is one place where the distinction 
is manifest as a difference in operation.

Randall Schulz
Mountain View, CA USA


At 21:45 2001-09-07, John William wrote:
>I just installed Cygwin and am having the following problem with rmdir() 
>-- it fails if the CWD is set to the directory to be deleted.
>
>main()
>{
>  mkdir("test");
>  rmdir("test"); <-- succeeds
>
>  mkdir("test");
>  chdir("test");
>  rmdir("test"); <-- fails
>}
>
>This is different than standard UN*X. It appears to me that POSIX only 
>requires that the directory be empty, it doesn't say that the CWD can't be 
>set to the directory to be deleted.
>
>Is this a known issue? It is causing problems with some programs I'm 
>trying to compile (they work fine under RH Linux, DJGPP and FreeBSD). 
>Please e-mail any reponses, as I am not subscribed to the mailing list. Thanks!
>
>- John


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: 1.3.2 rmdir fails if CWD is in the directory to be deleted?
  2001-09-07 21:45 John William
@ 2001-09-07 22:01 ` Christopher Faylor
  2001-09-08  4:07   ` Corinna Vinschen
  2001-09-07 22:06 ` Randall R Schulz
  2001-09-07 22:48 ` Rick Rankin
  2 siblings, 1 reply; 18+ messages in thread
From: Christopher Faylor @ 2001-09-07 22:01 UTC (permalink / raw)
  To: John William; +Cc: cygwin

On Sat, Sep 08, 2001 at 04:45:24AM +0000, John William wrote:
>I just installed Cygwin and am having the following problem with rmdir() -- 
>it fails if the CWD is set to the directory to be deleted.
>
>main()
>{
> mkdir("test");
> rmdir("test"); <-- succeeds
>
> mkdir("test");
> chdir("test");
> rmdir("test"); <-- fails
>}
>
>This is different than standard UN*X. It appears to me that POSIX only 
>requires that the directory be empty, it doesn't say that the CWD can't be 
>set to the directory to be deleted.
>
>Is this a known issue? It is causing problems with some programs I'm trying 
>to compile (they work fine under RH Linux, DJGPP and FreeBSD). Please e-mail 
>any reponses, as I am not subscribed to the mailing list. Thanks!

Welcome to Windows.  If Windows can't delete a directory while it is the
current directory of some process then there is no way that Cygwin can
do this either.

The Single Unix Specification does seem to imply that deleting the current
working directory should succeed but there are some UNIX systems out there
that don't adhere to this.  For instance, I just tried this on IRIX 5.3
and it failed to rmdir a directory if I was cd'ed to it.

cgf

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* 1.3.2 rmdir fails if CWD is in the directory to be deleted?
@ 2001-09-07 21:45 John William
  2001-09-07 22:01 ` Christopher Faylor
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: John William @ 2001-09-07 21:45 UTC (permalink / raw)
  To: cygwin

I just installed Cygwin and am having the following problem with rmdir() -- 
it fails if the CWD is set to the directory to be deleted.

main()
{
  mkdir("test");
  rmdir("test"); <-- succeeds

  mkdir("test");
  chdir("test");
  rmdir("test"); <-- fails
}

This is different than standard UN*X. It appears to me that POSIX only 
requires that the directory be empty, it doesn't say that the CWD can't be 
set to the directory to be deleted.

Is this a known issue? It is causing problems with some programs I'm trying 
to compile (they work fine under RH Linux, DJGPP and FreeBSD). Please e-mail 
any reponses, as I am not subscribed to the mailing list. Thanks!

- John


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2001-09-10 10:47 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-08 10:28 1.3.2 rmdir fails if CWD is in the directory to be deleted? John William
  -- strict thread matches above, loose matches on Subject: below --
2001-09-08 10:20 John William
2001-09-07 22:48 John William
2001-09-08  7:53 ` Randall R Schulz
2001-09-08 10:41 ` Christopher Faylor
2001-09-07 21:45 John William
2001-09-07 22:01 ` Christopher Faylor
2001-09-08  4:07   ` Corinna Vinschen
2001-09-07 22:06 ` Randall R Schulz
2001-09-07 22:48 ` Rick Rankin
2001-09-08  6:12   ` Ronald Landheer
2001-09-08  6:53     ` Robert Collins
2001-09-09  6:14       ` Ronald Landheer
2001-09-08  7:53   ` Randall R Schulz
2001-09-09  8:49     ` Rick Rankin
2001-09-09 16:07     ` James Youngman
2001-09-09 16:40       ` Christopher Faylor
2001-09-10 10:47         ` James Youngman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).