2004-03-19 Pierre Humblet <pierre.humblet@ieee.org>
* dir.cc (rmdir): Reorganize error handling to reduce indentation.
This commit is contained in:
parent
61f50f94d2
commit
83f96e3fbd
|
@ -1,3 +1,7 @@
|
||||||
|
2004-03-19 Pierre Humblet <pierre.humblet@ieee.org>
|
||||||
|
|
||||||
|
* dir.cc (rmdir): Reorganize error handling to reduce indentation.
|
||||||
|
|
||||||
2004-03-19 Christopher Faylor <cgf@redhat.com>
|
2004-03-19 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
* include/cygwin/version.h: Bump DLL minor number to 10.
|
* include/cygwin/version.h: Bump DLL minor number to 10.
|
||||||
|
|
|
@ -328,6 +328,7 @@ rmdir (const char *dir)
|
||||||
|
|
||||||
for (bool is_cwd = false; ; is_cwd = true)
|
for (bool is_cwd = false; ; is_cwd = true)
|
||||||
{
|
{
|
||||||
|
DWORD err;
|
||||||
int rc = RemoveDirectory (real_dir);
|
int rc = RemoveDirectory (real_dir);
|
||||||
DWORD att = GetFileAttributes (real_dir);
|
DWORD att = GetFileAttributes (real_dir);
|
||||||
|
|
||||||
|
@ -338,48 +339,51 @@ rmdir (const char *dir)
|
||||||
/* RemoveDirectory on a samba drive doesn't return an error if the
|
/* RemoveDirectory on a samba drive doesn't return an error if the
|
||||||
directory can't be removed because it's not empty. Checking for
|
directory can't be removed because it's not empty. Checking for
|
||||||
existence afterwards keeps us informed about success. */
|
existence afterwards keeps us informed about success. */
|
||||||
if (att != INVALID_FILE_ATTRIBUTES)
|
if (att == INVALID_FILE_ATTRIBUTES)
|
||||||
set_errno (ENOTEMPTY);
|
{
|
||||||
else
|
res = 0;
|
||||||
res = 0;
|
break;
|
||||||
|
}
|
||||||
|
err = ERROR_DIR_NOT_EMPTY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
err = GetLastError ();
|
||||||
/* This kludge detects if we are attempting to remove the current working
|
|
||||||
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?
|
|
||||||
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) && !is_cwd)
|
|
||||||
{
|
|
||||||
DWORD err = GetLastError ();
|
|
||||||
if (!SetCurrentDirectory ("c:\\"))
|
|
||||||
SetLastError (err);
|
|
||||||
else
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (res)
|
|
||||||
{
|
|
||||||
if (GetLastError () != ERROR_ACCESS_DENIED
|
|
||||||
|| !wincap.access_denied_on_delete ())
|
|
||||||
__seterrno ();
|
|
||||||
else
|
|
||||||
set_errno (ENOTEMPTY); /* On 9X ERROR_ACCESS_DENIED is
|
|
||||||
returned if you try to remove a
|
|
||||||
non-empty directory. */
|
|
||||||
|
|
||||||
/* If directory still exists, restore R/O attribute. */
|
/* This kludge detects if we are attempting to remove the current working
|
||||||
if (real_dir.has_attribute (FILE_ATTRIBUTE_READONLY))
|
directory. If so, we will move elsewhere to potentially allow the
|
||||||
SetFileAttributes (real_dir, real_dir);
|
rmdir to succeed. This means that cygwin's concept of the current working
|
||||||
if (is_cwd)
|
directory != Windows concept but, hey, whaddaregonnado?
|
||||||
SetCurrentDirectory (cygheap->cwd.win32);
|
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. (Actually it does on 9X.)
|
||||||
|
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)
|
||||||
|
&& !is_cwd
|
||||||
|
&& SetCurrentDirectory ("c:\\"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* On 9X ERROR_ACCESS_DENIED is returned
|
||||||
|
if you try to remove a non-empty directory. */
|
||||||
|
if (err == ERROR_ACCESS_DENIED
|
||||||
|
&& wincap.access_denied_on_delete ())
|
||||||
|
err = ERROR_DIR_NOT_EMPTY;
|
||||||
|
|
||||||
|
__seterrno_from_win_error (err);
|
||||||
|
|
||||||
|
/* Directory still exists, restore its characteristics. */
|
||||||
|
if (real_dir.has_attribute (FILE_ATTRIBUTE_READONLY))
|
||||||
|
SetFileAttributes (real_dir, real_dir);
|
||||||
|
if (is_cwd)
|
||||||
|
SetCurrentDirectory (real_dir);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
syscall_printf ("%d = rmdir (%s)", res, dir);
|
syscall_printf ("%d = rmdir (%s)", res, dir);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue