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

subversion at boxbackup.org subversion at boxbackup.org
Fri Aug 27 10:18:57 BST 2010


Author: chris
Date: 2010-08-27 10:18:57 +0100 (Fri, 27 Aug 2010)
New Revision: 2702

Modified:
   box/trunk/lib/backupstore/BackupStoreCheck2.cpp
   box/trunk/lib/backupstore/BackupStoreInfo.cpp
   box/trunk/lib/backupstore/BackupStoreInfo.h
Log:
Change the store info file format to include an account name and the 
number of blocks in current (not old or deleted) files, an 
often-requested feature since this number is difficult to calculate 
otherwise, because files may be both old and deleted, thus counted 
twice.


Modified: box/trunk/lib/backupstore/BackupStoreCheck2.cpp
===================================================================
--- box/trunk/lib/backupstore/BackupStoreCheck2.cpp	2010-08-27 09:12:27 UTC (rev 2701)
+++ box/trunk/lib/backupstore/BackupStoreCheck2.cpp	2010-08-27 09:18:57 UTC (rev 2702)
@@ -573,10 +573,11 @@
 void BackupStoreCheck::WriteNewStoreInfo()
 {
 	// Attempt to load the existing store info file
-	std::auto_ptr<BackupStoreInfo> poldInfo;
+	std::auto_ptr<BackupStoreInfo> pOldInfo;
 	try
 	{
-		poldInfo.reset(BackupStoreInfo::Load(mAccountID, mStoreRoot, mDiscSetNumber, true /* read only */).release());
+		pOldInfo.reset(BackupStoreInfo::Load(mAccountID, mStoreRoot, mDiscSetNumber, true /* read only */).release());
+		mAccountName = pOldInfo->GetAccountName();
 	}
 	catch(...)
 	{
@@ -584,12 +585,19 @@
 		++mNumberErrorsFound;
 	}
 
+	BOX_NOTICE("Total files: " << mNumFiles << " (of which "
+		"old files: " << mNumOldFiles << ", "
+		"deleted files: " << mNumDeletedFiles << "), "
+		"directories: " << mNumDirectories);
+
 	// Minimum soft and hard limits
 	int64_t minSoft = ((mBlocksUsed * 11) / 10) + 1024;
 	int64_t minHard = ((minSoft * 11) / 10) + 1024;
 
 	// Need to do anything?
-	if(poldInfo.get() != 0 && mNumberErrorsFound == 0 && poldInfo->GetAccountID() == mAccountID)
+	if(pOldInfo.get() != 0 &&
+		mNumberErrorsFound == 0 &&
+		pOldInfo->GetAccountID() == mAccountID)
 	{
 		// Leave the store info as it is, no need to alter it because nothing really changed,
 		// and the only essential thing was that the account ID was correct, which is was.
@@ -601,21 +609,23 @@
 	// Work out the new limits
 	int64_t softLimit = minSoft;
 	int64_t hardLimit = minHard;
-	if(poldInfo.get() != 0 && poldInfo->GetBlocksSoftLimit() > minSoft)
+	if(pOldInfo.get() != 0 && pOldInfo->GetBlocksSoftLimit() > minSoft)
 	{
-		softLimit = poldInfo->GetBlocksSoftLimit();
+		softLimit = pOldInfo->GetBlocksSoftLimit();
 	}
 	else
 	{
-		BOX_WARNING("Soft limit for account changed to ensure housekeeping doesn't delete files on next run.");
+		BOX_WARNING("Soft limit for account changed to ensure "
+			"housekeeping doesn't delete files on next run.");
 	}
-	if(poldInfo.get() != 0 && poldInfo->GetBlocksHardLimit() > minHard)
+	if(pOldInfo.get() != 0 && pOldInfo->GetBlocksHardLimit() > minHard)
 	{
-		hardLimit = poldInfo->GetBlocksHardLimit();
+		hardLimit = pOldInfo->GetBlocksHardLimit();
 	}
 	else
 	{
-		BOX_WARNING("Hard limit for account changed to ensure housekeeping doesn't delete files on next run.");
+		BOX_WARNING("Hard limit for account changed to ensure "
+			"housekeeping doesn't delete files on next run.");
 	}
 	
 	// Object ID
@@ -628,16 +638,27 @@
 	// Build a new store info
 	std::auto_ptr<BackupStoreInfo> info(BackupStoreInfo::CreateForRegeneration(
 		mAccountID,
+		mAccountName,
 		mStoreRoot,
 		mDiscSetNumber,
 		lastObjID,
 		mBlocksUsed,
+		mBlocksInCurrentFiles,
 		mBlocksInOldFiles,
 		mBlocksInDeletedFiles,
 		mBlocksInDirectories,
 		softLimit,
 		hardLimit));
+	info->AdjustNumFiles(mNumFiles);
+	info->AdjustNumOldFiles(mNumOldFiles);
+	info->AdjustNumDeletedFiles(mNumDeletedFiles);
+	info->AdjustNumDirectories(mNumDirectories);
 
+	if(pOldInfo.get())
+	{
+		mNumberErrorsFound += info->ReportChangesTo(*pOldInfo);
+	}
+
 	// Save to disc?
 	if(mFixErrors)
 	{

Modified: box/trunk/lib/backupstore/BackupStoreInfo.cpp
===================================================================
--- box/trunk/lib/backupstore/BackupStoreInfo.cpp	2010-08-27 09:12:27 UTC (rev 2701)
+++ box/trunk/lib/backupstore/BackupStoreInfo.cpp	2010-08-27 09:18:57 UTC (rev 2702)
@@ -11,6 +11,7 @@
 
 #include <algorithm>
 
+#include "Archive.h"
 #include "BackupStoreInfo.h"
 #include "BackupStoreException.h"
 #include "RaidFileWrite.h"
@@ -28,6 +29,7 @@
 // ******************
 // make sure the defaults in CreateNew are modified!
 // ******************
+// Old version, grandfathered, do not change!
 typedef struct
 {
 	int32_t mMagicValue;	// also the version number
@@ -44,9 +46,10 @@
 	uint32_t mOptionsPresent;		// bit mask of optional elements present
 	int64_t mNumberDeletedDirectories;
 	// Then loads of int64_t IDs for the deleted directories
-} info_StreamFormat;
+} info_StreamFormat_1;
 
-#define INFO_MAGIC_VALUE	0x34832476
+#define INFO_MAGIC_VALUE_1	0x34832476
+#define INFO_MAGIC_VALUE_2	0x494e4632 /* INF2 */
 
 // Use default packing
 #ifdef STRUCTURE_PACKING_FOR_WIRE_USE_HEADERS
@@ -79,8 +82,14 @@
 	  mClientStoreMarker(0),
 	  mLastObjectIDUsed(-1),
 	  mBlocksUsed(0),
+	  mBlocksInCurrentFiles(0),
 	  mBlocksInOldFiles(0),
-	  mBlocksInDeletedFiles(0)
+	  mBlocksInDeletedFiles(0),
+	  mBlocksInDirectories(0),
+	  mNumFiles(0),
+	  mNumOldFiles(0),
+	  mNumDeletedFiles(0),
+	  mNumDirectories(0)
 {
 }
 
@@ -106,46 +115,29 @@
 // --------------------------------------------------------------------------
 void BackupStoreInfo::CreateNew(int32_t AccountID, const std::string &rRootDir, int DiscSet, int64_t BlockSoftLimit, int64_t BlockHardLimit)
 {
-	// Initial header (is entire file)
-	info_StreamFormat hdr = {
-		htonl(INFO_MAGIC_VALUE), // mMagicValue
-		htonl(AccountID), // mAccountID
-		0, // mClientStoreMarker
-		box_hton64(1), // mLastObjectIDUsed (which is the root directory)
-		0, // mBlocksUsed
-		0, // mBlocksInOldFiles
-		0, // mBlocksInDeletedFiles
-		0, // mBlocksInDirectories
-		box_hton64(BlockSoftLimit), // mBlocksSoftLimit
-		box_hton64(BlockHardLimit), // mBlocksHardLimit
-		0, // mCurrentMarkNumber
-		0, // mOptionsPresent
-		0 // mNumberDeletedDirectories
-	};
-	
+	BackupStoreInfo info;
+	info.mAccountID = AccountID;
+	info.mDiscSet = DiscSet;
+	info.mReadOnly = false;
+	info.mLastObjectIDUsed = 1;
+	info.mBlocksSoftLimit = BlockSoftLimit;
+	info.mBlocksHardLimit = BlockHardLimit;
+
 	// Generate the filename
 	ASSERT(rRootDir[rRootDir.size() - 1] == '/' ||
 		rRootDir[rRootDir.size() - 1] == DIRECTORY_SEPARATOR_ASCHAR);
-	std::string fn(rRootDir + INFO_FILENAME);
-	
-	// Open the file for writing
-	RaidFileWrite rf(DiscSet, fn);
-	rf.Open(false);		// no overwriting, as this is a new file
-	
-	// Write header
-	rf.Write(&hdr, sizeof(hdr));
-	
-	// Commit it to disc, converting it to RAID now
-	rf.Commit(true);
-	
-	// Done.
+	info.mFilename = rRootDir + INFO_FILENAME;
+
+	info.Save(false);
 }
 
 // --------------------------------------------------------------------------
 //
 // Function
-//		Name:    BackupStoreInfo::Load(int32_t, const std::string &, int, bool)
-//		Purpose: Loads the info from disc, given the root information. Can be marked as read only.
+//		Name:    BackupStoreInfo::Load(int32_t, const std::string &,
+//			 int, bool)
+//		Purpose: Loads the info from disc, given the root
+//			 information. Can be marked as read only.
 //		Created: 2003/08/28
 //
 // --------------------------------------------------------------------------
@@ -156,20 +148,29 @@
 	
 	// Open the file for reading (passing on optional request for revision ID)
 	std::auto_ptr<RaidFileRead> rf(RaidFileRead::Open(DiscSet, fn, pRevisionID));
-	
-	// Read in a header
-	info_StreamFormat hdr;
-	if(!rf->ReadFullBuffer(&hdr, sizeof(hdr), 0 /* not interested in bytes read if this fails */))
+
+	// Read in format and version
+	int32_t magic;
+	if(!rf->ReadFullBuffer(&magic, sizeof(magic), 0))
 	{
-		THROW_EXCEPTION(BackupStoreException, CouldNotLoadStoreInfo)
+		THROW_EXCEPTION(BackupStoreException, CouldNotLoadStoreInfo);
 	}
-	
-	// Check it
-	if(ntohl(hdr.mMagicValue) != INFO_MAGIC_VALUE || (int32_t)ntohl(hdr.mAccountID) != AccountID)
+
+	bool v1 = false, v2 = false;
+
+	if(ntohl(magic) == INFO_MAGIC_VALUE_1)
 	{
+		v1 = true;
+	}
+	else if(ntohl(magic) == INFO_MAGIC_VALUE_2)
+	{
+		v2 = true;
+	}
+	else
+	{
 		THROW_EXCEPTION(BackupStoreException, BadStoreInfoOnLoad)
 	}
-	
+
 	// Make new object
 	std::auto_ptr<BackupStoreInfo> info(new BackupStoreInfo);
 	
@@ -179,19 +180,70 @@
 	info->mFilename = fn;
 	info->mReadOnly = ReadOnly;
 	
-	// Insert info from file
-	info->mClientStoreMarker	= box_ntoh64(hdr.mClientStoreMarker);
-	info->mLastObjectIDUsed		= box_ntoh64(hdr.mLastObjectIDUsed);
-	info->mBlocksUsed 		= box_ntoh64(hdr.mBlocksUsed);
-	info->mBlocksInOldFiles 	= box_ntoh64(hdr.mBlocksInOldFiles);
-	info->mBlocksInDeletedFiles	= box_ntoh64(hdr.mBlocksInDeletedFiles);
-	info->mBlocksInDirectories	= box_ntoh64(hdr.mBlocksInDirectories);
-	info->mBlocksSoftLimit		= box_ntoh64(hdr.mBlocksSoftLimit);
-	info->mBlocksHardLimit		= box_ntoh64(hdr.mBlocksHardLimit);
-	
-	// Load up array of deleted objects
-	int64_t numDelObj = box_ntoh64(hdr.mNumberDeletedDirectories);
-	
+	int64_t numDelObj;
+
+	if (v1)
+	{
+		// Read in a header
+		info_StreamFormat_1 hdr;
+
+		if(!rf->ReadFullBuffer(&hdr, sizeof(hdr),
+			0 /* not interested in bytes read if this fails */))
+		{
+			THROW_EXCEPTION(BackupStoreException,
+				CouldNotLoadStoreInfo)
+		}
+		
+		// Check it
+		if((int32_t)ntohl(hdr.mAccountID) != AccountID)
+		{
+			THROW_EXCEPTION(BackupStoreException,
+				BadStoreInfoOnLoad)
+		}
+		
+		// Insert info from file
+		info->mClientStoreMarker	= box_ntoh64(hdr.mClientStoreMarker);
+		info->mLastObjectIDUsed		= box_ntoh64(hdr.mLastObjectIDUsed);
+		info->mBlocksUsed 		= box_ntoh64(hdr.mBlocksUsed);
+		info->mBlocksInOldFiles 	= box_ntoh64(hdr.mBlocksInOldFiles);
+		info->mBlocksInDeletedFiles	= box_ntoh64(hdr.mBlocksInDeletedFiles);
+		info->mBlocksInDirectories	= box_ntoh64(hdr.mBlocksInDirectories);
+		info->mBlocksSoftLimit		= box_ntoh64(hdr.mBlocksSoftLimit);
+		info->mBlocksHardLimit		= box_ntoh64(hdr.mBlocksHardLimit);
+		
+		// Load up array of deleted objects
+		numDelObj = box_ntoh64(hdr.mNumberDeletedDirectories);
+	}
+	else if(v2)
+	{
+		Archive archive(*rf, IOStream::TimeOutInfinite);
+
+		// Check it
+		int32_t FileAccountID;
+		archive.Read(FileAccountID);
+		if (FileAccountID != AccountID)
+		{
+			THROW_EXCEPTION(BackupStoreException,
+				BadStoreInfoOnLoad)
+		}
+
+		archive.Read(info->mAccountName);
+		archive.Read(info->mClientStoreMarker);
+		archive.Read(info->mLastObjectIDUsed);
+		archive.Read(info->mBlocksUsed);
+		archive.Read(info->mBlocksInCurrentFiles);
+		archive.Read(info->mBlocksInOldFiles);
+		archive.Read(info->mBlocksInDeletedFiles);
+		archive.Read(info->mBlocksInDirectories);
+		archive.Read(info->mBlocksSoftLimit);
+		archive.Read(info->mBlocksHardLimit);
+	  	archive.Read(info->mNumFiles);
+	  	archive.Read(info->mNumOldFiles);
+	  	archive.Read(info->mNumDeletedFiles);
+	  	archive.Read(info->mNumDirectories);
+	  	archive.Read(numDelObj);
+	}
+
 	// Then load them in
 	if(numDelObj > 0)
 	{
@@ -238,9 +290,13 @@
 //		Created: 23/4/04
 //
 // --------------------------------------------------------------------------
-std::auto_ptr<BackupStoreInfo> BackupStoreInfo::CreateForRegeneration(int32_t AccountID, const std::string &rRootDir,
-	int DiscSet, int64_t LastObjectID, int64_t BlocksUsed, int64_t BlocksInOldFiles,
-	int64_t BlocksInDeletedFiles, int64_t BlocksInDirectories, int64_t BlockSoftLimit, int64_t BlockHardLimit)
+std::auto_ptr<BackupStoreInfo> BackupStoreInfo::CreateForRegeneration(
+	int32_t AccountID, const std::string& rAccountName,
+	const std::string &rRootDir, int DiscSet,
+	int64_t LastObjectID, int64_t BlocksUsed,
+	int64_t BlocksInCurrentFiles, int64_t BlocksInOldFiles,
+	int64_t BlocksInDeletedFiles, int64_t BlocksInDirectories,
+	int64_t BlockSoftLimit, int64_t BlockHardLimit)
 {
 	// Generate the filename
 	std::string fn(rRootDir + DIRECTORY_SEPARATOR INFO_FILENAME);
@@ -250,6 +306,7 @@
 	
 	// Put in basic info
 	info->mAccountID = AccountID;
+	info->mAccountName = rAccountName;
 	info->mDiscSet = DiscSet;
 	info->mFilename = fn;
 	info->mReadOnly = false;
@@ -257,7 +314,8 @@
 	// Insert info starting info
 	info->mClientStoreMarker	= 0;
 	info->mLastObjectIDUsed		= LastObjectID;
-	info->mBlocksUsed 			= BlocksUsed;
+	info->mBlocksUsed 		= BlocksUsed;
+	info->mBlocksInCurrentFiles	= BlocksInCurrentFiles;
 	info->mBlocksInOldFiles 	= BlocksInOldFiles;
 	info->mBlocksInDeletedFiles	= BlocksInDeletedFiles;
 	info->mBlocksInDirectories	= BlocksInDirectories;
@@ -272,12 +330,12 @@
 // --------------------------------------------------------------------------
 //
 // Function
-//		Name:    BackupStoreInfo::Save()
+//		Name:    BackupStoreInfo::Save(bool allowOverwrite)
 //		Purpose: Save modified info back to disc
 //		Created: 2003/08/28
 //
 // --------------------------------------------------------------------------
-void BackupStoreInfo::Save()
+void BackupStoreInfo::Save(bool allowOverwrite)
 {
 	// Make sure we're initialised (although should never come to this)
 	if(mFilename.empty() || mAccountID == -1 || mDiscSet == -1)
@@ -293,27 +351,32 @@
 	
 	// Then... open a write file
 	RaidFileWrite rf(mDiscSet, mFilename);
-	rf.Open(true);		// allow overwriting
+	rf.Open(allowOverwrite);
 	
 	// Make header
-	info_StreamFormat hdr;
-	hdr.mMagicValue 				= htonl(INFO_MAGIC_VALUE);
-	hdr.mAccountID 					= htonl(mAccountID);
-	hdr.mClientStoreMarker			= box_hton64(mClientStoreMarker);
-	hdr.mLastObjectIDUsed			= box_hton64(mLastObjectIDUsed);
-	hdr.mBlocksUsed 				= box_hton64(mBlocksUsed);
-	hdr.mBlocksInOldFiles 			= box_hton64(mBlocksInOldFiles);
-	hdr.mBlocksInDeletedFiles 		= box_hton64(mBlocksInDeletedFiles);
-	hdr.mBlocksInDirectories		= box_hton64(mBlocksInDirectories);
-	hdr.mBlocksSoftLimit			= box_hton64(mBlocksSoftLimit);
-	hdr.mBlocksHardLimit			= box_hton64(mBlocksHardLimit);
-	hdr.mCurrentMarkNumber			= 0;
-	hdr.mOptionsPresent				= 0;
-	hdr.mNumberDeletedDirectories	= box_hton64(mDeletedDirectories.size());
-	
-	// Write header
-	rf.Write(&hdr, sizeof(hdr));
-	
+	int32_t magic = htonl(INFO_MAGIC_VALUE_2);
+	rf.Write(&magic, sizeof(magic));
+	Archive archive(rf, IOStream::TimeOutInfinite);
+
+	archive.Write(mAccountID);
+	archive.Write(mAccountName);
+	archive.Write(mClientStoreMarker);
+	archive.Write(mLastObjectIDUsed);
+	archive.Write(mBlocksUsed);
+	archive.Write(mBlocksInCurrentFiles);
+	archive.Write(mBlocksInOldFiles);
+	archive.Write(mBlocksInDeletedFiles);
+	archive.Write(mBlocksInDirectories);
+	archive.Write(mBlocksSoftLimit);
+	archive.Write(mBlocksHardLimit);
+	archive.Write(mNumFiles);
+	archive.Write(mNumOldFiles);
+	archive.Write(mNumDeletedFiles);
+	archive.Write(mNumDirectories);
+
+	int64_t numDelObj = mDeletedDirectories.size();
+	archive.Write(numDelObj);
+
 	// Write the deleted object list
 	if(mDeletedDirectories.size() > 0)
 	{
@@ -349,8 +412,39 @@
 	mIsModified = false;
 }
 
+int BackupStoreInfo::ReportChangesTo(BackupStoreInfo& rOldInfo)
+{
+	int numChanges = 0;
 
+	#define COMPARE(attribute) \
+	if (rOldInfo.Get ## attribute () != Get ## attribute ()) \
+	{ \
+		BOX_WARNING(#attribute " changed from " << \
+			rOldInfo.Get ## attribute () << " to " << \
+			Get ## attribute ()); \
+		numChanges++; \
+	}
 
+	COMPARE(AccountID);
+	COMPARE(AccountName);
+	COMPARE(LastObjectIDUsed);
+	COMPARE(BlocksUsed);
+	COMPARE(BlocksInCurrentFiles);
+	COMPARE(BlocksInOldFiles);
+	COMPARE(BlocksInDeletedFiles);
+	COMPARE(BlocksInDirectories);
+	COMPARE(BlocksSoftLimit);
+	COMPARE(BlocksHardLimit);
+	COMPARE(NumFiles);
+	COMPARE(NumOldFiles);
+	COMPARE(NumDeletedFiles);
+	COMPARE(NumDirectories);
+
+	#undef COMPARE
+
+	return numChanges;
+}
+
 // --------------------------------------------------------------------------
 //
 // Function
@@ -378,6 +472,32 @@
 // --------------------------------------------------------------------------
 //
 // Function
+//		Name:    BackupStoreInfo::ChangeBlocksInCurrentFiles(int32_t)
+//		Purpose: Change number of blocks in current files, by a delta
+//			 amount
+//		Created: 2010/08/26
+//
+// --------------------------------------------------------------------------
+void BackupStoreInfo::ChangeBlocksInCurrentFiles(int64_t Delta)
+{
+	if(mReadOnly)
+	{
+		THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly)
+	}
+
+	if((mBlocksInCurrentFiles + Delta) < 0)
+	{
+		THROW_EXCEPTION(BackupStoreException,
+			StoreInfoBlockDeltaMakesValueNegative)
+	}
+	
+	mBlocksInCurrentFiles += Delta;
+	mIsModified = true;
+}
+
+// --------------------------------------------------------------------------
+//
+// Function
 //		Name:    BackupStoreInfo::ChangeBlocksInOldFiles(int32_t)
 //		Purpose: Change number of blocks in old files, by a delta amount
 //		Created: 2003/08/28
@@ -447,7 +567,71 @@
 	mIsModified = true;
 }
 
+void BackupStoreInfo::AdjustNumFiles(int64_t increase)
+{
+	if(mReadOnly)
+	{
+		THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly)
+	}
 
+	if((mNumFiles + increase) < 0)
+	{
+		THROW_EXCEPTION(BackupStoreException, StoreInfoBlockDeltaMakesValueNegative)
+	}
+	
+	mNumFiles += increase;
+	mIsModified = true;
+
+}
+
+void BackupStoreInfo::AdjustNumOldFiles(int64_t increase)
+{
+	if(mReadOnly)
+	{
+		THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly)
+	}
+
+	if((mNumOldFiles + increase) < 0)
+	{
+		THROW_EXCEPTION(BackupStoreException, StoreInfoBlockDeltaMakesValueNegative)
+	}
+	
+	mNumOldFiles += increase;
+	mIsModified = true;
+}
+
+void BackupStoreInfo::AdjustNumDeletedFiles(int64_t increase)
+{
+	if(mReadOnly)
+	{
+		THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly)
+	}
+
+	if((mNumDeletedFiles + increase) < 0)
+	{
+		THROW_EXCEPTION(BackupStoreException, StoreInfoBlockDeltaMakesValueNegative)
+	}
+	
+	mNumDeletedFiles += increase;
+	mIsModified = true;
+}
+
+void BackupStoreInfo::AdjustNumDirectories(int64_t increase)
+{
+	if(mReadOnly)
+	{
+		THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly)
+	}
+
+	if((mNumDirectories + increase) < 0)
+	{
+		THROW_EXCEPTION(BackupStoreException, StoreInfoBlockDeltaMakesValueNegative)
+	}
+	
+	mNumDirectories += increase;
+	mIsModified = true;
+}
+
 // --------------------------------------------------------------------------
 //
 // Function
@@ -590,4 +774,24 @@
 }
 
 
