[Box Backup-commit] COMMIT r3357 - box/trunk/bin/bbackupd

subversion at boxbackup.org subversion at boxbackup.org
Fri Aug 15 23:47:28 BST 2014


Author: chris
Date: 2014-08-15 23:47:27 +0100 (Fri, 15 Aug 2014)
New Revision: 3357

Modified:
   box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp
   box/trunk/bin/bbackupd/BackupClientDirectoryRecord.h
   box/trunk/bin/bbackupd/BackupDaemon.cpp
Log:
Use std::auto_ptrs instead of bare pointers for exclude lists.

Allows us to remove code to handle cleanups after exceptions and on Location
destruction.

Modified: box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp	2014-08-15 22:47:25 UTC (rev 3356)
+++ box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp	2014-08-15 22:47:27 UTC (rev 3357)
@@ -2117,11 +2117,8 @@
 //
 // --------------------------------------------------------------------------
 Location::Location()
-	: mIDMapIndex(0),
-	  mpExcludeFiles(0),
-	  mpExcludeDirs(0)
-{
-}
+: mIDMapIndex(0)
+{ }
 
 // --------------------------------------------------------------------------
 //
@@ -2132,19 +2129,7 @@
 //
 // --------------------------------------------------------------------------
 Location::~Location()
-{
-	// Clean up exclude locations
-	if(mpExcludeDirs != 0)
-	{
-		delete mpExcludeDirs;
-		mpExcludeDirs = 0;
-	}
-	if(mpExcludeFiles != 0)
-	{
-		delete mpExcludeFiles;
-		mpExcludeFiles = 0;
-	}
-}
+{ }
 
 // --------------------------------------------------------------------------
 //
@@ -2168,7 +2153,7 @@
 	//
 	//
 	//
-	if(mpDirectoryRecord.get() == NULL)
+	if(!mapDirectoryRecord.get())
 	{
 		int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP;
 		rArchive.Write(aMagicMarker);
@@ -2178,13 +2163,13 @@
 		int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_RECURSE; // be explicit about whether recursion follows
 		rArchive.Write(aMagicMarker);
 
-		mpDirectoryRecord->Serialize(rArchive);
+		mapDirectoryRecord->Serialize(rArchive);
 	}
 
 	//
 	//
 	//
-	if(!mpExcludeFiles)
+	if(!mapExcludeFiles.get())
 	{
 		int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP;
 		rArchive.Write(aMagicMarker);
@@ -2194,13 +2179,13 @@
 		int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_RECURSE; // be explicit about whether recursion follows
 		rArchive.Write(aMagicMarker);
 
-		mpExcludeFiles->Serialize(rArchive);
+		mapExcludeFiles->Serialize(rArchive);
 	}
 
 	//
 	//
 	//
-	if(!mpExcludeDirs)
+	if(!mapExcludeDirs.get())
 	{
 		int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP;
 		rArchive.Write(aMagicMarker);
@@ -2210,7 +2195,7 @@
 		int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_RECURSE; // be explicit about whether recursion follows
 		rArchive.Write(aMagicMarker);
 
-		mpExcludeDirs->Serialize(rArchive);
+		mapExcludeDirs->Serialize(rArchive);
 	}
 }
 
@@ -2228,17 +2213,9 @@
 	//
 	//
 	//
-	mpDirectoryRecord.reset(NULL);
-	if(mpExcludeFiles)
-	{
-		delete mpExcludeFiles;
-		mpExcludeFiles = NULL;
-	}
-	if(mpExcludeDirs)
-	{
-		delete mpExcludeDirs;
-		mpExcludeDirs = NULL;
-	}
+	mapDirectoryRecord.reset();
+	mapExcludeFiles.reset();
+	mapExcludeDirs.reset();
 
 	//
 	//
@@ -2265,8 +2242,8 @@
 			throw std::bad_alloc();
 		}
 
