* 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).
This commit is contained in:
Christopher Faylor 2000-03-18 06:26:14 +00:00
parent 03261851a1
commit 87b82db4e7
4 changed files with 48 additions and 19 deletions

View 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>

View 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;
}

View 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;}

View 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: