summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-09-04 01:36:08 +0000
committerChris Wilson <chris+github@qwirx.com>2014-09-04 01:36:08 +0000
commit426a506afd1ffb3bd67e61b4693ee9bb968097a1 (patch)
treea6a726552411a781e692de657e3a630fa8d65d65 /bin
parent75ad60bcc4d33589bb5afb307a87fd19b220a9e8 (diff)
Simplify code with macros, update comments and fix whitespace.
Hopefully all of these changes are inconsequential. Merged back changes from the test refactor branch to reduce diffs.
Diffstat (limited to 'bin')
-rw-r--r--bin/bbackupd/BackupClientContext.cpp10
-rw-r--r--bin/bbackupd/BackupClientContext.h11
-rw-r--r--bin/bbackupd/BackupClientDirectoryRecord.cpp60
-rw-r--r--bin/bbackupd/BackupDaemon.cpp51
-rw-r--r--bin/bbackupd/BackupDaemon.h24
-rw-r--r--bin/bbackupd/bbackupd.cpp10
-rw-r--r--bin/bbackupquery/BackupQueries.cpp4
7 files changed, 84 insertions, 86 deletions
diff --git a/bin/bbackupd/BackupClientContext.cpp b/bin/bbackupd/BackupClientContext.cpp
index 5025bf5c..977f7ec1 100644
--- a/bin/bbackupd/BackupClientContext.cpp
+++ b/bin/bbackupd/BackupClientContext.cpp
@@ -42,11 +42,11 @@
// --------------------------------------------------------------------------
BackupClientContext::BackupClientContext
(
- LocationResolver &rResolver,
- TLSContext &rTLSContext,
+ LocationResolver &rResolver,
+ TLSContext &rTLSContext,
const std::string &rHostname,
int Port,
- uint32_t AccountNumber,
+ uint32_t AccountNumber,
bool ExtendedLogging,
bool ExtendedLogToFile,
std::string ExtendedLogFile,
@@ -152,7 +152,7 @@ BackupProtocolClient &BackupClientContext::GetConnection()
if (mExtendedLogToFile)
{
ASSERT(mpExtendedLogFileHandle == NULL);
-
+
mpExtendedLogFileHandle = fopen(
mExtendedLogFile.c_str(), "a+");
@@ -198,7 +198,7 @@ BackupProtocolClient &BackupClientContext::GetConnection()
{
// IGNORE
}
-
+
// Then throw an exception about this
THROW_EXCEPTION_MESSAGE(BackupStoreException,
ClientMarkerNotAsExpected,
diff --git a/bin/bbackupd/BackupClientContext.h b/bin/bbackupd/BackupClientContext.h
index 7e081e2d..a1b5d824 100644
--- a/bin/bbackupd/BackupClientContext.h
+++ b/bin/bbackupd/BackupClientContext.h
@@ -42,11 +42,11 @@ class BackupClientContext : public DiffTimer
public:
BackupClientContext
(
- LocationResolver &rResolver,
- TLSContext &rTLSContext,
+ LocationResolver &rResolver,
+ TLSContext &rTLSContext,
const std::string &rHostname,
int32_t Port,
- uint32_t AccountNumber,
+ uint32_t AccountNumber,
bool ExtendedLogging,
bool ExtendedLogToFile,
std::string ExtendedLogFile,
@@ -59,11 +59,8 @@ private:
public:
BackupProtocolClient &GetConnection();
-
void CloseAnyOpenConnection();
-
int GetTimeout() const;
-
BackupClientDeleteList &GetDeleteList();
void PerformDeletions();
@@ -74,7 +71,7 @@ public:
void SetClientStoreMarker(int64_t ClientStoreMarker) {mClientStoreMarker = ClientStoreMarker;}
int64_t GetClientStoreMarker() const {return mClientStoreMarker;}
-
+
bool StorageLimitExceeded() {return mStorageLimitExceeded;}
void SetStorageLimitExceeded() {mStorageLimitExceeded = true;}
diff --git a/bin/bbackupd/BackupClientDirectoryRecord.cpp b/bin/bbackupd/BackupClientDirectoryRecord.cpp
index 9fa745ec..292330ab 100644
--- a/bin/bbackupd/BackupClientDirectoryRecord.cpp
+++ b/bin/bbackupd/BackupClientDirectoryRecord.cpp
@@ -652,14 +652,16 @@ BackupClientDirectoryRecord::FetchDirectoryListing(BackupClientDirectoryRecord::
std::auto_ptr<BackupStoreDirectory> apDir;
// Get connection to store
- BackupProtocolClient &connection(rParams.mrContext.GetConnection());
+ BackupProtocolCallable &connection(rParams.mrContext.GetConnection());
// Query the directory
std::auto_ptr<BackupProtocolSuccess> dirreply(connection.QueryListDirectory(
mObjectID,
- BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING, // both files and directories
- BackupProtocolListDirectory::Flags_Deleted |
- BackupProtocolListDirectory::Flags_OldVersion, // exclude old/deleted stuff
+ // both files and directories
+ BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
+ // exclude old/deleted stuff
+ BackupProtocolListDirectory::Flags_Deleted |
+ BackupProtocolListDirectory::Flags_OldVersion,
true /* want attributes */));
// Retrieve the directory from the stream following
@@ -825,7 +827,7 @@ bool BackupClientDirectoryRecord::UpdateItems(
rNotifier.NotifyFileStatFailed(this, nonVssFilePath,
strerror(errno));
- // Report the error (logs and
+ // Report the error (logs and
// eventual email to administrator)
SetErrorWhenReadingFilesystemObject(rParams, nonVssFilePath);
@@ -959,12 +961,12 @@ bool BackupClientDirectoryRecord::UpdateItems(
// Condition for upload:
// modification time within sync period
// if it's been seen before but not uploaded, is the time from this first sight longer than the MaxUploadWait
- // and if we know about it from a directory listing, that it hasn't got the same upload time as on the store
+ // and if we know about it from a directory listing, that it hasn't got the same upload time as on the store
bool doUpload = false;
std::string decisionReason = "unknown";
- // Only upload a file if the mod time locally is
+ // Only upload a file if the mod time locally is
// different to that on the server.
if (en == 0 || en->GetModificationTime() != modTime)
@@ -987,32 +989,32 @@ bool BackupClientDirectoryRecord::UpdateItems(
}
}
- // However, just in case things are continually
+ // However, just in case things are continually
// modified, we check the first seen time.
- // The two compares of syncPeriodEnd and
- // pendingFirstSeenTime are because the values
+ // The two compares of syncPeriodEnd and
+ // pendingFirstSeenTime are because the values
// are unsigned.
- if (!doUpload &&
+ if (!doUpload &&
pendingFirstSeenTime != 0 &&
rParams.mSyncPeriodEnd > pendingFirstSeenTime &&
- (rParams.mSyncPeriodEnd - pendingFirstSeenTime)
+ (rParams.mSyncPeriodEnd - pendingFirstSeenTime)
> rParams.mMaxUploadWait)
{
doUpload = true;
decisionReason = "continually modified";
}
- // Then make sure that if files are added with a
+ // Then make sure that if files are added with a
// time less than the sync period start
- // (which can easily happen on file server), it
+ // (which can easily happen on file server), it
// gets uploaded. The directory contents checksum
- // will pick up the fact it has been added, so the
+ // will pick up the fact it has been added, so the
// store listing will be available when this happens.
if (!doUpload &&
- modTime <= rParams.mSyncPeriodStart &&
- en != 0 &&
+ modTime <= rParams.mSyncPeriodStart &&
+ en != 0 &&
en->GetModificationTime() != modTime)
{
doUpload = true;
@@ -1023,7 +1025,7 @@ bool BackupClientDirectoryRecord::UpdateItems(
// the future for file server clients,
// just upload the file if it's madly in the future.
- if (!doUpload && modTime >
+ if (!doUpload && modTime >
rParams.mUploadAfterThisTimeInTheFuture)
{
doUpload = true;
@@ -1044,14 +1046,14 @@ bool BackupClientDirectoryRecord::UpdateItems(
int age = BoxTimeToSeconds(now -
modTime);
std::ostringstream s;
- s << "modified too recently: "
- "only " << age << " seconds ago";
+ s << "modified too recently: only " <<
+ age << " seconds ago";
decisionReason = s.str();
}
else
{
std::ostringstream s;
- s << "mod time is " << modTime <<
+ s << "mod time is " << modTime <<
" which is outside sync window, "
<< rParams.mSyncPeriodStart << " to "
<< rParams.mSyncPeriodEnd;
@@ -1082,7 +1084,7 @@ bool BackupClientDirectoryRecord::UpdateItems(
{
// Upload the file to the server, recording the
// object ID it returns
- bool noPreviousVersionOnServer =
+ bool noPreviousVersionOnServer =
((pDirOnStore != 0) && (en == 0));
// Surround this in a try/catch block, to
@@ -1126,7 +1128,7 @@ bool BackupClientDirectoryRecord::UpdateItems(
if (e.GetType() == BackupStoreException::ExceptionType &&
e.GetSubType() == BackupStoreException::SignalReceived)
{
- // abort requested, pass the
+ // abort requested, pass the
// exception on up.
throw;
}
@@ -1287,7 +1289,7 @@ bool BackupClientDirectoryRecord::UpdateItems(
// Erase contents of files to save space when recursing
rFiles.clear();
- // Delete the pending entries, if the map is entry
+ // Delete the pending entries, if the map is empty
if(mpPendingEntries != 0 && mpPendingEntries->size() == 0)
{
BOX_TRACE("Deleting mpPendingEntries from dir ID " <<
@@ -1761,7 +1763,7 @@ int64_t BackupClientDirectoryRecord::UploadFile(
rLocalPath,
mObjectID, /* containing directory */
rStoreFilename, diffFromID, *blockIndexStream,
- connection.GetTimeout(),
+ connection.GetTimeout(),
&rContext, // DiffTimer implementation
0 /* not interested in the modification time */,
&isCompletelyDifferent,
@@ -1809,11 +1811,9 @@ int64_t BackupClientDirectoryRecord::UploadFile(
// Send to store
std::auto_ptr<BackupProtocolSuccess> stored(
- connection.QueryStoreFile(
- mObjectID, ModificationTime,
- AttributesHash,
- diffFromID,
- rStoreFilename, apWrappedStream));
+ connection.QueryStoreFile(mObjectID, ModificationTime,
+ AttributesHash, diffFromID, rStoreFilename,
+ apWrappedStream));
rContext.SetNiceMode(false);
diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp
index 0fca634c..5b965c26 100644
--- a/bin/bbackupd/BackupDaemon.cpp
+++ b/bin/bbackupd/BackupDaemon.cpp
@@ -870,8 +870,8 @@ void BackupDaemon::RunSyncNow()
// just connect, as this may be unnecessary)
BackupClientContext clientContext
(
- *mpLocationResolver,
- mTlsContext,
+ *mpLocationResolver,
+ mTlsContext,
conf.GetKeyValue("StoreHostname"),
conf.GetKeyValueInt("StorePort"),
conf.GetKeyValueUint32("AccountNumber"),
@@ -929,19 +929,18 @@ void BackupDaemon::RunSyncNow()
// Paranoid check on sync times
if(syncPeriodStart >= syncPeriodEnd) return;
- // Adjust syncPeriodEnd to emulate snapshot
- // behaviour properly
+ // Adjust syncPeriodEnd to emulate snapshot behaviour properly
box_time_t syncPeriodEndExtended = syncPeriodEnd;
// Using zero min file age?
if(minimumFileAge == 0)
{
// Add a year on to the end of the end time,
- // to make sure we sync files which are
+ // to make sure we sync files which are
// modified after the scan run started.
- // Of course, they may be eligible to be
+ // Of course, they may be eligible to be
// synced again the next time round,
- // but this should be OK, because the changes
+ // but this should be OK, because the changes
// only upload should upload no data.
syncPeriodEndExtended += SecondsToBoxTime(
(time_t)(356*24*3600));
@@ -954,11 +953,11 @@ void BackupDaemon::RunSyncNow()
params.mSyncPeriodEnd = syncPeriodEndExtended;
// use potentially extended end time
params.mMaxUploadWait = maxUploadWait;
- params.mFileTrackingSizeThreshold =
+ params.mFileTrackingSizeThreshold =
conf.GetKeyValueInt("FileTrackingSizeThreshold");
- params.mDiffingUploadSizeThreshold =
+ params.mDiffingUploadSizeThreshold =
conf.GetKeyValueInt("DiffingUploadSizeThreshold");
- params.mMaxFileTimeInFuture =
+ params.mMaxFileTimeInFuture =
SecondsToBoxTime(conf.GetKeyValueInt("MaxFileTimeInFuture"));
mNumFilesUploaded = 0;
mNumDirsCreated = 0;
@@ -997,22 +996,21 @@ void BackupDaemon::RunSyncNow()
// Set store marker
clientContext.SetClientStoreMarker(mClientStoreMarker);
-
- // Set up the locations, if necessary --
- // need to do it here so we have a
- // (potential) connection to use
+
+ // Set up the locations, if necessary -- need to do it here so we have
+ // a (potential) connection to use.
{
const Configuration &locations(
conf.GetSubConfiguration(
"BackupLocations"));
-
+
// Make sure all the directory records
// are set up
SetupLocations(clientContext, locations);
}
-
+
mpProgressNotifier->NotifyIDMapsSetup(clientContext);
-
+
// Get some ID maps going
SetupIDMapsForSync();
@@ -1022,7 +1020,7 @@ void BackupDaemon::RunSyncNow()
#ifdef ENABLE_VSS
CreateVssBackupComponents();
#endif
-
+
// Go through the records, syncing them
for(Locations::const_iterator
i(mLocations.begin());
@@ -1055,7 +1053,7 @@ void BackupDaemon::RunSyncNow()
// Unset exclude lists (just in case)
clientContext.SetExcludeLists(0, 0);
}
-
+
// Perform any deletions required -- these are
// delayed until the end to allow renaming to
// happen neatly.
@@ -1087,8 +1085,8 @@ void BackupDaemon::RunSyncNow()
CommitIDMapsAfterSync();
// Calculate when the next sync run should be
- mNextSyncTime = mCurrentSyncStartTime +
- mUpdateStoreInterval +
+ mNextSyncTime = mCurrentSyncStartTime +
+ mUpdateStoreInterval +
Random::RandomInt(mUpdateStoreInterval >>
SYNC_PERIOD_RANDOM_EXTRA_TIME_SHIFT_BY);
@@ -1098,7 +1096,7 @@ void BackupDaemon::RunSyncNow()
// info. If we save successfully, we must
// delete the file next time we start a backup
- mDeleteStoreObjectInfoFile =
+ mDeleteStoreObjectInfoFile =
SerializeStoreObjectInfo(mLastSyncTime, mNextSyncTime);
// --------------------------------------------------------------------------------------------
@@ -1804,7 +1802,8 @@ int BackupDaemon::ParseSyncAllowScriptOutput(const std::string& script,
if(delay == "")
{
- BOX_ERROR("SyncAllowScript output an empty line");
+ BOX_ERROR("SyncAllowScript output an empty line, sleeping for "
+ << waitInSeconds << " seconds (" << script << ")");
return waitInSeconds;
}
@@ -1815,7 +1814,7 @@ int BackupDaemon::ParseSyncAllowScriptOutput(const std::string& script,
waitInSeconds = -1;
BOX_NOTICE("SyncAllowScript requested a backup now "
- << "(" << script << ")");
+ "(" << script << ")");
}
else
{
@@ -1832,7 +1831,7 @@ int BackupDaemon::ParseSyncAllowScriptOutput(const std::string& script,
throw;
}
- BOX_NOTICE("SyncAllowScript requested a delay of " <<
+ BOX_NOTICE("SyncAllowScript requested a delay of " <<
waitInSeconds << " seconds (" << script << ")");
}
@@ -2546,7 +2545,7 @@ void BackupDaemon::SetupLocations(BackupClientContext &rClientContext, const Con
new MemBlockStream(attr));
std::auto_ptr<BackupProtocolSuccess>
dirCreate(connection.QueryCreateDirectory(
- BackupProtocolListDirectory::RootDirectory,
+ BACKUPSTORE_ROOT_DIRECTORY_ID, // containing directory
attrModTime, dirname, attrStream));
// Object ID for later creation
diff --git a/bin/bbackupd/BackupDaemon.h b/bin/bbackupd/BackupDaemon.h
index ca3382fa..925aea1a 100644
--- a/bin/bbackupd/BackupDaemon.h
+++ b/bin/bbackupd/BackupDaemon.h
@@ -237,21 +237,21 @@ public:
void SetSysadminNotifier (SysadminNotifier* p) { mpSysadminNotifier = p; }
virtual bool RunBackgroundTask(State state, uint64_t progress,
uint64_t maximum);
-
+
private:
ProgressNotifier* mpProgressNotifier;
LocationResolver* mpLocationResolver;
RunStatusProvider* mpRunStatusProvider;
SysadminNotifier* mpSysadminNotifier;
std::auto_ptr<Timer> mapCommandSocketPollTimer;
-
- /* ProgressNotifier implementation */
+
+ /* ProgressNotifier implementation */
public:
virtual void NotifyIDMapsSetup(BackupClientContext& rContext) { }
virtual void NotifyScanDirectory(
const BackupClientDirectoryRecord* pDirRecord,
- const std::string& rLocalPath)
+ const std::string& rLocalPath)
{
if (mLogAllFileAccess)
{
@@ -266,7 +266,7 @@ public:
}
virtual void NotifyDirStatFailed(
const BackupClientDirectoryRecord* pDirRecord,
- const std::string& rLocalPath,
+ const std::string& rLocalPath,
const std::string& rErrorMsg)
{
BOX_WARNING("Failed to access directory: " << rLocalPath
@@ -293,11 +293,11 @@ public:
const std::string& rLocalPath)
{
#ifdef WIN32
- BOX_WARNING("Ignored directory: " << rLocalPath <<
+ BOX_WARNING("Ignored directory: " << rLocalPath <<
": is an NTFS junction/reparse point; create "
"a new location if you want to back it up");
#else
- BOX_WARNING("Ignored directory: " << rLocalPath <<
+ BOX_WARNING("Ignored directory: " << rLocalPath <<
": is a mount point; create a new location "
"if you want to back it up");
#endif
@@ -446,7 +446,7 @@ public:
{
if (mLogAllFileAccess)
{
- BOX_NOTICE("Deleted directory: " << rRemotePath <<
+ BOX_NOTICE("Deleted directory: " << rRemotePath <<
" (ID " << BOX_FORMAT_OBJECTID(ObjectID) <<
")");
}
@@ -457,7 +457,7 @@ public:
{
if (mLogAllFileAccess)
{
- BOX_NOTICE("Deleted file: " << rRemotePath <<
+ BOX_NOTICE("Deleted file: " << rRemotePath <<
" (ID " << BOX_FORMAT_OBJECTID(ObjectID) <<
")");
}
@@ -465,19 +465,19 @@ public:
virtual void NotifyReadProgress(int64_t readSize, int64_t offset,
int64_t length, box_time_t elapsed, box_time_t finish)
{
- BOX_TRACE("Read " << readSize << " bytes at " << offset <<
+ BOX_TRACE("Read " << readSize << " bytes at " << offset <<
", " << (length - offset) << " remain, eta " <<
BoxTimeToSeconds(finish - elapsed) << "s");
}
virtual void NotifyReadProgress(int64_t readSize, int64_t offset,
int64_t length)
{
- BOX_TRACE("Read " << readSize << " bytes at " << offset <<
+ BOX_TRACE("Read " << readSize << " bytes at " << offset <<
", " << (length - offset) << " remain");
}
virtual void NotifyReadProgress(int64_t readSize, int64_t offset)
{
- BOX_TRACE("Read " << readSize << " bytes at " << offset <<
+ BOX_TRACE("Read " << readSize << " bytes at " << offset <<
", unknown bytes remaining");
}
diff --git a/bin/bbackupd/bbackupd.cpp b/bin/bbackupd/bbackupd.cpp
index bb64f745..5977615f 100644
--- a/bin/bbackupd/bbackupd.cpp
+++ b/bin/bbackupd/bbackupd.cpp
@@ -45,10 +45,12 @@ int main(int argc, const char *argv[])
#else // !WIN32
- BackupDaemon daemon;
- ExitCode = daemon.Main(BOX_GET_DEFAULT_BBACKUPD_CONFIG_FILE,
- argc, argv);
-
+ {
+ BackupDaemon daemon;
+ ExitCode = daemon.Main(BOX_GET_DEFAULT_BBACKUPD_CONFIG_FILE,
+ argc, argv);
+ }
+
#endif // WIN32
MAINHELPER_END
diff --git a/bin/bbackupquery/BackupQueries.cpp b/bin/bbackupquery/BackupQueries.cpp
index c701ff7e..7bd2e367 100644
--- a/bin/bbackupquery/BackupQueries.cpp
+++ b/bin/bbackupquery/BackupQueries.cpp
@@ -291,8 +291,8 @@ void BackupQueries::CommandList(const std::vector<std::string> &args, const bool
#endif
// Attempt to find the directory
- rootDir = FindDirectoryObjectID(storeDirEncoded,
- opts[LIST_OPTION_ALLOWOLD],
+ rootDir = FindDirectoryObjectID(storeDirEncoded,
+ opts[LIST_OPTION_ALLOWOLD],
opts[LIST_OPTION_ALLOWDELETED]);
if(rootDir == 0)