[Box Backup-commit] COMMIT r1989 - box/chris/general/bin/bbackupd

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Sun, 9 Dec 2007 12:02:17 +0000 (UTC)


Author: chris
Date: 2007-12-09 12:02:17 +0000 (Sun, 09 Dec 2007)
New Revision: 1989

Modified:
   box/chris/general/bin/bbackupd/BackupDaemon.cpp
Log:
Hopefully fix a bug reported by Tobias Balle-Petersen, where unused
locations on the store would never be deleted because the timer would be
reset on every backup pass (refs #3, merges [1726])


Modified: box/chris/general/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/general/bin/bbackupd/BackupDaemon.cpp	2007-12-09 01:47:47 UTC (rev 1988)
+++ box/chris/general/bin/bbackupd/BackupDaemon.cpp	2007-12-09 12:02:17 UTC (rev 1989)
@@ -1977,8 +1977,7 @@
 
 		BOX_NOTICE(dir.GetNumberOfEntries() << " redundant locations "
 			"in root directory found, will delete from store "
-			"after " << BACKUP_DELETE_UNUSED_ROOT_ENTRIES_AFTER 
-			<< " seconds.");
+			"after " << secs << " seconds.");
 
 		// Store directories in list of things to delete
 		mUnusedRootDirEntries.clear();
@@ -1989,14 +1988,13 @@
 			// Add name to list
 			BackupStoreFilenameClear clear(en->GetName());
 			const std::string &name(clear.GetClearFilename());
-			mUnusedRootDirEntries.push_back(std::pair<int64_t,std::string>(en->GetObjectID(), name));
+			mUnusedRootDirEntries.push_back(
+				std::pair<int64_t,std::string>
+				(en->GetObjectID(), name));
 			// Log this
 			BOX_INFO("Unused location in root: " << name);
 		}
 		ASSERT(mUnusedRootDirEntries.size() > 0);
-		// Time to delete them
-		mDeleteUnusedRootDirEntriesAfter =
-			GetCurrentBoxTime() + SecondsToBoxTime(BACKUP_DELETE_UNUSED_ROOT_ENTRIES_AFTER);
 	}
 }
 
@@ -2438,16 +2436,27 @@
 // --------------------------------------------------------------------------
 void BackupDaemon::DeleteUnusedRootDirEntries(BackupClientContext &rContext)
 {
-	if(mUnusedRootDirEntries.empty() || mDeleteUnusedRootDirEntriesAfter == 0)
+	if(mUnusedRootDirEntries.empty())
 	{
-		// Nothing to do.
+		BOX_INFO("Not deleting unused entries - none in list");
 		return;
 	}
 	
+	if(mDeleteUnusedRootDirEntriesAfter == 0)
+	{
+		BOX_INFO("Not deleting unused entries - "
+			"zero delete time (bad)");
+		return;
+	}
+
 	// Check time
-	if(GetCurrentBoxTime() < mDeleteUnusedRootDirEntriesAfter)
+	box_time_t now = GetCurrentBoxTime();
+	if(now < mDeleteUnusedRootDirEntriesAfter)
 	{
-		// Too early to delete files
+		int secs = BoxTimeToSeconds(mDeleteUnusedRootDirEntriesAfter
+			- now);
+		BOX_INFO("Not deleting unused entries - too early ("
+			<< secs << " seconds remaining)");
 		return;
 	}