* syscalls.cc (_rename): Try MoveFile() at first before

MoveFileEx(..., MOVEFILE_REPLACE_EXISTING).
This commit is contained in:
DJ Delorie 2000-04-19 03:21:13 +00:00
parent 7916b1efda
commit ef6581f9ff
2 changed files with 32 additions and 25 deletions

View File

@ -1,3 +1,8 @@
Mon Apr 17 12:08:47 2000 Kazuhiro Fujieda <fujieda@jaist.ac.jp>
* syscalls.cc (_rename): Try MoveFile() at first before
MoveFileEx(..., MOVEFILE_REPLACE_EXISTING).
Tue Apr 18 19:15:29 2000 Christopher Faylor <cgf@cygnus.com>
* dcrt0.cc (globify): Don't use \ quoting when apparently quoting a DOS

View File

@ -1200,43 +1200,45 @@ _rename (const char *oldpath, const char *newpath)
SetFileAttributesA (real_new.get_win32 (), newatts & ~ FILE_ATTRIBUTE_READONLY);
}
/* First make sure we have the permissions */
if (!MoveFileEx (real_old.get_win32 (), real_new.get_win32 (), MOVEFILE_REPLACE_EXISTING))
{
res = -1;
if (!MoveFile (real_old.get_win32 (), real_new.get_win32 ()))
res = -1;
/* !!! fixme, check for windows version before trying this.. */
if (GetLastError () == ERROR_CALL_NOT_IMPLEMENTED)
if (res == 0 || GetLastError () != ERROR_ALREADY_EXISTS)
goto done;
if (os_being_run == winNT)
{
if (MoveFileEx (real_old.get_win32 (), real_new.get_win32 (),
MOVEFILE_REPLACE_EXISTING))
res = 0;
}
else
{
syscall_printf ("try win95 hack");
for (;;)
{
/* How sad, we must be on win95, try it the stupid way */
syscall_printf ("try win95 hack");
for (;;)
if (!DeleteFileA (real_new.get_win32 ()) &&
GetLastError () != ERROR_FILE_NOT_FOUND)
{
syscall_printf ("deleting %s to be paranoid",
real_new.get_win32 ());
break;
}
else
{
if (MoveFile (real_old.get_win32 (), real_new.get_win32 ()))
{
res = 0;
break;
}
if (GetLastError () != ERROR_ALREADY_EXISTS)
{
syscall_printf ("%s already_exists", real_new.get_win32 ());
break;
}
if (!DeleteFileA (real_new.get_win32 ()) &&
GetLastError () != ERROR_FILE_NOT_FOUND)
{
syscall_printf ("deleting %s to be paranoid",
real_new.get_win32 ());
break;
}
}
}
if (res)
__seterrno ();
}
done:
if (res)
__seterrno ();
if (res == 0)
{
/* make the new file have the permissions of the old one */