-		mpDirectoryRecord.reset(pSubRecord);
-		mpDirectoryRecord->Deserialize(rArchive);
+		mapDirectoryRecord.reset(pSubRecord);
+		mapDirectoryRecord->Deserialize(rArchive);
 	}
 	else
 	{
@@ -2285,13 +2262,13 @@
 	}
 	else if(aMagicMarker == ARCHIVE_MAGIC_VALUE_RECURSE)
 	{
-		mpExcludeFiles = new ExcludeList;
-		if(!mpExcludeFiles)
+		mapExcludeFiles.reset(new ExcludeList);
+		if(!mapExcludeFiles.get())
 		{
 			throw std::bad_alloc();
 		}
 
-		mpExcludeFiles->Deserialize(rArchive);
+		mapExcludeFiles->Deserialize(rArchive);
 	}
 	else
 	{
@@ -2310,13 +2287,13 @@
 	}
 	else if(aMagicMarker == ARCHIVE_MAGIC_VALUE_RECURSE)
 	{
-		mpExcludeDirs = new ExcludeList;
-		if(!mpExcludeDirs)
+		mapExcludeDirs.reset(new ExcludeList);
+		if(!mapExcludeDirs.get())
 		{
 			throw std::bad_alloc();
 		}
 
-		mpExcludeDirs->Deserialize(rArchive);
+		mapExcludeDirs->Deserialize(rArchive);
 	}
 	else
 	{

Modified: box/trunk/bin/bbackupd/BackupClientDirectoryRecord.h
===================================================================
--- box/trunk/bin/bbackupd/BackupClientDirectoryRecord.h	2014-08-15 22:47:25 UTC (rev 3356)
+++ box/trunk/bin/bbackupd/BackupClientDirectoryRecord.h	2014-08-15 22:47:27 UTC (rev 3357)
@@ -214,10 +214,10 @@
 public:
 	std::string mName;
 	std::string mPath;
-	std::auto_ptr<BackupClientDirectoryRecord> mpDirectoryRecord;
+	std::auto_ptr<BackupClientDirectoryRecord> mapDirectoryRecord;
+	std::auto_ptr<ExcludeList> mapExcludeFiles;
+	std::auto_ptr<ExcludeList> mapExcludeDirs;
 	int mIDMapIndex;
-	ExcludeList *mpExcludeFiles;
-	ExcludeList *mpExcludeDirs;
 
 #ifdef ENABLE_VSS
 	bool mIsSnapshotCreated;

Modified: box/trunk/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupDaemon.cpp	2014-08-15 22:47:25 UTC (rev 3356)
+++ box/trunk/bin/bbackupd/BackupDaemon.cpp	2014-08-15 22:47:27 UTC (rev 3357)
@@ -1034,8 +1034,8 @@
 		// Set exclude lists (context doesn't
 		// take ownership)
 		clientContext.SetExcludeLists(
-			(*i)->mpExcludeFiles,
-			(*i)->mpExcludeDirs);
+			(*i)->mapExcludeFiles.get(),
+			(*i)->mapExcludeDirs.get());
 
 		// Sync the directory
 		std::string locationPath = (*i)->mPath;
@@ -1046,7 +1046,7 @@
 		}
 #endif
 
-		(*i)->mpDirectoryRecord->SyncDirectory(params,
+		(*i)->mapDirectoryRecord->SyncDirectory(params,
 			BackupProtocolListDirectory::RootDirectory,
 			locationPath, std::string("/") + (*i)->mName, **i);
 
@@ -2408,8 +2408,8 @@
 				pLoc->mPath = rConfig.GetKeyValue("Path");
 				
 				// Read the exclude lists from the Configuration
-				pLoc->mpExcludeFiles = BackupClientMakeExcludeList_Files(rConfig);
-				pLoc->mpExcludeDirs = BackupClientMakeExcludeList_Dirs(rConfig);
+				pLoc->mapExcludeFiles.reset(BackupClientMakeExcludeList_Files(rConfig));
+				pLoc->mapExcludeDirs.reset(BackupClientMakeExcludeList_Dirs(rConfig));
 			}
 
 			// Does this exist on the server?
@@ -2558,11 +2558,10 @@
 
 			// Create and store the directory object for the root of this location
 			ASSERT(oid != 0);
-			if(pLoc->mpDirectoryRecord.get() == NULL)
+			if(pLoc->mapDirectoryRecord.get() == NULL)
 			{
-				BackupClientDirectoryRecord *precord =
-					new BackupClientDirectoryRecord(oid, *pLocName);
-				pLoc->mpDirectoryRecord.reset(precord);
+				pLoc->mapDirectoryRecord.reset(
+					new BackupClientDirectoryRecord(oid, *pLocName));
 			}
 			
 			// Remove it from the temporary list to avoid deletion




More information about the Boxbackup-commit mailing list