+// --------------------------------------------------------------------------
+//
+// Function
+//		Name:    BackupStoreInfo::SetAccountName(const std::string&)
+//		Purpose: Sets the account name
+//		Created: 2008/08/22
+//
+// --------------------------------------------------------------------------
+void BackupStoreInfo::SetAccountName(const std::string& rName)
+{
+	if(mReadOnly)
+	{
+		THROW_EXCEPTION(BackupStoreException, StoreInfoIsReadOnly)
+	}
+	
+	mAccountName = rName;
+	
+	mIsModified = true;
+}
 
+

Modified: box/trunk/lib/backupstore/BackupStoreInfo.h
===================================================================
--- box/trunk/lib/backupstore/BackupStoreInfo.h	2010-08-27 09:12:27 UTC (rev 2701)
+++ box/trunk/lib/backupstore/BackupStoreInfo.h	2010-08-27 09:18:57 UTC (rev 2702)
@@ -46,23 +46,31 @@
 	bool IsModified() const {return mIsModified;}
 	
 	// Save modified infomation back to store
-	void Save();
+	void Save(bool allowOverwrite = true);
 	
 	// Data access functions
 	int32_t GetAccountID() const {return mAccountID;}
 	int64_t GetLastObjectIDUsed() const {return mLastObjectIDUsed;}
 	int64_t GetBlocksUsed() const {return mBlocksUsed;}
