From: cgf Date: Sat, 18 Mar 2000 06:26:14 +0000 (+0000) Subject: * delqueue.cc (delqueue_list::queue_file): Add some debugging. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=81e92b2eca202bf411971fdccd415a4417d69f2f;p=pf3gnuchains%2Fsourceware.git * delqueue.cc (delqueue_list::queue_file): Add some debugging. * path.h (class path_conv): Add a char * operator for the most common case. * syscalls.cc (_unlink): Rewrite to use FILE_FLAG_DELETE_ON_CLOSE when possible (i.e., on NT). --- diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index e6a509f419..a9e5b27575 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,11 @@ +Sat Mar 18 01:24:25 2000 Christopher Faylor + + * delqueue.cc (delqueue_list::queue_file): Add some debugging. + * path.h (class path_conv): Add a char * operator for the most common + case. + * syscalls.cc (_unlink): Rewrite to use FILE_FLAG_DELETE_ON_CLOSE when + possible (i.e., on NT). + Fri Mar 17 18:16:00 2000 Corinna Vinschen Patch suggested by Eric Fifer diff --git a/winsup/cygwin/delqueue.cc b/winsup/cygwin/delqueue.cc index 81d2bd68ba..17feb69917 100644 --- a/winsup/cygwin/delqueue.cc +++ b/winsup/cygwin/delqueue.cc @@ -54,6 +54,7 @@ delqueue_list::queue_file (const char *dosname) strcpy(name[i], temp); inuse[i] = 1; empty = 0; + debug_printf ("adding '%s' to queue %d", temp, i); return; } diff --git a/winsup/cygwin/path.h b/winsup/cygwin/path.h index f0ab684b24..01058a49b9 100644 --- a/winsup/cygwin/path.h +++ b/winsup/cygwin/path.h @@ -66,6 +66,7 @@ class path_conv path_conv (const char * const, symlink_follow follow_mode = SYMLINK_FOLLOW, int use_full_path = 0, const suffix_info *suffixes = NULL); inline char *get_win32 () { return path; } + operator char *() {return path; } BOOL is_device () {return devn != FH_BAD;} DWORD get_devn () {return devn == FH_BAD ? (DWORD) FH_DISK : devn;} short get_unitn () {return devn == FH_BAD ? 0 : unit;} diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index e93fe6e14b..e94e8ea321 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -67,17 +67,39 @@ _unlink (const char *ourname) } /* Windows won't check the directory mode, so we do that ourselves. */ - if (! writable_directory (win32_name.get_win32 ())) + if (!writable_directory (win32_name)) { syscall_printf ("non-writable directory"); goto done; } - if (DeleteFileA (win32_name.get_win32 ())) - res = 0; - else + for (int i = 0; i < 2; i++) { + if (DeleteFile (win32_name)) + { + syscall_printf ("DeleteFile succeeded"); + res = 0; + break; + } + + /* FIXME: There's a race here. */ + HANDLE h = CreateFile (win32_name, GENERIC_READ, + FILE_SHARE_READ, + &sec_none_nih, OPEN_EXISTING, + FILE_FLAG_DELETE_ON_CLOSE, 0); + if (h != INVALID_HANDLE_VALUE) + { + CloseHandle (h); + syscall_printf ("CreateFile/CloseHandle succeeded"); + res = 0; + break; + } + + if (i > 0) + goto err; + res = GetLastError (); + syscall_printf ("couldn't delete file, %E"); /* if access denied, chmod to be writable in case it is not and try again */ @@ -85,29 +107,26 @@ _unlink (const char *ourname) and only try again if permissions are not sufficient */ if (res == ERROR_ACCESS_DENIED) { - /* chmod ourname to be writable here */ - res = chmod (ourname, 0777); - - if (DeleteFileA (win32_name.get_win32 ())) - { - res = 0; - goto done; - } - res = GetLastError (); + /* chmod file to be writable here */ + if (chmod (win32_name, 0777) == 0) + continue; + else + goto err; } /* If we get ERROR_SHARING_VIOLATION, the file may still be open - Windows NT doesn't support deleting a file while it's open. */ if (res == ERROR_SHARING_VIOLATION) { - cygwin_shared->delqueue.queue_file (win32_name.get_win32 ()); + cygwin_shared->delqueue.queue_file (win32_name); res = 0; + break; } - else - { - __seterrno (); - res = -1; - } + + err: + __seterrno (); + res = -1; + break; } done: