2004-03-14 Pierre Humblet <pierre.humblet@ieee.org>

* dir.cc (rmdir): Construct real_dir with flag PC_FULL.
        Use a loop instead of recursion to handle the current directory.
This commit is contained in:
Pierre Humblet 2004-03-14 16:16:45 +00:00
parent f8a8e7a1f6
commit 83a74ea24a
2 changed files with 55 additions and 50 deletions

View File

@ -1,3 +1,8 @@
2004-03-14 Pierre Humblet <pierre.humblet@ieee.org>
* dir.cc (rmdir): Construct real_dir with flag PC_FULL.
Use a loop instead of recursion to handle the current directory.
2004-03-14 Christopher Faylor <cgf@redhat.com>
* cygtls.cc (_cygtls::remove): Call remove_wq to ensure that wait stuff
@ -94,7 +99,7 @@
* sigproc.h (waitq): Delete declaration.
* wait.cc (wait4): Use _my_tls waitq structure rather than per_thread.
2004-02-11 Pierre Humblet <pierre.humblet@ieee.org>
2004-03-11 Pierre Humblet <pierre.humblet@ieee.org>
* cygtls.h (_cygtls::newmask): Delete member.
(_cygtls::deltamask): New member.

View File

@ -308,7 +308,7 @@ rmdir (const char *dir)
int res = -1;
DWORD devn;
path_conv real_dir (dir, PC_SYM_NOFOLLOW);
path_conv real_dir (dir, PC_SYM_NOFOLLOW | PC_FULL);
if (real_dir.error)
set_errno (real_dir.error);
@ -326,6 +326,8 @@ rmdir (const char *dir)
SetFileAttributes (real_dir,
(DWORD) real_dir & ~FILE_ATTRIBUTE_READONLY);
for (bool is_cwd = false; ; is_cwd = true)
{
int rc = RemoveDirectory (real_dir);
DWORD att = GetFileAttributes (real_dir);
@ -347,21 +349,16 @@ rmdir (const char *dir)
directory. If so, we will move elsewhere to potentially allow the
rmdir to succeed. This means that cygwin's concept of the current working
directory != Windows concept but, hey, whaddaregonnado?
Note that this will not cause something like the following to work:
$ cd foo
$ rmdir .
since the shell will have foo "open" in the above case and so Windows will
not allow the deletion.
FIXME: A potential workaround for this is for cygwin apps to *never* call
SetCurrentDirectory. */
if (strcasematch (real_dir, cygheap->cwd.win32)
&& !strcasematch ("c:\\", cygheap->cwd.win32))
&& !strcasematch ("c:\\", cygheap->cwd.win32) && !is_cwd)
{
DWORD err = GetLastError ();
if (!SetCurrentDirectory ("c:\\"))
SetLastError (err);
else if ((res = rmdir (dir)))
SetCurrentDirectory (cygheap->cwd.win32);
else
continue;
}
if (res)
{
@ -376,10 +373,13 @@ rmdir (const char *dir)
/* If directory still exists, restore R/O attribute. */
if (real_dir.has_attribute (FILE_ATTRIBUTE_READONLY))
SetFileAttributes (real_dir, real_dir);
if (is_cwd)
SetCurrentDirectory (cygheap->cwd.win32);
}
}
break;
}
}
syscall_printf ("%d = rmdir (%s)", res, dir);
return res;
}