diff options
author | VMware, Inc <> | 2013-09-17 20:35:32 -0700 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2013-09-22 22:26:41 -0700 |
commit | 1dd5464914032fe986710bddaa2359c70a0e2c82 (patch) | |
tree | 30eefc8301757f93ac55da439a4af0a27e9c9559 | |
parent | 23f95ad9ba8896d1b3a2215ceaf336a0d776d449 (diff) |
Change FileIO_AtomicUpdate to not close files prior to rename on Posix.
Windows rename fails if the target files are open. Posix does not
have that restriction.
Signed-off-by: Dmitry Torokhov <dtor@vmware.com>
-rw-r--r-- | open-vm-tools/lib/file/fileIO.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/open-vm-tools/lib/file/fileIO.c b/open-vm-tools/lib/file/fileIO.c index 07520dec..75309fa8 100644 --- a/open-vm-tools/lib/file/fileIO.c +++ b/open-vm-tools/lib/file/fileIO.c @@ -823,12 +823,16 @@ FileIO_AtomicUpdate(FileIODescriptor *newFD, // IN/OUT: file IO descriptor { char *currPath; char *newPath; +#if defined(_WIN32) uint32 currAccess; uint32 newAccess; - Bool ret = FALSE; FileIOResult status; FileIODescriptor tmpFD; +#else + int fd; +#endif int savedErrno = 0; + Bool ret = FALSE; ASSERT(FileIO_IsValid(newFD)); ASSERT(FileIO_IsValid(currFD)); @@ -840,7 +844,6 @@ FileIO_AtomicUpdate(FileIODescriptor *newFD, // IN/OUT: file IO descriptor char *fileName = NULL; char *dstDirName = NULL; char *dstFileName = NULL; - int fd; currPath = File_FullPath(FileIO_Filename(currFD)); newPath = File_FullPath(FileIO_Filename(newFD)); @@ -947,7 +950,7 @@ swapdone: NOT_REACHED(); #endif } - +#if defined(_WIN32) currPath = Unicode_Duplicate(FileIO_Filename(currFD)); newPath = Unicode_Duplicate(FileIO_Filename(newFD)); @@ -965,13 +968,8 @@ swapdone: * middle of transferring ownership. */ -#if defined(_WIN32) CloseHandle(currFD->win32); currFD->win32 = INVALID_HANDLE_VALUE; -#else - close(currFD->posix); - currFD->posix = -1; -#endif if (File_RenameRetry(newPath, currPath, 10) == 0) { ret = TRUE; } else { @@ -997,11 +995,7 @@ swapdone: } ASSERT(tmpFD.lockToken == NULL); -#if defined(_WIN32) currFD->win32 = tmpFD.win32; -#else - currFD->posix = tmpFD.posix; -#endif FileIO_Cleanup(&tmpFD); Unicode_Free(currPath); @@ -1009,4 +1003,24 @@ swapdone: errno = savedErrno; return ret; +#else + currPath = (char *)FileIO_Filename(currFD); + newPath = (char *)FileIO_Filename(newFD); + + if (File_Rename(newPath, currPath)) { + Log("%s: rename of '%s' to '%s' failed %d.\n", + __FUNCTION__, newPath, currPath, errno); + savedErrno = errno; + } else { + ret = TRUE; + fd = newFD->posix; + newFD->posix = currFD->posix; + currFD->posix = fd; + FileIO_Close(newFD); + } + + errno = savedErrno; + + return ret; +#endif } |