summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ebourne <martin@ebourne.me.uk>2005-12-20 08:20:33 +0000
committerMartin Ebourne <martin@ebourne.me.uk>2005-12-20 08:20:33 +0000
commit8c4be43948dbe9a3bafd9d2fa8f350cb3359828e (patch)
treefc06a296bb9622bd5da7adad52e94d900aa48809
parentee95f5d73a7f2ca50d38dea6e862a6c683dfc8cc (diff)
Rationalise type usage for time values. Now:
Box time is always box_time_t seconds is time_t microseconds is uint64_t
-rw-r--r--bin/bbackupd/BackupClientContext.cpp2
-rw-r--r--bin/bbackupd/BackupDaemon.cpp21
-rw-r--r--bin/bbackupquery/BackupQueries.cpp2
-rw-r--r--bin/bbstored/BBStoreDHousekeeping.cpp4
-rw-r--r--lib/common/BoxTime.cpp3
-rw-r--r--lib/common/BoxTime.h10
-rw-r--r--lib/common/BoxTimeToText.cpp4
-rw-r--r--test/bbackupd/testbbackupd.cpp4
8 files changed, 23 insertions, 27 deletions
diff --git a/bin/bbackupd/BackupClientContext.cpp b/bin/bbackupd/BackupClientContext.cpp
index 50f2cd08..38d0b98c 100644
--- a/bin/bbackupd/BackupClientContext.cpp
+++ b/bin/bbackupd/BackupClientContext.cpp
@@ -201,7 +201,7 @@ void BackupClientContext::CloseAnyOpenConnection()
if(mClientStoreMarker == ClientStoreMarker_NotKnown)
{
// Yes, choose one, the current time will do
- int64_t marker = GetCurrentBoxTime();
+ box_time_t marker = GetCurrentBoxTime();
// Set it on the store
mpConnection->QuerySetClientStoreMarker(marker);
diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp
index c56aaa59..6c5422ca 100644
--- a/bin/bbackupd/BackupDaemon.cpp
+++ b/bin/bbackupd/BackupDaemon.cpp
@@ -64,7 +64,7 @@
#include "MemLeakFindOn.h"
-#define MAX_SLEEP_TIME ((unsigned int)1024)
+static const time_t MAX_SLEEP_TIME = 1024;
// Make the actual sync period have a little bit of extra time, up to a 64th of the main sync period.
// This prevents repetative cycles of load on the server
@@ -444,16 +444,16 @@ void BackupDaemon::Run2()
// Setup various timings
// How often to connect to the store (approximate)
- box_time_t updateStoreInterval = SecondsToBoxTime((uint32_t)conf.GetKeyValueInt("UpdateStoreInterval"));
+ box_time_t updateStoreInterval = SecondsToBoxTime(conf.GetKeyValueInt("UpdateStoreInterval"));
// But are we connecting automatically?
bool automaticBackup = conf.GetKeyValueBool("AutomaticBackup");
// The minimum age a file needs to be before it will be considered for uploading
- box_time_t minimumFileAge = SecondsToBoxTime((uint32_t)conf.GetKeyValueInt("MinimumFileAge"));
+ box_time_t minimumFileAge = SecondsToBoxTime(conf.GetKeyValueInt("MinimumFileAge"));
// The maximum time we'll wait to upload a file, regardless of how often it's modified
- box_time_t maxUploadWait = SecondsToBoxTime((uint32_t)conf.GetKeyValueInt("MaxUploadWait"));
+ box_time_t maxUploadWait = SecondsToBoxTime(conf.GetKeyValueInt("MaxUploadWait"));
// Adjust by subtracting the minimum file age, so is relative to sync period end in comparisons
maxUploadWait = (maxUploadWait > minimumFileAge)?(maxUploadWait - minimumFileAge):(0);
@@ -492,7 +492,8 @@ void BackupDaemon::Run2()
// Pause a while, but no more than MAX_SLEEP_TIME seconds (use the conditional because times are unsigned)
box_time_t requiredDelay = (nextSyncTime < currentTime)?(0):(nextSyncTime - currentTime);
// If there isn't automatic backup happening, set a long delay. And limit delays at the same time.
- if(!automaticBackup || requiredDelay > SecondsToBoxTime((uint32_t)MAX_SLEEP_TIME)) requiredDelay = SecondsToBoxTime((uint32_t)MAX_SLEEP_TIME);
+ if(!automaticBackup || requiredDelay > SecondsToBoxTime(MAX_SLEEP_TIME))
+ requiredDelay = SecondsToBoxTime(MAX_SLEEP_TIME);
// Only do the delay if there is a delay required
if(requiredDelay > 0)
@@ -506,7 +507,7 @@ void BackupDaemon::Run2()
else
{
// No command socket or connection, just do a normal sleep
- int sleepSeconds = BoxTimeToSeconds(requiredDelay);
+ time_t sleepSeconds = BoxTimeToSeconds(requiredDelay);
::sleep((sleepSeconds <= 0)?1:sleepSeconds);
}
}
@@ -528,7 +529,7 @@ void BackupDaemon::Run2()
if(d > 0)
{
// Script has asked for a delay
- nextSyncTime = GetCurrentBoxTime() + SecondsToBoxTime((uint32_t)d);
+ nextSyncTime = GetCurrentBoxTime() + SecondsToBoxTime(d);
doSync = false;
}
}
@@ -562,7 +563,7 @@ void BackupDaemon::Run2()
// files which are modified after the scan run started.
// Of course, they may be eligable to be synced again the next time round,
// but this should be OK, because the changes only upload should upload no data.
- syncPeriodEndExtended += SecondsToBoxTime((uint32_t)(356*24*3600));
+ syncPeriodEndExtended += SecondsToBoxTime((time_t)(356*24*3600));
}
// Do sync
@@ -587,7 +588,7 @@ void BackupDaemon::Run2()
params.mMaxUploadWait = maxUploadWait;
params.mFileTrackingSizeThreshold = conf.GetKeyValueInt("FileTrackingSizeThreshold");
params.mDiffingUploadSizeThreshold = conf.GetKeyValueInt("DiffingUploadSizeThreshold");
- params.mMaxFileTimeInFuture = SecondsToBoxTime((uint32_t)conf.GetKeyValueInt("MaxFileTimeInFuture"));
+ params.mMaxFileTimeInFuture = SecondsToBoxTime(conf.GetKeyValueInt("MaxFileTimeInFuture"));
// Set store marker
clientContext.SetClientStoreMarker(clientStoreMarker);
@@ -1397,7 +1398,7 @@ TRACE0("new location\n");
ASSERT(mUnusedRootDirEntries.size() > 0);
// Time to delete them
mDeleteUnusedRootDirEntriesAfter =
- GetCurrentBoxTime() + SecondsToBoxTime((uint32_t)BACKUP_DELETE_UNUSED_ROOT_ENTRIES_AFTER);
+ GetCurrentBoxTime() + SecondsToBoxTime(BACKUP_DELETE_UNUSED_ROOT_ENTRIES_AFTER);
}
}
diff --git a/bin/bbackupquery/BackupQueries.cpp b/bin/bbackupquery/BackupQueries.cpp
index b37abc9d..02b60aa3 100644
--- a/bin/bbackupquery/BackupQueries.cpp
+++ b/bin/bbackupquery/BackupQueries.cpp
@@ -956,7 +956,7 @@ void BackupQueries::CommandCompare(const std::vector<std::string> &args, const b
{
// Files modified after this time shouldn't be on the server, so report errors slightly differently
params.mLatestFileUploadTime = FileModificationTime(st)
- - SecondsToBoxTime((uint32_t)mrConfiguration.GetKeyValueInt("MinimumFileAge"));
+ - SecondsToBoxTime(mrConfiguration.GetKeyValueInt("MinimumFileAge"));
}
else
{
diff --git a/bin/bbstored/BBStoreDHousekeeping.cpp b/bin/bbstored/BBStoreDHousekeeping.cpp
index 2eb19089..d3656630 100644
--- a/bin/bbstored/BBStoreDHousekeeping.cpp
+++ b/bin/bbstored/BBStoreDHousekeeping.cpp
@@ -33,7 +33,7 @@ void BackupStoreDaemon::HousekeepingProcess()
{
// Get the time between housekeeping runs
const Configuration &rconfig(GetConfiguration());
- int64_t housekeepingInterval = SecondsToBoxTime((uint32_t)rconfig.GetKeyValueInt("TimeBetweenHousekeeping"));
+ int64_t housekeepingInterval = SecondsToBoxTime(rconfig.GetKeyValueInt("TimeBetweenHousekeeping"));
int64_t lastHousekeepingRun = 0;
@@ -108,7 +108,7 @@ void BackupStoreDaemon::HousekeepingProcess()
// Calculate how long should wait before doing the next housekeeping run
timeNow = GetCurrentBoxTime();
- int64_t secondsToGo = BoxTimeToSeconds((lastHousekeepingRun + housekeepingInterval) - timeNow);
+ time_t secondsToGo = BoxTimeToSeconds((lastHousekeepingRun + housekeepingInterval) - timeNow);
if(secondsToGo < 1) secondsToGo = 1;
if(secondsToGo > 60) secondsToGo = 60;
int32_t millisecondsToGo = ((int)secondsToGo) * 1000;
diff --git a/lib/common/BoxTime.cpp b/lib/common/BoxTime.cpp
index feada309..960fc329 100644
--- a/lib/common/BoxTime.cpp
+++ b/lib/common/BoxTime.cpp
@@ -25,8 +25,7 @@
// --------------------------------------------------------------------------
box_time_t GetCurrentBoxTime()
{
- ASSERT(sizeof(uint32_t) == sizeof(time_t));
- return SecondsToBoxTime((uint32_t)time(0));
+ return SecondsToBoxTime(time(0));
}
diff --git a/lib/common/BoxTime.h b/lib/common/BoxTime.h
index d166d6e7..398e6b1c 100644
--- a/lib/common/BoxTime.h
+++ b/lib/common/BoxTime.h
@@ -23,19 +23,15 @@ typedef uint64_t box_time_t;
box_time_t GetCurrentBoxTime();
-inline box_time_t SecondsToBoxTime(uint32_t Seconds)
+inline box_time_t SecondsToBoxTime(time_t Seconds)
{
return ((box_time_t)Seconds * MICRO_SEC_IN_SEC_LL);
}
-inline box_time_t SecondsToBoxTime(uint64_t Seconds)
-{
- return ((box_time_t)Seconds * MICRO_SEC_IN_SEC_LL);
-}
-inline box_time_t BoxTimeToSeconds(box_time_t Time)
+inline time_t BoxTimeToSeconds(box_time_t Time)
{
return Time / MICRO_SEC_IN_SEC_LL;
}
-inline box_time_t BoxTimeToMilliSeconds(box_time_t Time)
+inline uint64_t BoxTimeToMilliSeconds(box_time_t Time)
{
return Time / MILLI_SEC_IN_NANO_SEC_LL;
}
diff --git a/lib/common/BoxTimeToText.cpp b/lib/common/BoxTimeToText.cpp
index 297d2100..ff8b2e49 100644
--- a/lib/common/BoxTimeToText.cpp
+++ b/lib/common/BoxTimeToText.cpp
@@ -29,7 +29,7 @@ std::string BoxTimeToISO8601String(box_time_t Time)
{
#ifdef WIN32
struct tm *time;
- box_time_t bob = BoxTimeToSeconds(Time);
+ time_t bob = BoxTimeToSeconds(Time);
__time64_t winTime = bob;
@@ -46,7 +46,7 @@ std::string BoxTimeToISO8601String(box_time_t Time)
time->tm_mon + 1, time->tm_mday, time->tm_hour,
time->tm_min, time->tm_sec);
#else // ! WIN32
- time_t timeInSecs = (time_t)BoxTimeToSeconds(Time);
+ time_t timeInSecs = BoxTimeToSeconds(Time);
struct tm time;
gmtime_r(&timeInSecs, &time);
diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp
index acd13a10..560cf16f 100644
--- a/test/bbackupd/testbbackupd.cpp
+++ b/test/bbackupd/testbbackupd.cpp
@@ -452,7 +452,7 @@ int test_bbackupd()
fclose(f);
// and then move the time backwards!
struct timeval times[2];
- BoxTimeToTimeval(SecondsToBoxTime((uint32_t)(365*24*60*60)), times[1]);
+ BoxTimeToTimeval(SecondsToBoxTime((time_t)(365*24*60*60)), times[1]);
times[0] = times[1];
TEST_THAT(::utimes("testfiles/TestDir1/sub23/rand.h", times) == 0);
}
@@ -646,7 +646,7 @@ int test_bbackupd()
fclose(f);
// and then move the time forwards!
struct timeval times[2];
- BoxTimeToTimeval(GetCurrentBoxTime() + SecondsToBoxTime((uint32_t)(365*24*60*60)), times[1]);
+ BoxTimeToTimeval(GetCurrentBoxTime() + SecondsToBoxTime((time_t)(365*24*60*60)), times[1]);
times[0] = times[1];
TEST_THAT(::utimes("testfiles/TestDir1/sub23/in-the-future", times) == 0);
}