public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* 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
* 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-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-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

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-07 21:45 1.3.2 rmdir fails if CWD is in the directory to be deleted? 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
2001-09-07 22:48 John William
2001-09-08  7:53 ` Randall R Schulz
2001-09-08 10:41 ` Christopher Faylor
2001-09-08 10:20 John William
2001-09-08 10:28 John William

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).