summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-08-15 22:47:27 +0000
committerChris Wilson <chris+github@qwirx.com>2014-08-15 22:47:27 +0000
commit59b5045c4005dd85658de4f613237e21e897f6b2 (patch)
treea133d48298c03d5ab7baddc7d1fc308dc3ee1da8
parent84d41d846b44d94ec87105e92aa5a2513975dd2b (diff)
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.
-rw-r--r--bin/bbackupd/BackupClientDirectoryRecord.cpp63
-rw-r--r--bin/bbackupd/BackupClientDirectoryRecord.h6
-rw-r--r--bin/bbackupd/BackupDaemon.cpp17
3 files changed, 31 insertions, 55 deletions
diff --git a/bin/bbackupd/BackupClientDirectoryRecord.cpp b/bin/bbackupd/BackupClientDirectoryRecord.cpp
index 79a46a05..897c02e4 100644
--- a/bin/bbackupd/BackupClientDirectoryRecord.cpp
+++ b/bin/bbackupd/BackupClientDirectoryRecord.cpp
@@ -2117,11 +2117,8 @@ void BackupClientDirectoryRecord::Serialize(Archive & rArchive) const
//
// --------------------------------------------------------------------------
Location::Location()
- : mIDMapIndex(0),
- mpExcludeFiles(0),
- mpExcludeDirs(0)
-{
-}
+: mIDMapIndex(0)
+{ }
// --------------------------------------------------------------------------
//
@@ -2132,19 +2129,7 @@ Location::Location()
//
// --------------------------------------------------------------------------
Location::~Location()
-{
- // Clean up exclude locations
- if(mpExcludeDirs != 0)
- {
- delete mpExcludeDirs;
- mpExcludeDirs = 0;
- }
- if(mpExcludeFiles != 0)
- {
- delete mpExcludeFiles;
- mpExcludeFiles = 0;
- }
-}
+{ }
// --------------------------------------------------------------------------
//
@@ -2168,7 +2153,7 @@ void Location::Serialize(Archive & rArchive) const
//
//
//
- if(mpDirectoryRecord.get() == NULL)
+ if(!mapDirectoryRecord.get())
{
int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP;
rArchive.Write(aMagicMarker);
@@ -2178,13 +2163,13 @@ void Location::Serialize(Archive & rArchive) const
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 @@ void Location::Serialize(Archive & rArchive) const
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 @@ void Location::Serialize(Archive & rArchive) const
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 @@ void Location::Deserialize(Archive &rArchive)
//
//
//
- 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 @@ void Location::Deserialize(Archive &rArchive)
throw std::bad_alloc();
}
- mpDirectoryRecord.reset(pSubRecord);
- mpDirectoryRecord->Deserialize(rArchive);
+ mapDirectoryRecord.reset(pSubRecord);
+ mapDirectoryRecord->Deserialize(rArchive);
}
else
{
@@ -2285,13 +2262,13 @@ void Location::Deserialize(Archive &rArchive)
}
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 @@ void Location::Deserialize(Archive &rArchive)
}
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
{
diff --git a/bin/bbackupd/BackupClientDirectoryRecord.h b/bin/bbackupd/BackupClientDirectoryRecord.h
index 5af4d9ac..7c2b98fc 100644
--- a/bin/bbackupd/BackupClientDirectoryRecord.h
+++ b/bin/bbackupd/BackupClientDirectoryRecord.h
@@ -214,10 +214,10 @@ private:
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;
diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp
index 3d352286..577b1861 100644
--- a/bin/bbackupd/BackupDaemon.cpp
+++ b/bin/bbackupd/BackupDaemon.cpp
@@ -1034,8 +1034,8 @@ void BackupDaemon::RunSyncNow()
// 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 @@ void BackupDaemon::RunSyncNow()
}
#endif
- (*i)->mpDirectoryRecord->SyncDirectory(params,
+ (*i)->mapDirectoryRecord->SyncDirectory(params,
BackupProtocolListDirectory::RootDirectory,
locationPath, std::string("/") + (*i)->mName, **i);
@@ -2408,8 +2408,8 @@ void BackupDaemon::SetupLocations(BackupClientContext &rClientContext, const Con
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 @@ void BackupDaemon::SetupLocations(BackupClientContext &rClientContext, const Con
// 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