+	int64_t GetBlocksInCurrentFiles() const {return mBlocksInCurrentFiles;}
 	int64_t GetBlocksInOldFiles() const {return mBlocksInOldFiles;}
 	int64_t GetBlocksInDeletedFiles() const {return mBlocksInDeletedFiles;}
 	int64_t GetBlocksInDirectories() const {return mBlocksInDirectories;}
 	const std::vector<int64_t> &GetDeletedDirectories() const {return mDeletedDirectories;}
 	int64_t GetBlocksSoftLimit() const {return mBlocksSoftLimit;}
 	int64_t GetBlocksHardLimit() const {return mBlocksHardLimit;}
+	int64_t GetNumFiles() const {return mNumFiles;}
+	int64_t GetNumOldFiles() const {return mNumOldFiles;}
+	int64_t GetNumDeletedFiles() const {return mNumDeletedFiles;}
+	int64_t GetNumDirectories() const {return mNumDirectories;}
 	bool IsReadOnly() const {return mReadOnly;}
 	int GetDiscSetNumber() const {return mDiscSet;}
+
+	int ReportChangesTo(BackupStoreInfo& rOldInfo);
 	
 	// Data modification functions
 	void ChangeBlocksUsed(int64_t Delta);
+	void ChangeBlocksInCurrentFiles(int64_t Delta);
 	void ChangeBlocksInOldFiles(int64_t Delta);
 	void ChangeBlocksInDeletedFiles(int64_t Delta);
 	void ChangeBlocksInDirectories(int64_t Delta);
