+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>
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;}
}
/* 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 */
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: