diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 80eb566dd..0de8344e0 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +Mon Apr 17 12:08:47 2000 Kazuhiro Fujieda + + * syscalls.cc (_rename): Try MoveFile() at first before + MoveFileEx(..., MOVEFILE_REPLACE_EXISTING). + Tue Apr 18 19:15:29 2000 Christopher Faylor * dcrt0.cc (globify): Don't use \ quoting when apparently quoting a DOS diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 16f3b48d7..ca9777f79 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -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 */