aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2003-03-09 18:10:42 +0000
committerChristopher Faylor <me@cgf.cx>2003-03-09 18:10:42 +0000
commit36c4a441f6eb951779c4fc74d0e00ceec5ee3005 (patch)
treef95abd8ee63cc7e6470d1422135660e431e9da73
parentc379f2ed076264d23614d5d608ae62d43404fe5f (diff)
downloadnewlib-36c4a441f6eb951779c4fc74d0e00ceec5ee3005.zip
newlib-36c4a441f6eb951779c4fc74d0e00ceec5ee3005.tar.gz
newlib-36c4a441f6eb951779c4fc74d0e00ceec5ee3005.tar.bz2
* syscalls.cc (unlink): Attempt to be more clever about setting attributes of
file. Only open file in query mode to avoid having to mess with security stuff for reading.
-rw-r--r--winsup/cygwin/ChangeLog6
-rw-r--r--winsup/cygwin/syscalls.cc36
2 files changed, 30 insertions, 12 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 34730cf..33b3df3 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,9 @@
+2003-03-09 Christopher Faylor <cgf@redhat.com>
+
+ * syscalls.cc (unlink): Attempt to be more clever about setting
+ attributes of file. Only open file in query mode to avoid having to
+ mess with security stuff for reading.
+
2003-03-09 Corinna Vinschen <corinna@vinschen.de>
* rmsym: Fix regular expression.
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 27e40d0..3551723 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -130,36 +130,48 @@ unlink (const char *ourname)
if (!writable_directory (win32_name))
{
syscall_printf ("non-writable directory");
+ set_errno (EPERM);
goto done;
}
+ /* Allow us to delete even if read-only */
SetFileAttributes (win32_name, (DWORD) win32_name & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM));
/* Attempt to use "delete on close" semantics to handle removing
a file which may be open. */
HANDLE h;
- h = CreateFile (win32_name, GENERIC_READ, FILE_SHARE_DELETE, &sec_none_nih,
+ h = CreateFile (win32_name, 0, FILE_SHARE_READ, &sec_none_nih,
OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, 0);
-
- (void) SetFileAttributes (win32_name, (DWORD) win32_name);
- (void) DeleteFile (win32_name);
- DWORD lasterr;
- lasterr = GetLastError ();
if (h != INVALID_HANDLE_VALUE)
- CloseHandle (h);
-
- if (GetFileAttributes (win32_name) == INVALID_FILE_ATTRIBUTES
- || (!win32_name.isremote () && wincap.has_delete_on_close ()))
{
- syscall_printf ("DeleteFile succeeded");
- goto ok;
+ (void) SetFileAttributes (win32_name, (DWORD) win32_name);
+ BOOL res = CloseHandle (h);
+ syscall_printf ("%d = CloseHandle (%p)", res, h);
+ if (GetFileAttributes (win32_name) == INVALID_FILE_ATTRIBUTES
+ || (!win32_name.isremote () && wincap.has_delete_on_close ()))
+ {
+ syscall_printf ("CreateFile (FILE_FLAG_DELETE_ON_CLOSE) succeeded");
+ goto ok;
+ }
+ else
+ {
+ syscall_printf ("CreateFile (FILE_FLAG_DELETE_ON_CLOSE) failed");
+ SetFileAttributes (win32_name, (DWORD) win32_name & ~(FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM));
+ }
}
+
+ /* Try a delete with attributes reset */
if (DeleteFile (win32_name))
{
syscall_printf ("DeleteFile after CreateFile/ClosHandle succeeded");
goto ok;
}
+ DWORD lasterr;
+ lasterr = GetLastError ();
+
+ (void) SetFileAttributes (win32_name, (DWORD) win32_name);
+
/* Windows 9x seems to report ERROR_ACCESS_DENIED rather than sharing
violation. So, set lasterr to ERROR_SHARING_VIOLATION in this case
to simplify tests. */