@@ -70,6 +78,10 @@
 	void AddDeletedDirectory(int64_t DirID);
 	void RemovedDeletedDirectory(int64_t DirID);
 	void ChangeLimits(int64_t BlockSoftLimit, int64_t BlockHardLimit);
+	void AdjustNumFiles(int64_t increase);
+	void AdjustNumOldFiles(int64_t increase);
+	void AdjustNumDeletedFiles(int64_t increase);
+	void AdjustNumDirectories(int64_t increase);
 	
 	// Object IDs
 	int64_t AllocateObjectID();
@@ -78,14 +90,23 @@
 	int64_t GetClientStoreMarker() {return mClientStoreMarker;}
 	void SetClientStoreMarker(int64_t ClientStoreMarker);
 
+	const std::string& GetAccountName() { return mAccountName; }
+	void SetAccountName(const std::string& rName);
+
 private:
-	static std::auto_ptr<BackupStoreInfo> CreateForRegeneration(int32_t AccountID, const std::string &rRootDir,
-		int DiscSet, int64_t LastObjectID, int64_t BlocksUsed, int64_t BlocksInOldFiles,
-		int64_t BlocksInDeletedFiles, int64_t BlocksInDirectories, int64_t BlockSoftLimit, int64_t BlockHardLimit);
+	static std::auto_ptr<BackupStoreInfo> CreateForRegeneration(
+		int32_t AccountID, const std::string &rAccountName,
+		const std::string &rRootDir, int DiscSet,
+		int64_t LastObjectID, int64_t BlocksUsed,
+		int64_t BlocksInCurrentFiles, int64_t BlocksInOldFiles,
+		int64_t BlocksInDeletedFiles, int64_t BlocksInDirectories,
+		int64_t BlockSoftLimit, int64_t BlockHardLimit);
 
-private:
 	// Location information
+	// Be VERY careful about changing types of these values, as
+	// they now define the sizes of fields on disk (via Archive).
 	int32_t mAccountID;
+	std::string mAccountName;
 	int mDiscSet;
 	std::string mFilename;
 	bool mReadOnly;
@@ -97,15 +118,19 @@
 	// Account information
 	int64_t mLastObjectIDUsed;
 	int64_t mBlocksUsed;
+	int64_t mBlocksInCurrentFiles;
 	int64_t mBlocksInOldFiles;
 	int64_t mBlocksInDeletedFiles;
 	int64_t mBlocksInDirectories;
 	int64_t mBlocksSoftLimit;
 	int64_t mBlocksHardLimit;
+	int64_t mNumFiles;
+	int64_t mNumOldFiles;
+	int64_t mNumDeletedFiles;
+	int64_t mNumDirectories;
 	std::vector<int64_t> mDeletedDirectories;
 };
 
-
 #endif // BACKUPSTOREINFO__H
 
 




More information about the Boxbackup-commit mailing list