[Box Backup-dev] COMMIT r350 - in box/chris/bb-save-state: . bin/bbackupd lib/common
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Sun, 29 Jan 2006 22:40:50 +0000 (GMT)
Author: chris
Date: 2006-01-29 22:40:45 +0000 (Sun, 29 Jan 2006)
New Revision: 350
Modified:
box/chris/bb-save-state/BUGS.txt
box/chris/bb-save-state/bin/bbackupd/BackupClientDirectoryRecord.cpp
box/chris/bb-save-state/bin/bbackupd/BackupDaemon.cpp
box/chris/bb-save-state/lib/common/Archive.h
box/chris/bb-save-state/lib/common/ExcludeList.cpp
Log:
* lib/common/Archive.h
* lib/common/ExcludeList.cpp
* bin/bbackupd/BackupClientDirectoryRecord.cpp
* bin/bbackupd/BackupDaemon.cpp
- Removed all operator overloading for Archive
- Changed Get() to Read(), and Add() to Write(), to match Protocol
- Minor spacing and comment cleanups
* BUGS.txt
- Removed the note about converting Archive to remove operator overloading
Modified: box/chris/bb-save-state/BUGS.txt
===================================================================
--- box/chris/bb-save-state/BUGS.txt 2006-01-29 21:06:37 UTC (rev 349)
+++ box/chris/bb-save-state/BUGS.txt 2006-01-29 22:40:45 UTC (rev 350)
@@ -9,7 +9,7 @@
* bbackupquery restore, if not root, then won't do file ownership properly, but won't alert the user to this fact
* empty (real) directories in the store aren't deleted when they're empty (and will never be used again) -- uses up disc space unnecessarily
* need unit tests for SSL keepalives and state saving (serialisation)
-* make Archive derive from Protocol, eliminate << operator overloading >>
+* make Archive derive from Protocol
* more automated tests for win32
* change off_t to box_off_t in preparation for win32 large file support
* support large files on win32 by using native *i64 functions instead of posix
Modified: box/chris/bb-save-state/bin/bbackupd/BackupClientDirectoryRecord.cpp
===================================================================
--- box/chris/bb-save-state/bin/bbackupd/BackupClientDirectoryRecord.cpp 2006-01-29 21:06:37 UTC (rev 349)
+++ box/chris/bb-save-state/bin/bbackupd/BackupClientDirectoryRecord.cpp 2006-01-29 22:40:45 UTC (rev 350)
@@ -1235,13 +1235,16 @@
//
//
//
- rArchive >> mObjectID >> mSubDirName >> mInitialSyncDone >> mSyncDone;
+ rArchive.Read(mObjectID);
+ rArchive.Read(mSubDirName);
+ rArchive.Read(mInitialSyncDone);
+ rArchive.Read(mSyncDone);
//
//
//
int64_t iCount = 0;
- rArchive.Get(iCount);
+ rArchive.Read(iCount);
if (iCount != sizeof(mStateChecksum)/sizeof(mStateChecksum[0]))
{
@@ -1250,26 +1253,33 @@
}
for (int v = 0; v < iCount; v++)
- /**** LOAD ****/ rArchive.Get(mStateChecksum[v]);
+ {
+ // Load each checksum entry
+ rArchive.Read(mStateChecksum[v]);
+ }
//
//
//
iCount = 0;
- rArchive.Get(iCount);
+ rArchive.Read(iCount);
if (iCount > 0)
{
- /**** LOAD ****/ mpPendingEntries = new std::map<std::string, box_time_t>;
+ // load each pending entry
+ mpPendingEntries = new std::map<std::string, box_time_t>;
if (!mpPendingEntries)
+ {
throw std::bad_alloc();
+ }
for (int v = 0; v < iCount; v++)
{
std::string strItem;
box_time_t btItem;
- rArchive >> strItem >> btItem;
+ rArchive.Read(strItem);
+ rArchive.Read(btItem);
(*mpPendingEntries)[strItem] = btItem;
}
}
@@ -1278,18 +1288,23 @@
//
//
iCount = 0;
- rArchive.Get(iCount);
+ rArchive.Read(iCount);
if (iCount > 0)
{
for (int v = 0; v < iCount; v++)
{
std::string strItem;
- rArchive.Get(strItem);
+ rArchive.Read(strItem);
- BackupClientDirectoryRecord* pSubDirRecord = new BackupClientDirectoryRecord(0, ""); // will be deserialized anyway, give it id 0 for now
+ BackupClientDirectoryRecord* pSubDirRecord =
+ new BackupClientDirectoryRecord(0, "");
+ // will be deserialized anyway, give it id 0 for now
+
if (!pSubDirRecord)
+ {
throw std::bad_alloc();
+ }
/***** RECURSE *****/
pSubDirRecord->Deserialize(rArchive);
@@ -1312,17 +1327,25 @@
//
//
//
- rArchive << mObjectID << mSubDirName << mInitialSyncDone << mSyncDone;
+ rArchive.Write(mObjectID);
+ rArchive.Write(mSubDirName);
+ rArchive.Write(mInitialSyncDone);
+ rArchive.Write(mSyncDone);
//
//
//
int64_t iCount = 0;
- iCount = sizeof(mStateChecksum)/sizeof(mStateChecksum[0]);
- rArchive.Add(iCount); // add count to see if we have crossed build-level mods
+ // when reading back the archive, we will
+ // need to know how many items there are.
+ iCount = sizeof(mStateChecksum) / sizeof(mStateChecksum[0]);
+ rArchive.Write(iCount);
+
for (int v = 0; v < iCount; v++)
- rArchive.Add(mStateChecksum[v]);
+ {
+ rArchive.Write(mStateChecksum[v]);
+ }
//
//
@@ -1330,28 +1353,35 @@
if (!mpPendingEntries)
{
iCount = 0;
- rArchive.Add(iCount);
+ rArchive.Write(iCount);
}
else
{
iCount = mpPendingEntries->size();
- rArchive.Add(iCount);
+ rArchive.Write(iCount);
- for (std::map<std::string, box_time_t>::const_iterator i = mpPendingEntries->begin(); i != mpPendingEntries->end(); i++)
- rArchive << (*i).first << (*i).second;
+ for (std::map<std::string, box_time_t>::const_iterator
+ i = mpPendingEntries->begin();
+ i != mpPendingEntries->end(); i++)
+ {
+ rArchive.Write(i->first);
+ rArchive.Write(i->second);
+ }
}
//
//
//
iCount = mSubDirectories.size();
- rArchive.Add(iCount);
+ rArchive.Write(iCount);
- for (std::map<std::string, BackupClientDirectoryRecord*>::const_iterator i = mSubDirectories.begin(); i != mSubDirectories.end(); i++)
+ for (std::map<std::string, BackupClientDirectoryRecord*>::const_iterator
+ i = mSubDirectories.begin();
+ i != mSubDirectories.end(); i++)
{
- const BackupClientDirectoryRecord* pSubItem = (*i).second;
+ const BackupClientDirectoryRecord* pSubItem = i->second;
ASSERT(pSubItem);
- rArchive.Add((*i).first);
+ rArchive.Write(i->first);
pSubItem->Serialize(rArchive);
}
}
Modified: box/chris/bb-save-state/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/bb-save-state/bin/bbackupd/BackupDaemon.cpp 2006-01-29 21:06:37 UTC (rev 349)
+++ box/chris/bb-save-state/bin/bbackupd/BackupDaemon.cpp 2006-01-29 22:40:45 UTC (rev 350)
@@ -1929,13 +1929,15 @@
//
//
//
- rArchive >> mName >> mPath >> mIDMapIndex;
+ rArchive.Read(mName);
+ rArchive.Read(mPath);
+ rArchive.Read(mIDMapIndex);
//
//
//
int64_t aMagicMarker = 0;
- rArchive.Get(aMagicMarker);
+ rArchive.Read(aMagicMarker);
if (aMagicMarker == ARCHIVE_MAGIC_VALUE_NOOP)
{
@@ -1959,7 +1961,7 @@
//
//
//
- rArchive.Get(aMagicMarker);
+ rArchive.Read(aMagicMarker);
if (aMagicMarker == ARCHIVE_MAGIC_VALUE_NOOP)
{
@@ -1982,7 +1984,7 @@
//
//
//
- rArchive.Get(aMagicMarker);
+ rArchive.Read(aMagicMarker);
if (aMagicMarker == ARCHIVE_MAGIC_VALUE_NOOP)
{
@@ -2017,7 +2019,9 @@
//
//
//
- rArchive << mName << mPath << mIDMapIndex;
+ rArchive.Write(mName);
+ rArchive.Write(mPath);
+ rArchive.Write(mIDMapIndex);
//
//
@@ -2025,12 +2029,12 @@
if (mpDirectoryRecord.get() == NULL)
{
int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP;
- rArchive.Add(aMagicMarker);
+ rArchive.Write(aMagicMarker);
}
else
{
int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_RECURSE; // be explicit about whether recursion follows
- rArchive.Add(aMagicMarker);
+ rArchive.Write(aMagicMarker);
mpDirectoryRecord->Serialize(rArchive);
}
@@ -2041,12 +2045,12 @@
if (!mpExcludeFiles)
{
int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP;
- rArchive.Add(aMagicMarker);
+ rArchive.Write(aMagicMarker);
}
else
{
int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_RECURSE; // be explicit about whether recursion follows
- rArchive.Add(aMagicMarker);
+ rArchive.Write(aMagicMarker);
mpExcludeFiles->Serialize(rArchive);
}
@@ -2057,12 +2061,12 @@
if (!mpExcludeDirs)
{
int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP;
- rArchive.Add(aMagicMarker);
+ rArchive.Write(aMagicMarker);
}
else
{
int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_RECURSE; // be explicit about whether recursion follows
- rArchive.Add(aMagicMarker);
+ rArchive.Write(aMagicMarker);
mpExcludeDirs->Serialize(rArchive);
}
@@ -2134,19 +2138,19 @@
O_WRONLY | O_CREAT | O_TRUNC);
IOStreamArchive anArchive(aFile, 0);
- anArchive.Add(STOREOBJECTINFO_MAGIC_ID_VALUE);
- anArchive.Add(STOREOBJECTINFO_MAGIC_ID_STRING);
- anArchive.Add(STOREOBJECTINFO_VERSION);
- anArchive.Add(GetLoadedConfigModifiedTime());
- anArchive.Add(aClientStoreMarker);
- anArchive.Add(theLastSyncTime);
- anArchive.Add(theNextSyncTime);
+ anArchive.Write(STOREOBJECTINFO_MAGIC_ID_VALUE);
+ anArchive.Write(STOREOBJECTINFO_MAGIC_ID_STRING);
+ anArchive.Write(STOREOBJECTINFO_VERSION);
+ anArchive.Write(GetLoadedConfigModifiedTime());
+ anArchive.Write(aClientStoreMarker);
+ anArchive.Write(theLastSyncTime);
+ anArchive.Write(theNextSyncTime);
//
//
//
int64_t iCount = mLocations.size();
- anArchive.Add(iCount);
+ anArchive.Write(iCount);
for (int v = 0; v < iCount; v++)
{
@@ -2158,10 +2162,10 @@
//
//
iCount = mIDMapMounts.size();
- anArchive.Add(iCount);
+ anArchive.Write(iCount);
for (int v = 0; v < iCount; v++)
- anArchive.Add(mIDMapMounts[v]);
+ anArchive.Write(mIDMapMounts[v]);
//
//
@@ -2219,7 +2223,7 @@
// see if the content looks like a valid serialised archive
//
int iMagicValue = 0;
- anArchive.Get(iMagicValue);
+ anArchive.Read(iMagicValue);
if (iMagicValue != STOREOBJECTINFO_MAGIC_ID_VALUE)
{
@@ -2234,7 +2238,7 @@
// get a bit optimistic and read in a string identifier
//
std::string strMagicValue;
- anArchive.Get(strMagicValue);
+ anArchive.Read(strMagicValue);
if (strMagicValue != STOREOBJECTINFO_MAGIC_ID_STRING)
{
@@ -2250,7 +2254,7 @@
// version by mistake
//
int iVersion = 0;
- anArchive.Get(iVersion);
+ anArchive.Read(iVersion);
if (iVersion != STOREOBJECTINFO_VERSION)
{
@@ -2267,7 +2271,7 @@
// for the loaded bbackupd.conf file
//
box_time_t lastKnownConfigModTime;
- anArchive.Get(lastKnownConfigModTime);
+ anArchive.Read(lastKnownConfigModTime);
if (lastKnownConfigModTime != GetLoadedConfigModifiedTime())
{
@@ -2280,15 +2284,15 @@
//
// this is it, go at it
//
- anArchive.Get(aClientStoreMarker);
- anArchive.Get(theLastSyncTime);
- anArchive.Get(theNextSyncTime);
+ anArchive.Read(aClientStoreMarker);
+ anArchive.Read(theLastSyncTime);
+ anArchive.Read(theNextSyncTime);
//
//
//
int64_t iCount = 0;
- anArchive.Get(iCount);
+ anArchive.Read(iCount);
for (int v = 0; v < iCount; v++)
{
@@ -2304,12 +2308,12 @@
//
//
iCount = 0;
- anArchive.Get(iCount);
+ anArchive.Read(iCount);
for (int v = 0; v < iCount; v++)
{
std::string strItem;
- anArchive.Get(strItem);
+ anArchive.Read(strItem);
mIDMapMounts.push_back(strItem);
}
Modified: box/chris/bb-save-state/lib/common/Archive.h
===================================================================
--- box/chris/bb-save-state/lib/common/Archive.h 2006-01-29 21:06:37 UTC (rev 349)
+++ box/chris/bb-save-state/lib/common/Archive.h 2006-01-29 22:40:45 UTC (rev 350)
@@ -34,39 +34,21 @@
//
// primitive insertion operations
//
- virtual void Add(bool bItem) = 0;
- virtual void Add(int iItem) = 0;
- virtual void Add(int64_t iItem) = 0;
- virtual void Add(uint64_t iItem) = 0;
- virtual void Add(uint8_t iItem) = 0;
- virtual void Add(const std::string & strItem) = 0;
+ virtual void Write(bool bItem) = 0;
+ virtual void Write(int iItem) = 0;
+ virtual void Write(int64_t iItem) = 0;
+ virtual void Write(uint64_t iItem) = 0;
+ virtual void Write(uint8_t iItem) = 0;
+ virtual void Write(const std::string & strItem) = 0;
//
- // chaining support
- //
- Archive & operator<<(bool bItem) { Add(bItem); return *this; }
- Archive & operator<<(int iItem) { Add(iItem); return *this; }
- Archive & operator<<(int64_t iItem) { Add(iItem); return *this; }
- Archive & operator<<(uint64_t iItem) { Add(iItem); return *this; }
- Archive & operator<<(uint8_t iItem) { Add(iItem); return *this; }
- Archive & operator<<(const std::string & strItem) { Add(strItem); return *this; }
- //
// primitive extraction oprations
//
- virtual void Get(bool & bItem) = 0;
- virtual void Get(int & iItem) = 0;
- virtual void Get(int64_t & iItem) = 0;
- virtual void Get(uint64_t & iItem) = 0;
- virtual void Get(uint8_t & iItem) = 0;
- virtual void Get(std::string & strItem) = 0;
- //
- // chaining support
- //
- Archive & operator>>(bool & bItem) { Get(bItem); return *this; }
- Archive & operator>>(int & iItem) { Get(iItem); return *this; }
- Archive & operator>>(int64_t & iItem) { Get(iItem); return *this; }
- Archive & operator>>(uint64_t & iItem) { Get(iItem); return *this; }
- Archive & operator>>(uint8_t & iItem) { Get(iItem); return *this; }
- Archive & operator>>(std::string & strItem) { Get(strItem); return *this; }
+ virtual void Read(bool & bItem) = 0;
+ virtual void Read(int & iItem) = 0;
+ virtual void Read(int64_t & iItem) = 0;
+ virtual void Read(uint64_t & iItem) = 0;
+ virtual void Read(uint8_t & iItem) = 0;
+ virtual void Read(std::string & strItem) = 0;
private:
Archive(const Archive &);
Archive & operator=(const Archive &);
@@ -85,43 +67,43 @@
//
//
//
- virtual void Add(bool bItem)
+ virtual void Write(bool bItem)
{
- Add((int) bItem);
+ Write((int) bItem);
}
- virtual void Add(int iItem)
+ virtual void Write(int iItem)
{
int32_t privItem = htonl(iItem);
mStream.Write(&privItem, sizeof(privItem));
}
- virtual void Add(int64_t iItem)
+ virtual void Write(int64_t iItem)
{
int64_t privItem = box_hton64(iItem);
mStream.Write(&privItem, sizeof(privItem));
}
- virtual void Add(uint64_t iItem)
+ virtual void Write(uint64_t iItem)
{
uint64_t privItem = box_hton64(iItem);
mStream.Write(&privItem, sizeof(privItem));
}
- virtual void Add(uint8_t iItem)
+ virtual void Write(uint8_t iItem)
{
int privItem = iItem;
- Add(privItem);
+ Write(privItem);
}
- virtual void Add(const std::string & strItem)
+ virtual void Write(const std::string & strItem)
{
int iSize = strItem.size();
- Add(iSize);
+ Write(iSize);
mStream.Write(strItem.c_str(), iSize);
}
//
//
//
- virtual void Get(bool & bItem)
+ virtual void Read(bool & bItem)
{
int privItem;
- Get(privItem);
+ Read(privItem);
if (privItem)
{
@@ -132,7 +114,7 @@
bItem = false;
}
}
- virtual void Get(int & iItem)
+ virtual void Read(int & iItem)
{
int32_t privItem;
if(!mStream.ReadFullBuffer(&privItem, sizeof(privItem), 0 /* not interested in bytes read if this fails */))
@@ -141,7 +123,7 @@
}
iItem = ntohl(privItem);
}
- virtual void Get(int64_t & iItem)
+ virtual void Read(int64_t & iItem)
{
int64_t privItem;
if(!mStream.ReadFullBuffer(&privItem, sizeof(privItem), 0 /* not interested in bytes read if this fails */))
@@ -150,7 +132,7 @@
}
iItem = box_ntoh64(privItem);
}
- virtual void Get(uint64_t & iItem)
+ virtual void Read(uint64_t & iItem)
{
uint64_t privItem;
if(!mStream.ReadFullBuffer(&privItem, sizeof(privItem), 0 /* not interested in bytes read if this fails */))
@@ -159,16 +141,16 @@
}
iItem = box_ntoh64(privItem);
}
- virtual void Get(uint8_t & iItem)
+ virtual void Read(uint8_t & iItem)
{
int privItem;
- Get(privItem);
+ Read(privItem);
iItem = privItem;
}
- virtual void Get(std::string & strItem)
+ virtual void Read(std::string & strItem)
{
int iSize;
- Get(iSize);
+ Read(iSize);
// Assume most strings are relatively small
char buf[256];
Modified: box/chris/bb-save-state/lib/common/ExcludeList.cpp
===================================================================
--- box/chris/bb-save-state/lib/common/ExcludeList.cpp 2006-01-29 21:06:37 UTC (rev 349)
+++ box/chris/bb-save-state/lib/common/ExcludeList.cpp 2006-01-29 22:40:45 UTC (rev 350)
@@ -256,16 +256,16 @@
//
//
int64_t iCount = 0;
- rArchive.Get(iCount);
+ rArchive.Read(iCount);
if (iCount > 0)
{
for (int v = 0; v < iCount; v++)
{
+ // load each one
std::string strItem;
- rArchive.Get(strItem);
-
- /**** LOAD ****/ mDefinite.insert(strItem);
+ rArchive.Read(strItem);
+ mDefinite.insert(strItem);
}
}
@@ -273,14 +273,14 @@
//
//
#ifndef PLATFORM_REGEX_NOT_SUPPORTED
- rArchive.Get(iCount);
+ rArchive.Read(iCount);
if (iCount > 0)
{
for (int v = 0; v < iCount; v++)
{
std::string strItem;
- rArchive.Get(strItem);
+ rArchive.Read(strItem);
// Allocate memory
regex_t* pregex = new regex_t;
@@ -288,15 +288,19 @@
try
{
// Compile
- if(::regcomp(pregex, strItem.c_str(), REG_EXTENDED | REG_NOSUB) != 0)
+ if(::regcomp(pregex, strItem.c_str(),
+ REG_EXTENDED | REG_NOSUB) != 0)
{
- THROW_EXCEPTION(CommonException, BadRegularExpression)
+ THROW_EXCEPTION(CommonException,
+ BadRegularExpression)
}
// Store in list of regular expressions
- /**** LOAD ****/ mRegex.push_back(pregex);
- // Store in list of regular expression string for Serialize
- /**** LOAD ****/ mRegexStr.push_back(strItem);
+ mRegex.push_back(pregex);
+
+ // Store in list of regular expression strings
+ // for Serialize
+ mRegexStr.push_back(strItem);
}
catch(...)
{
@@ -311,7 +315,7 @@
//
//
int64_t aMagicMarker = 0;
- rArchive.Get(aMagicMarker);
+ rArchive.Read(aMagicMarker);
if (aMagicMarker == ARCHIVE_MAGIC_VALUE_NOOP)
{
@@ -319,9 +323,11 @@
}
else if (aMagicMarker == ARCHIVE_MAGIC_VALUE_RECURSE)
{
- /**** LOAD ****/ mpAlwaysInclude = new ExcludeList;
+ mpAlwaysInclude = new ExcludeList;
if (!mpAlwaysInclude)
+ {
throw std::bad_alloc();
+ }
mpAlwaysInclude->Deserialize(rArchive);
}
@@ -347,22 +353,30 @@
//
//
int64_t iCount = mDefinite.size();
- rArchive.Add(iCount);
+ rArchive.Write(iCount);
- for (std::set<std::string>::const_iterator i = mDefinite.begin(); i != mDefinite.end(); i++)
- rArchive.Add(*i);
+ for (std::set<std::string>::const_iterator i = mDefinite.begin();
+ i != mDefinite.end(); i++)
+ {
+ rArchive.Write(*i);
+ }
//
//
//
#ifndef PLATFORM_REGEX_NOT_SUPPORTED
- ASSERT(mRegex.size() == mRegexStr.size()); // don't even try to save compiled regular expressions - use string copies
+ // don't even try to save compiled regular expressions,
+ // use string copies instead.
+ ASSERT(mRegex.size() == mRegexStr.size());
iCount = mRegexStr.size();
- rArchive.Add(iCount);
+ rArchive.Write(iCount);
- for (std::vector<std::string>::const_iterator i = mRegexStr.begin(); i != mRegexStr.end(); i++)
- rArchive.Add(*i);
+ for (std::vector<std::string>::const_iterator i = mRegexStr.begin();
+ i != mRegexStr.end(); i++)
+ {
+ rArchive.Write(*i);
+ }
#endif // PLATFORM_REGEX_NOT_SUPPORTED
//
@@ -371,12 +385,12 @@
if (!mpAlwaysInclude)
{
int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_NOOP;
- rArchive.Add(aMagicMarker);
+ rArchive.Write(aMagicMarker);
}
else
{
int64_t aMagicMarker = ARCHIVE_MAGIC_VALUE_RECURSE; // be explicit about whether recursion follows
- rArchive.Add(aMagicMarker);
+ rArchive.Write(aMagicMarker);
mpAlwaysInclude->Serialize(rArchive);
}