OSDN Git Service

* delqueue.cc (delqueue_list::queue_file): Add some debugging.
authorcgf <cgf>
Sat, 18 Mar 2000 06:26:14 +0000 (06:26 +0000)
committercgf <cgf>
Sat, 18 Mar 2000 06:26:14 +0000 (06:26 +0000)
* 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).

winsup/cygwin/ChangeLog
winsup/cygwin/delqueue.cc
winsup/cygwin/path.h
winsup/cygwin/syscalls.cc

index e6a509f..a9e5b27 100644 (file)
@@ -1,3 +1,11 @@
+Sat Mar 18 01:24:25 2000  Christopher Faylor <cgf@cygnus.com>
+
+       * 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 <corinna@vinschen.de>
 
        Patch suggested by Eric Fifer <EFifer@sanwaint.com>
index 81d2bd6..17feb69 100644 (file)
@@ -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;
       }
 
index f0ab684..01058a4 100644 (file)
@@ -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;}
index e93fe6e..e94e8ea 100644 (file)
@@ -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: