[Box Backup-commit] COMMIT r3274 - box/trunk/lib/backupstore

subversion at boxbackup.org subversion at boxbackup.org
Thu Feb 13 23:29:37 GMT 2014


Author: chris
Date: 2014-02-13 23:29:37 +0000 (Thu, 13 Feb 2014)
New Revision: 3274

Modified:
   box/trunk/lib/backupstore/BackupStoreContext.cpp
Log:
Check that adding a new directory doesn't exceed store limits.

Modified: box/trunk/lib/backupstore/BackupStoreContext.cpp
===================================================================
--- box/trunk/lib/backupstore/BackupStoreContext.cpp	2014-02-13 23:29:27 UTC (rev 3273)
+++ box/trunk/lib/backupstore/BackupStoreContext.cpp	2014-02-13 23:29:37 UTC (rev 3274)
@@ -1032,6 +1032,7 @@
 	{
 		THROW_EXCEPTION(BackupStoreException, StoreInfoNotLoaded)
 	}
+
 	if(mReadOnly)
 	{
 		THROW_EXCEPTION(BackupStoreException, ContextIsReadOnly)
@@ -1065,6 +1066,8 @@
 	// Create an empty directory with the given attributes on disc
 	std::string fn;
 	MakeObjectFilename(id, fn, true /* make sure the directory it's in exists */);
+	int64_t dirSize;
+
 	{
 		BackupStoreDirectory emptyDir(id, InDirectory);
 		// add the atttribues
@@ -1075,7 +1078,17 @@
 		dirFile.Open(false /* no overwriting */);
 		emptyDir.WriteToStream(dirFile);
 		// Get disc usage, before it's commited
-		int64_t dirSize = dirFile.GetDiscUsageInBlocks();
+		dirSize = dirFile.GetDiscUsageInBlocks();
+
+		// Exceeds the hard limit?
+		int64_t newTotalBlocksUsed = mapStoreInfo->GetBlocksUsed() + 
+			dirSize;
+		if(newTotalBlocksUsed > mapStoreInfo->GetBlocksHardLimit())
+		{
+			THROW_EXCEPTION(BackupStoreException, AddedFileExceedsStorageLimit)
+			// The file will be deleted automatically by the RaidFile object
+		}
+
 		// Commit the file
 		dirFile.Commit(BACKUP_STORE_CONVERT_TO_RAID_IMMEDIATELY);		
 




More information about the Boxbackup-commit mailing list