[Box Backup-dev] COMMIT r862 - box/chris/merge/bin/bbstored

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Thu, 31 Aug 2006 21:08:11 +0100


Author: chris
Date: 2006-08-31 21:08:11 +0100 (Thu, 31 Aug 2006)
New Revision: 862

Modified:
   box/chris/merge/bin/bbstored/BackupContext.cpp
Log:
* bin/bbstored/BackupContext.cpp
- Delete the temporary file on Win32 just like on other platforms (note
  that this reduces the guarantees that the file will be deleted,
  especially if an exception is thrown, refs #819)


Modified: box/chris/merge/bin/bbstored/BackupContext.cpp
===================================================================
--- box/chris/merge/bin/bbstored/BackupContext.cpp	2006-08-31 19:59:02 UTC (rev 861)
+++ box/chris/merge/bin/bbstored/BackupContext.cpp	2006-08-31 20:08:11 UTC (rev 862)
@@ -125,7 +125,6 @@
 // --------------------------------------------------------------------------
 bool BackupContext::AttemptToGetWriteLock()
 {
-#ifndef WIN32
 	// Make the filename of the write lock file
 	std::string writeLockFile;
 	StoreStructure::MakeWriteLockFilename(mStoreRoot, mStoreDiscSet, writeLockFile);
@@ -159,10 +158,6 @@
 	}
 	
 	return gotLock;
-#else // WIN32
-	// no housekeeping process, we do have the lock
-	return true;
-#endif // !WIN32
 }
 
 
@@ -466,12 +461,6 @@
 #else
 				FileStream diff(tempFn.c_str(), O_RDWR | O_CREAT | O_EXCL);
 				FileStream diff2(tempFn.c_str(), O_RDONLY);
-
-				// Unlink it immediately, so it definitely goes away
-				if(::unlink(tempFn.c_str()) != 0)
-				{
-					THROW_EXCEPTION(CommonException, OSFileError);
-				}
 #endif
 				
 				// Stream the incoming diff to this temporary file
@@ -514,6 +503,14 @@
 				spaceAdjustFromDiff = from->GetDiscUsageInBlocks() - oldVersionNewBlocksUsed;
 
 				// Everything cleans up here...
+				diff.Close();
+				diff2.Close();
+
+				// Unlink the temporary file
+				if(::unlink(tempFn.c_str()) != 0)
+				{
+					THROW_EXCEPTION(CommonException, OSFileError);
+				}
 			}
 			catch(...)
 			{