[Box Backup-commit] COMMIT r3377 - in box/trunk: bin/bbackupd bin/bbackupquery lib/backupclient lib/backupstore lib/common lib/intercept lib/raidfile lib/server test/backupstore test/basicserver test/bbackupd

subversion at boxbackup.org subversion at boxbackup.org
Thu Sep 4 02:36:09 BST 2014


Author: chris
Date: 2014-09-04 02:36:08 +0100 (Thu, 04 Sep 2014)
New Revision: 3377

Modified:
   box/trunk/bin/bbackupd/BackupClientContext.cpp
   box/trunk/bin/bbackupd/BackupClientContext.h
   box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp
   box/trunk/bin/bbackupd/BackupDaemon.cpp
   box/trunk/bin/bbackupd/BackupDaemon.h
   box/trunk/bin/bbackupd/bbackupd.cpp
   box/trunk/bin/bbackupquery/BackupQueries.cpp
   box/trunk/lib/backupclient/BackupClientRestore.cpp
   box/trunk/lib/backupstore/BackupProtocol.h
   box/trunk/lib/backupstore/BackupStoreContext.cpp
   box/trunk/lib/backupstore/BackupStoreDirectory.cpp
   box/trunk/lib/backupstore/BackupStoreFileDiff.cpp
   box/trunk/lib/backupstore/BackupStoreFileEncodeStream.cpp
   box/trunk/lib/common/BoxTime.h
   box/trunk/lib/common/DebugMemLeakFinder.cpp
   box/trunk/lib/common/FileStream.cpp
   box/trunk/lib/common/IOStream.h
   box/trunk/lib/common/ReadLoggingStream.h
   box/trunk/lib/common/Test.cpp
   box/trunk/lib/common/Test.h
   box/trunk/lib/common/Timer.cpp
   box/trunk/lib/intercept/intercept.cpp
   box/trunk/lib/raidfile/RaidFileUtil.cpp
   box/trunk/lib/server/ServerTLS.h
   box/trunk/lib/server/SocketStream.cpp
   box/trunk/lib/server/SocketStreamTLS.cpp
   box/trunk/lib/server/makeprotocol.pl.in
   box/trunk/test/backupstore/testbackupstore.cpp
   box/trunk/test/basicserver/TestCommands.cpp
   box/trunk/test/bbackupd/testbbackupd.cpp
Log:
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.

Modified: box/trunk/bin/bbackupd/BackupClientContext.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupClientContext.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/bin/bbackupd/BackupClientContext.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -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 @@
 		if (mExtendedLogToFile)
 		{
 			ASSERT(mpExtendedLogFileHandle == NULL);
-			
+
 			mpExtendedLogFileHandle = fopen(
 				mExtendedLogFile.c_str(), "a+");
 
@@ -198,7 +198,7 @@
 				{
 					// IGNORE
 				}
-				
+
 				// Then throw an exception about this
 				THROW_EXCEPTION_MESSAGE(BackupStoreException,
 					ClientMarkerNotAsExpected,

Modified: box/trunk/bin/bbackupd/BackupClientContext.h
===================================================================
--- box/trunk/bin/bbackupd/BackupClientContext.h	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/bin/bbackupd/BackupClientContext.h	2014-09-04 01:36:08 UTC (rev 3377)
@@ -42,11 +42,11 @@
 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 @@
 public:
 
 	BackupProtocolClient &GetConnection();
-	
 	void CloseAnyOpenConnection();
-	
 	int GetTimeout() const;
-	
 	BackupClientDeleteList &GetDeleteList();
 	void PerformDeletions();
 
@@ -74,7 +71,7 @@
 
 	void SetClientStoreMarker(int64_t ClientStoreMarker) {mClientStoreMarker = ClientStoreMarker;}
 	int64_t GetClientStoreMarker() const {return mClientStoreMarker;}
-	
+
 	bool StorageLimitExceeded() {return mStorageLimitExceeded;}
 	void SetStorageLimitExceeded() {mStorageLimitExceeded = true;}
 

Modified: box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -652,14 +652,16 @@
 	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 @@
 				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 @@
 		// 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,16 +989,16 @@
 				}
 			}
 
-			// 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;
@@ -1003,16 +1005,16 @@
 				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 @@
 			// 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 @@
 				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 @@
 			{
 				// 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 @@
 					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 @@
 	// 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 @@
 					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 @@
 
 		// 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);
 

Modified: box/trunk/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupDaemon.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/bin/bbackupd/BackupDaemon.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -870,8 +870,8 @@
 	// just connect, as this may be unnecessary)
 	BackupClientContext clientContext
 	(
-		*mpLocationResolver, 
-		mTlsContext, 
+		*mpLocationResolver,
+		mTlsContext,
 		conf.GetKeyValue("StoreHostname"),
 		conf.GetKeyValueInt("StorePort"),
 		conf.GetKeyValueUint32("AccountNumber"),
@@ -929,8 +929,7 @@
 	// 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?
@@ -937,11 +936,11 @@
 	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 @@
 	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 @@
 	
 	// 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 @@
 #ifdef ENABLE_VSS
 	CreateVssBackupComponents();
 #endif
-					
+
 	// Go through the records, syncing them
 	for(Locations::const_iterator 
 		i(mLocations.begin()); 
@@ -1055,7 +1053,7 @@
 		// 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 @@
 	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 @@
 	// 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 @@
 
 	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 @@
 		waitInSeconds = -1;
 
 		BOX_NOTICE("SyncAllowScript requested a backup now "
-			<< "(" << script << ")");
+			"(" << script << ")");
 	}
 	else
 	{
@@ -1832,7 +1831,7 @@
 			throw;
 		}
 
-		BOX_NOTICE("SyncAllowScript requested a delay of " << 
+		BOX_NOTICE("SyncAllowScript requested a delay of " <<
 			waitInSeconds << " seconds (" << script << ")");
 	}
 
@@ -2546,7 +2545,7 @@
 						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

Modified: box/trunk/bin/bbackupd/BackupDaemon.h
===================================================================
--- box/trunk/bin/bbackupd/BackupDaemon.h	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/bin/bbackupd/BackupDaemon.h	2014-09-04 01:36:08 UTC (rev 3377)
@@ -237,7 +237,7 @@
 	void SetSysadminNotifier (SysadminNotifier*  p) { mpSysadminNotifier = p; }
 	virtual bool RunBackgroundTask(State state, uint64_t progress,
 		uint64_t maximum);
-		
+
 private:
 	ProgressNotifier* mpProgressNotifier;
 	LocationResolver* mpLocationResolver;
@@ -244,14 +244,14 @@
 	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 @@
 	}
 	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 @@
 		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 @@
 	{
 		if (mLogAllFileAccess)
 		{
-			BOX_NOTICE("Deleted directory: " << rRemotePath << 
+			BOX_NOTICE("Deleted directory: " << rRemotePath <<
 				" (ID " << BOX_FORMAT_OBJECTID(ObjectID) <<
 				")");
 		}
@@ -457,7 +457,7 @@
 	{
 		if (mLogAllFileAccess)
 		{
-			BOX_NOTICE("Deleted file: " << rRemotePath << 
+			BOX_NOTICE("Deleted file: " << rRemotePath <<
 				" (ID " << BOX_FORMAT_OBJECTID(ObjectID) <<
 				")");
 		}
@@ -465,7 +465,7 @@
 	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");
 	}
@@ -472,12 +472,12 @@
 	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");
 	}
 

Modified: box/trunk/bin/bbackupd/bbackupd.cpp
===================================================================
--- box/trunk/bin/bbackupd/bbackupd.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/bin/bbackupd/bbackupd.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -45,10 +45,12 @@
 
 #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

Modified: box/trunk/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/trunk/bin/bbackupquery/BackupQueries.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/bin/bbackupquery/BackupQueries.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -291,8 +291,8 @@
 #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)

Modified: box/trunk/lib/backupclient/BackupClientRestore.cpp
===================================================================
--- box/trunk/lib/backupclient/BackupClientRestore.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/backupclient/BackupClientRestore.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -224,7 +224,7 @@
 			DIRECTORY_SEPARATOR_ASCHAR + 
 			rLevel.mNextLevelLocalName);
 		BackupClientRestoreDir(rConnection, rLevel.mNextLevelID,
-			rRemoteDirectoryName + '/' + 
+			rRemoteDirectoryName + '/' +
 			rLevel.mNextLevelLocalName, localDirname,
 			Params, *rLevel.mpNextLevel);
 		
@@ -232,7 +232,7 @@
 		rLevel.mRestoredObjects.insert(rLevel.mNextLevelID);
 
 		// Remove the level for the recursed directory
-		rLevel.RemoveLevel();		
+		rLevel.RemoveLevel();
 	}
 	
 	// Create the local directory, if not already done.
@@ -299,7 +299,7 @@
 	}
 
 	std::string parentDirectoryName(rLocalDirectoryName);
-	if(parentDirectoryName[parentDirectoryName.size() - 1] == 
+	if(parentDirectoryName[parentDirectoryName.size() - 1] ==
 		DIRECTORY_SEPARATOR_ASCHAR)
 	{
 		parentDirectoryName.resize(parentDirectoryName.size() - 1);
@@ -309,7 +309,7 @@
 
 	if(lastSlash == std::string::npos)
 	{
-		// might be a forward slash separator, 
+		// might be a forward slash separator,
 		// especially in the unit tests!
 		lastSlash = parentDirectoryName.rfind('/');
 	}
@@ -889,7 +889,7 @@
 	}
 	
 	// Restore the directory
-	int result = BackupClientRestoreDir(rConnection, DirectoryID, 
+	int result = BackupClientRestoreDir(rConnection, DirectoryID,
 		RemoteDirectoryName, LocalDirectoryName, params,
 		params.mResumeInfo);
 	if (result != Restore_Complete)

Modified: box/trunk/lib/backupstore/BackupProtocol.h
===================================================================
--- box/trunk/lib/backupstore/BackupProtocol.h	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/backupstore/BackupProtocol.h	2014-09-04 01:36:08 UTC (rev 3377)
@@ -31,7 +31,7 @@
 
 public:
 	BackupProtocolLocal2(int32_t AccountNumber,
-		const std::string& ConnectionDetails, 
+		const std::string& ConnectionDetails,
 		const std::string& AccountRootDir, int DiscSetNumber,
 		bool ReadOnly)
 	// This is rather ugly: the BackupProtocolLocal constructor must not

Modified: box/trunk/lib/backupstore/BackupStoreContext.cpp
===================================================================
--- box/trunk/lib/backupstore/BackupStoreContext.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/backupstore/BackupStoreContext.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -350,12 +350,9 @@
 	std::auto_ptr<RaidFileRead> objectFile(RaidFileRead::Open(mStoreDiscSet, filename, &revID));
 	ASSERT(revID != 0);
 	
-	// New directory object
-	std::auto_ptr<BackupStoreDirectory> dir(new BackupStoreDirectory);
-	
 	// Read it from the stream, then set it's revision ID
 	BufferedStream buf(*objectFile);
-	dir->ReadFromStream(buf, IOStream::TimeOutInfinite);
+	std::auto_ptr<BackupStoreDirectory> dir(new BackupStoreDirectory(buf));
 	dir->SetRevisionID(revID);
 			
 	// Make sure the size of the directory is available for writing the dir back

Modified: box/trunk/lib/backupstore/BackupStoreDirectory.cpp
===================================================================
--- box/trunk/lib/backupstore/BackupStoreDirectory.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/backupstore/BackupStoreDirectory.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -480,7 +480,8 @@
 {
 	// Grab the raw bytes from the stream which compose the header
 	en_StreamFormat entry;
-	if(!rStream.ReadFullBuffer(&entry, sizeof(entry), 0 /* not interested in bytes read if this fails */, Timeout))
+	if(!rStream.ReadFullBuffer(&entry, sizeof(entry),
+		0 /* not interested in bytes read if this fails */, Timeout))
 	{
 		THROW_EXCEPTION(BackupStoreException, CouldntReadEntireStructureFromStream)
 	}

Modified: box/trunk/lib/backupstore/BackupStoreFileDiff.cpp
===================================================================
--- box/trunk/lib/backupstore/BackupStoreFileDiff.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/backupstore/BackupStoreFileDiff.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -114,12 +114,11 @@
 // Function
 //		Name:    BackupStoreFile::EncodeFileDiff(const char *, int64_t, const BackupStoreFilename &, int64_t, IOStream &, int64_t *)
 //		Purpose: Similar to EncodeFile, but takes the object ID of the file it's
-//				 diffing from, and the index of the blocks in a stream. It'll then
-//				 calculate which blocks can be reused from that old file.
-//				 The timeout is the timeout value for reading the diff block index.
-//				 If pIsCompletelyDifferent != 0, it will be set to true if the
-//				 the two files are completely different (do not share any block), false otherwise.
-//				 
+//			 diffing from, and the index of the blocks in a stream. It'll then
+//			 calculate which blocks can be reused from that old file.
+//			 The timeout is the timeout value for reading the diff block index.
+//			 If pIsCompletelyDifferent != 0, it will be set to true if the
+//			 the two files are completely different (do not share any block), false otherwise.
 //		Created: 12/1/04
 //
 // --------------------------------------------------------------------------
@@ -126,8 +125,8 @@
 std::auto_ptr<BackupStoreFileEncodeStream> BackupStoreFile::EncodeFileDiff
 (
 	const std::string& Filename, int64_t ContainerID,
-	const BackupStoreFilename &rStoreFilename, int64_t DiffFromObjectID, 
-	IOStream &rDiffFromBlockIndex, int Timeout, DiffTimer *pDiffTimer, 
+	const BackupStoreFilename &rStoreFilename, int64_t DiffFromObjectID,
+	IOStream &rDiffFromBlockIndex, int Timeout, DiffTimer *pDiffTimer,
 	int64_t *pModificationTime, bool *pIsCompletelyDifferent,
 	BackgroundTask* pBackgroundTask)
 {
@@ -528,7 +527,7 @@
 		
 		// Search for each block size in turn
 		// NOTE: Do the smallest size first, so that the scheme for adding
-		// entries in the found list works as expected and replaces smallers block
+		// entries in the found list works as expected and replaces smaller blocks
 		// with larger blocks when it finds matches at the same offset in the file.
 		for(int s = BACKUP_FILE_DIFF_MAX_BLOCK_SIZES - 1; s >= 0; --s)
 		{
@@ -670,6 +669,7 @@
 						}
 						else
 						{
+							// Too many to log
 							// BOX_TRACE("False alarm match of " << Sizes[s] << " bytes with hash " << hash << " at offset " << fileOffset);
 						}
 

Modified: box/trunk/lib/backupstore/BackupStoreFileEncodeStream.cpp
===================================================================
--- box/trunk/lib/backupstore/BackupStoreFileEncodeStream.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/backupstore/BackupStoreFileEncodeStream.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -709,11 +709,12 @@
 //		Created: 15/1/04
 //
 // --------------------------------------------------------------------------
-BackupStoreFileEncodeStream::Recipe::Recipe(BackupStoreFileCreation::BlocksAvailableEntry *pBlockIndex,
-		int64_t NumBlocksInIndex, int64_t OtherFileID)
-	: mpBlockIndex(pBlockIndex),
-	  mNumBlocksInIndex(NumBlocksInIndex),
-	  mOtherFileID(OtherFileID)
+BackupStoreFileEncodeStream::Recipe::Recipe(
+	BackupStoreFileCreation::BlocksAvailableEntry *pBlockIndex,
+	int64_t NumBlocksInIndex, int64_t OtherFileID)
+: mpBlockIndex(pBlockIndex),
+  mNumBlocksInIndex(NumBlocksInIndex),
+  mOtherFileID(OtherFileID)
 {
 	ASSERT((mpBlockIndex == 0) || (NumBlocksInIndex != 0))
 }

Modified: box/trunk/lib/common/BoxTime.h
===================================================================
--- box/trunk/lib/common/BoxTime.h	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/common/BoxTime.h	2014-09-04 01:36:08 UTC (rev 3377)
@@ -10,8 +10,8 @@
 #ifndef BOXTIME__H
 #define BOXTIME__H
 
-// Time is presented as an unsigned 64 bit integer, in microseconds
-typedef int64_t	box_time_t;
+// Time is presented as a signed 64 bit integer, in microseconds
+typedef int64_t box_time_t;
 
 #define NANO_SEC_IN_SEC		(1000000000LL)
 #define NANO_SEC_IN_USEC 	(1000)

Modified: box/trunk/lib/common/DebugMemLeakFinder.cpp
===================================================================
--- box/trunk/lib/common/DebugMemLeakFinder.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/common/DebugMemLeakFinder.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -599,9 +599,6 @@
 	}
 }
 
-
-
-
 void add_object_block(void *block, size_t size, const char *file, int line, bool array)
 {
 	InternalAllocGuard guard;

Modified: box/trunk/lib/common/FileStream.cpp
===================================================================
--- box/trunk/lib/common/FileStream.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/common/FileStream.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -248,7 +248,7 @@
 // --------------------------------------------------------------------------
 void FileStream::Write(const void *pBuffer, int NBytes, int Timeout)
 {
-	if(mOSFileHandle == INVALID_FILE) 
+	if(mOSFileHandle == INVALID_FILE)
 	{
 		THROW_EXCEPTION(CommonException, FileClosed)
 	}

Modified: box/trunk/lib/common/IOStream.h
===================================================================
--- box/trunk/lib/common/IOStream.h	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/common/IOStream.h	2014-09-04 01:36:08 UTC (rev 3377)
@@ -54,7 +54,7 @@
 	virtual pos_type GetPosition() const;
 	virtual void Seek(pos_type Offset, int SeekType);
 	virtual void Close();
-	
+
 	// Has all data that can be read been read?
 	virtual bool StreamDataLeft() = 0;
 	// Has the stream been closed (writing not possible)
@@ -69,7 +69,4 @@
 	virtual std::string ToString() const;
 };
 
-
 #endif // IOSTREAM__H
-
-

Modified: box/trunk/lib/common/ReadLoggingStream.h
===================================================================
--- box/trunk/lib/common/ReadLoggingStream.h	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/common/ReadLoggingStream.h	2014-09-04 01:36:08 UTC (rev 3377)
@@ -49,7 +49,7 @@
 	virtual bool StreamClosed();
 
 private:
-	ReadLoggingStream(const ReadLoggingStream &rToCopy) 
+	ReadLoggingStream(const ReadLoggingStream &rToCopy)
 	: mrSource(rToCopy.mrSource), mrLogger(rToCopy.mrLogger)
 	{ /* do not call */ }
 };

Modified: box/trunk/lib/common/Test.cpp
===================================================================
--- box/trunk/lib/common/Test.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/common/Test.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -136,7 +136,7 @@
 	if(!TestFileNotEmpty(pidFile))
 	{
 		TEST_FAIL_WITH_MESSAGE("Server didn't save PID file "
-			"(perhaps one was already running?)");	
+			"(perhaps one was already running?)");
 		return -1;
 	}
 	
@@ -145,7 +145,7 @@
 	FILE *f = fopen(pidFile, "r");
 	if(f == NULL || fscanf(f, "%d", &pid) != 1)
 	{
-		TEST_FAIL_WITH_MESSAGE("Couldn't read PID file");	
+		TEST_FAIL_WITH_MESSAGE("Couldn't read PID file");
 		return -1;
 	}
 	fclose(f);
@@ -155,7 +155,7 @@
 
 int LaunchServer(const std::string& rCommandLine, const char *pidFile)
 {
-	::fprintf(stdout, "Starting server: %s\n", rCommandLine.c_str());
+	BOX_INFO("Starting server: " << rCommandLine);
 
 #ifdef WIN32
 
@@ -189,14 +189,10 @@
 
 	free(tempCmd);
 
-	if (result == 0)
-	{
-		DWORD err = GetLastError();
-		printf("Launch failed: %s: error %d\n", rCommandLine.c_str(),
-			(int)err);
-		TEST_FAIL_WITH_MESSAGE("Couldn't start server");
+	TEST_THAT_OR(result != 0,
+		BOX_LOG_WIN_ERROR("Launch failed: " << rCommandLine);
 		return -1;
-	}
+		);
 
 	CloseHandle(procInfo.hProcess);
 	CloseHandle(procInfo.hThread);
@@ -205,11 +201,10 @@
 
 #else // !WIN32
 
-	if(RunCommand(rCommandLine) != 0)
-	{
-		TEST_FAIL_WITH_MESSAGE("Couldn't start server");
+	TEST_THAT_OR(RunCommand(rCommandLine) == 0,
+		TEST_FAIL_WITH_MESSAGE("Failed to start server: " << rCommandLine);
 		return -1;
-	}
+		)
 
 	return WaitForServerStartup(pidFile, 0);
 
@@ -234,7 +229,7 @@
 
 	for (int i = 0; i < 15; i++)
 	{
-		if (TestFileNotEmpty(pidFile))	
+		if (TestFileNotEmpty(pidFile))
 		{
 			break;
 		}
@@ -252,13 +247,13 @@
 
 	if (pidIfKnown && !ServerIsAlive(pidIfKnown))
 	{
-		TEST_FAIL_WITH_MESSAGE("Server died!");	
+		TEST_FAIL_WITH_MESSAGE("Server died!");
 		return -1;
 	}
 
 	if (!TestFileNotEmpty(pidFile))
 	{
-		TEST_FAIL_WITH_MESSAGE("Server didn't save PID file");	
+		TEST_FAIL_WITH_MESSAGE("Server didn't save PID file");
 		return -1;
 	}
 
@@ -381,7 +376,7 @@
 // Wait a given number of seconds for something to complete
 void wait_for_operation(int seconds, const char* message)
 {
-	BOX_TRACE("Waiting " << seconds << " seconds for " << message);
+	BOX_INFO("Waiting " << seconds << " seconds for " << message);
 
 	for(int l = 0; l < seconds; ++l)
 	{
@@ -395,4 +390,3 @@
 {
 	ShortSleep(SecondsToBoxTime(seconds), true);
 }
-

Modified: box/trunk/lib/common/Test.h
===================================================================
--- box/trunk/lib/common/Test.h	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/common/Test.h	2014-09-04 01:36:08 UTC (rev 3377)
@@ -157,6 +157,9 @@
 		printf("Test failed on <%s>\n", _line_str.c_str()); \
 	}
 
+#define TEST_STARTSWITH(expected, actual) \
+	TEST_EQUAL_LINE(expected, actual.substr(0, std::string(expected).size()), actual);
+
 bool TestFileExists(const char *Filename);
 bool TestDirExists(const char *Filename);
 

Modified: box/trunk/lib/common/Timer.cpp
===================================================================
--- box/trunk/lib/common/Timer.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/common/Timer.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -155,7 +155,7 @@
 			}
 		}
 	}
-		
+
 	Reschedule();
 }
 

Modified: box/trunk/lib/intercept/intercept.cpp
===================================================================
--- box/trunk/lib/intercept/intercept.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/intercept/intercept.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -132,7 +132,7 @@
 	intercept_delay_ms = 0;
 }
 
-void intercept_setup_delay(const char *filename, unsigned int delay_after, 
+void intercept_setup_delay(const char *filename, unsigned int delay_after,
 	int delay_ms, int syscall_to_delay, int num_delays)
 {
 	BOX_TRACE("Setup for delay: " << filename <<

Modified: box/trunk/lib/raidfile/RaidFileUtil.cpp
===================================================================
--- box/trunk/lib/raidfile/RaidFileUtil.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/raidfile/RaidFileUtil.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -14,7 +14,7 @@
 
 #include "RaidFileUtil.h"
 #include "FileModificationTime.h"
-#include "RaidFileRead.h"	// for type definition
+#include "RaidFileRead.h" // for type definition
 
 #include "MemLeakFindOn.h"
 

Modified: box/trunk/lib/server/ServerTLS.h
===================================================================
--- box/trunk/lib/server/ServerTLS.h	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/server/ServerTLS.h	2014-09-04 01:36:08 UTC (rev 3377)
@@ -52,7 +52,8 @@
 		std::string certFile(serverconf.GetKeyValue("CertificateFile"));
 		std::string keyFile(serverconf.GetKeyValue("PrivateKeyFile"));
 		std::string caFile(serverconf.GetKeyValue("TrustedCAsFile"));
-		mContext.Initialise(true /* as server */, certFile.c_str(), keyFile.c_str(), caFile.c_str());
+		mContext.Initialise(true /* as server */, certFile.c_str(),
+			keyFile.c_str(), caFile.c_str());
 	
 		// Then do normal stream server stuff
 		ServerStream<SocketStreamTLS, Port, ListenBacklog,

Modified: box/trunk/lib/server/SocketStream.cpp
===================================================================
--- box/trunk/lib/server/SocketStream.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/server/SocketStream.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -323,15 +323,15 @@
 // --------------------------------------------------------------------------
 void SocketStream::Write(const void *pBuffer, int NBytes, int Timeout)
 {
-	if(mSocketHandle == INVALID_SOCKET_VALUE) 
+	if(mSocketHandle == INVALID_SOCKET_VALUE)
 	{
 		THROW_EXCEPTION(ServerException, BadSocketHandle)
 	}
-	
+
 	// Buffer in byte sized type.
 	ASSERT(sizeof(char) == 1);
 	const char *buffer = (char *)pBuffer;
-	
+
 	// Bytes left to send
 	int bytesLeft = NBytes;
 	box_time_t start = GetCurrentBoxTime();
@@ -348,11 +348,10 @@
 		{
 			// Error.
 			mWriteClosed = true;	// assume can't write again
-			BOX_LOG_SYS_ERROR("Failed to write to socket");
-			THROW_EXCEPTION(ConnectionException,
-				SocketWriteError);
+			THROW_SYS_ERROR("Failed to write to socket",
+				ConnectionException, SocketWriteError);
 		}
-		
+
 		// Knock off bytes sent
 		bytesLeft -= sent;
 		// Move buffer pointer
@@ -359,11 +358,11 @@
 		buffer += sent;
 
 		mBytesWritten += sent;
-		
+
 		// Need to wait until it can send again?
 		if(bytesLeft > 0)
 		{
-			BOX_TRACE("Waiting to send data on socket " << 
+			BOX_TRACE("Waiting to send data on socket " <<
 				mSocketHandle << " (" << bytesLeft <<
 				" of " << NBytes << " bytes left)");
 
@@ -388,7 +387,7 @@
 // --------------------------------------------------------------------------
 void SocketStream::Close()
 {
-	if(mSocketHandle == INVALID_SOCKET_VALUE) 
+	if(mSocketHandle == INVALID_SOCKET_VALUE)
 	{
 		THROW_EXCEPTION(ServerException, BadSocketHandle)
 	}
@@ -419,14 +418,14 @@
 	{
 		THROW_EXCEPTION(ServerException, BadSocketHandle)
 	}
-	
+
 	// Do anything?
 	if(!Read && !Write) return;
-	
+
 	int how = SHUT_RDWR;
 	if(Read && !Write) how = SHUT_RD;
 	if(!Read && Write) how = SHUT_WR;
-	
+
 	// Shut it down!
 	if(::shutdown(mSocketHandle, how) == -1)
 	{

Modified: box/trunk/lib/server/SocketStreamTLS.cpp
===================================================================
--- box/trunk/lib/server/SocketStreamTLS.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/server/SocketStreamTLS.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -132,7 +132,7 @@
 
 	tOSSocketHandle socket = GetSocketHandle();
 	BIO_set_fd(mpBIO, socket, BIO_NOCLOSE);
-	
+
 	// Then the SSL object
 	mpSSL = ::SSL_new(rContext.GetRawContext());
 	if(mpSSL == 0)
@@ -155,7 +155,7 @@
 		THROW_EXCEPTION(ServerException, SocketSetNonBlockingFailed)
 	}
 #endif
-	
+
 	// FIXME: This is less portable than the above. However, it MAY be needed
 	// for cygwin, which has/had bugs with fcntl
 	//
@@ -223,8 +223,9 @@
 //
 // Function
 //		Name:    WaitWhenRetryRequired(int, int)
-//		Purpose: Waits until the condition required by the TLS layer is met.
-//				 Returns true if the condition is met, false if timed out.
+//		Purpose: Waits until the condition required by the TLS layer
+//		         is met. Returns true if the condition is met, false
+//		         if timed out.
 //		Created: 2003/08/15
 //
 // --------------------------------------------------------------------------
@@ -320,13 +321,13 @@
 void SocketStreamTLS::Write(const void *pBuffer, int NBytes, int Timeout)
 {
 	if(!mpSSL) {THROW_EXCEPTION(ServerException, TLSNoSSLObject)}
-	
+
 	// Make sure zero byte writes work as expected
 	if(NBytes == 0)
 	{
 		return;
 	}
-	
+
 	// from man SSL_write
 	//
 	// SSL_write() will only return with success, when the
@@ -333,7 +334,7 @@
 	// complete contents of buf of length num has been written.
 	//
 	// So no worries about partial writes and moving the buffer around
-	
+
 	while(true)
 	{
 		// try the write

Modified: box/trunk/lib/server/makeprotocol.pl.in
===================================================================
--- box/trunk/lib/server/makeprotocol.pl.in	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/lib/server/makeprotocol.pl.in	2014-09-04 01:36:08 UTC (rev 3377)
@@ -811,10 +811,12 @@
 	{
 		push @base_classes, $replyable_base_class;
 	}
+
 	if (not $writing_server)
 	{
 		push @base_classes, $callable_base_class;
 	}
+
 	if (not $writing_local)
 	{
 		push @base_classes, $custom_protocol_subclass;

Modified: box/trunk/test/backupstore/testbackupstore.cpp
===================================================================
--- box/trunk/test/backupstore/testbackupstore.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/test/backupstore/testbackupstore.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -409,8 +409,7 @@
 		}
 	}
 
-	tearDown();
-	return true;
+	return tearDown();
 }
 
 void write_test_file(int t)
@@ -417,7 +416,7 @@
 {
 	std::string filename("testfiles/test");
 	filename += uploads[t].fnextra;
-	printf("%s\n", filename.c_str());
+	BOX_TRACE("Writing " << filename);
 	
 	FileStream write(filename.c_str(), O_WRONLY | O_CREAT);
 	
@@ -457,9 +456,9 @@
 	TEST_THAT(unlink("testfiles/test_download") == 0);
 }
 
-void test_everything_deleted(BackupProtocolCallable &protocol, int64_t DirID)
+void assert_everything_deleted(BackupProtocolCallable &protocol, int64_t DirID)
 {
-	printf("Test for del: %llx\n", (unsigned long long)DirID);
+	BOX_TRACE("Test for del: " << BOX_FORMAT_OBJECTID(DirID));
 	
 	// Command
 	std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory(
@@ -478,7 +477,7 @@
 		{
 			dirs++;
 			// Recurse
-			test_everything_deleted(protocol, en->GetObjectID());
+			assert_everything_deleted(protocol, en->GetObjectID());
 		}
 		else
 		{
@@ -486,7 +485,7 @@
 		}
 
 		// Check it's deleted
-		TEST_THAT(en->GetFlags() & BackupProtocolListDirectory::Flags_Deleted);
+		TEST_THAT(en->IsDeleted());
 	}
 	
 	// Check there were the right number of files and directories
@@ -571,10 +570,10 @@
 {
 	// Command
 	std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory(
-			BackupProtocolListDirectory::RootDirectory,
+			BACKUPSTORE_ROOT_DIRECTORY_ID,
 			BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
 			BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
-	TEST_THAT(dirreply->GetObjectID() == BackupProtocolListDirectory::RootDirectory);
+	TEST_THAT(dirreply->GetObjectID() == BACKUPSTORE_ROOT_DIRECTORY_ID);
 	// Stream
 	BackupStoreDirectory dir(protocol.ReceiveStream(), SHORT_TIMEOUT);
 	TEST_EQUAL(UPLOAD_NUM, dir.GetNumberOfEntries());
@@ -799,7 +798,9 @@
 	BackupStoreFilenameClear store1name("file1");
 	{
 		FileStream out("testfiles/file1_upload1", O_WRONLY | O_CREAT);
-		std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/file1", BackupProtocolListDirectory::RootDirectory, store1name));
+		std::auto_ptr<IOStream> encoded(
+			BackupStoreFile::EncodeFile("testfiles/file1",
+				BACKUPSTORE_ROOT_DIRECTORY_ID, store1name));
 		encoded->CopyStreamTo(out);
 	}
 
@@ -816,7 +817,7 @@
 	{
 		std::auto_ptr<IOStream> upload(new FileStream("testfiles/file1_upload1"));
 		std::auto_ptr<BackupProtocolSuccess> stored(protocol.QueryStoreFile(
-			BackupProtocolListDirectory::RootDirectory,
+			BACKUPSTORE_ROOT_DIRECTORY_ID,
 			0x123456789abcdefLL,		/* modification time */
 			0x7362383249872dfLL,		/* attr hash */
 			0,							/* diff from ID */
@@ -833,8 +834,8 @@
 	// And retrieve it
 	{
 		// Retrieve as object
-		std::auto_ptr<BackupProtocolSuccess> getfile(protocol.QueryGetObject(store1objid));
-		TEST_THAT(getfile->GetObjectID() == store1objid);
+		COMMAND(QueryGetObject(store1objid), store1objid);
+
 		// BLOCK
 		{
 			// Get stream
@@ -849,8 +850,8 @@
 		}
 
 		// Retrieve as file
-		std::auto_ptr<BackupProtocolSuccess> getobj(protocol.QueryGetFile(BackupProtocolListDirectory::RootDirectory, store1objid));
-		TEST_THAT(getobj->GetObjectID() == store1objid);
+		COMMAND(QueryGetFile(BACKUPSTORE_ROOT_DIRECTORY_ID, store1objid), store1objid);
+
 		// BLOCK
 		{
 			UNLINK_IF_EXISTS("testfiles/file1_upload_retrieved_str");
@@ -887,7 +888,7 @@
 
 		// and again, by name
 		{
-			std::auto_ptr<BackupProtocolSuccess> getblockindex(protocol.QueryGetBlockIndexByName(BackupProtocolListDirectory::RootDirectory, store1name));
+			std::auto_ptr<BackupProtocolSuccess> getblockindex(protocol.QueryGetBlockIndexByName(BACKUPSTORE_ROOT_DIRECTORY_ID, store1name));
 			TEST_THAT(getblockindex->GetObjectID() == store1objid);
 			std::auto_ptr<IOStream> blockIndexStream(protocol.ReceiveStream());
 			// Check against uploaded file
@@ -899,7 +900,7 @@
 	{
 		// Command
 		std::auto_ptr<BackupProtocolSuccess> dirreply(protocol.QueryListDirectory(
-				BackupProtocolListDirectory::RootDirectory,
+				BACKUPSTORE_ROOT_DIRECTORY_ID,
 				BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
 				BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
 		// Stream
@@ -928,7 +929,7 @@
 	// Upload again, as a patch to the original file.
 	int64_t patch1_id = BackupStoreFile::QueryStoreFileDiff(protocol,
 		"testfiles/file1", // LocalFilename
-		BackupProtocolListDirectory::RootDirectory, // DirectoryObjectID
+		BACKUPSTORE_ROOT_DIRECTORY_ID, // DirectoryObjectID
 		store1objid, // DiffFromFileID
 		0x7362383249872dfLL, // AttributesHash
 		store1name // StoreFilename
@@ -958,7 +959,7 @@
 
 	int64_t patch2_id = BackupStoreFile::QueryStoreFileDiff(protocol,
 		"testfiles/file1", // LocalFilename
-		BackupProtocolListDirectory::RootDirectory, // DirectoryObjectID
+		BACKUPSTORE_ROOT_DIRECTORY_ID, // DirectoryObjectID
 		patch1_id, // DiffFromFileID
 		0x7362383249872dfLL, // AttributesHash
 		store1name // StoreFilename
@@ -991,7 +992,7 @@
 	// but used to not adjust the number of old/deleted files properly.
 	int64_t replaced_id = BackupStoreFile::QueryStoreFileDiff(protocol,
 		"testfiles/file1", // LocalFilename
-		BackupProtocolListDirectory::RootDirectory, // DirectoryObjectID
+		BACKUPSTORE_ROOT_DIRECTORY_ID, // DirectoryObjectID
 		0, // DiffFromFileID
 		0x7362383249872dfLL, // AttributesHash
 		store1name // StoreFilename
@@ -1041,7 +1042,7 @@
 
 	// Check that deleting files is accounted for as well
 	protocol.QueryDeleteFile(
-		BackupProtocolListDirectory::RootDirectory, // InDirectory
+		BACKUPSTORE_ROOT_DIRECTORY_ID, // InDirectory
 		store1name); // Filename
 
 	// The old version file is deleted as well!
@@ -1080,8 +1081,10 @@
 
 	// Try using GetFile on a directory
 	{
-		TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolSuccess> getFile(protocol.QueryGetFile(BackupProtocolListDirectory::RootDirectory, BackupProtocolListDirectory::RootDirectory)),
-			ConnectionException, Protocol_UnexpectedReply);
+		int64_t subdirid = create_directory(protocol);
+		TEST_COMMAND_RETURNS_ERROR(protocol,
+			QueryGetFile(BACKUPSTORE_ROOT_DIRECTORY_ID, subdirid),
+			Err_FileDoesNotVerify);
 	}
 
 	// Try retrieving an object that doesn't exist. That used to return
@@ -1093,7 +1096,7 @@
 	protocol.QueryFinished();
 	TEST_THAT(run_housekeeping_and_check_account());
 
-	ExpectedRefCounts.resize(2); // stop test failure in tearDown()
+	ExpectedRefCounts.resize(3); // stop test failure in tearDown()
 	tearDown();
 	return true;
 }
@@ -1108,7 +1111,7 @@
 	std::auto_ptr<BackupProtocolSuccess> dirCreate(protocol.QueryCreateDirectory(
 		parent_dir_id, FAKE_ATTR_MODIFICATION_TIME, dirname, attr));
 
-	int64_t subdirid = dirCreate->GetObjectID(); 
+	int64_t subdirid = dirCreate->GetObjectID();
 	set_refcount(subdirid, 1);
 	return subdirid;
 }
@@ -1152,8 +1155,8 @@
 	std::auto_ptr<BackupProtocolVersion> serverVersion
 		(protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION));
 	TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION);
-	TEST_CHECK_THROWS(protocol.QueryLogin(0x01234567, 0),
-		ConnectionException, Protocol_UnexpectedReply);
+	TEST_COMMAND_RETURNS_ERROR_OR(protocol, QueryLogin(0x01234567, 0),
+		Err_CannotLockStoreForWriting, return false);
 	protocol.QueryFinished();
 	return true;
 }
@@ -1195,7 +1198,7 @@
 		// Command
 		std::auto_ptr<BackupProtocolSuccess> dirreply(
 			apProtocol->QueryListDirectory(
-				BackupProtocolListDirectory::RootDirectory,
+				BACKUPSTORE_ROOT_DIRECTORY_ID,
 				BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
 				BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
 		// Stream
@@ -1208,7 +1211,7 @@
 	// Command
 	std::auto_ptr<BackupProtocolSuccess> dirreply(
 		protocolReadOnly.QueryListDirectory(
-			BackupProtocolListDirectory::RootDirectory,
+			BACKUPSTORE_ROOT_DIRECTORY_ID,
 			BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
 			BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING,
 			false /* no attributes */));
@@ -1217,7 +1220,7 @@
 		protocolReadOnly.GetTimeout());
 	TEST_THAT(dir.GetNumberOfEntries() == 0);			
 
-	// BLOCK
+	// TODO FIXME dedent
 	{
 		TEST_THAT(check_num_files(0, 0, 0, 1));
 
@@ -1234,11 +1237,11 @@
 			filename += uploads[t].fnextra;
 			int64_t modtime = 0;
 
-			std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile(filename.c_str(), BackupProtocolListDirectory::RootDirectory, uploads[t].name, &modtime));
+			std::auto_ptr<IOStream> upload(BackupStoreFile::EncodeFile(filename.c_str(), BACKUPSTORE_ROOT_DIRECTORY_ID, uploads[t].name, &modtime));
 			TEST_THAT(modtime != 0);
 			
 			std::auto_ptr<BackupProtocolSuccess> stored(apProtocol->QueryStoreFile(
-				BackupProtocolListDirectory::RootDirectory,
+				BACKUPSTORE_ROOT_DIRECTORY_ID,
 				modtime,
 				modtime, /* use it for attr hash too */
 				0, /* diff from ID */
@@ -1277,7 +1280,7 @@
 			std::auto_ptr<IOStream> attrnew(
 				new MemBlockStream(attr3, sizeof(attr3)));
 			std::auto_ptr<BackupProtocolSuccess> set(apProtocol->QuerySetReplacementFileAttributes(
-				BackupProtocolListDirectory::RootDirectory,
+				BACKUPSTORE_ROOT_DIRECTORY_ID,
 				32498749832475LL,
 				uploads[UPLOAD_ATTRS_EN].name,
 				attrnew));
@@ -1288,7 +1291,7 @@
 		// Delete one of them (will implicitly delete an old version)
 		{
 			std::auto_ptr<BackupProtocolSuccess> del(apProtocol->QueryDeleteFile(
-				BackupProtocolListDirectory::RootDirectory,
+				BACKUPSTORE_ROOT_DIRECTORY_ID,
 				uploads[UPLOAD_DELETE_EN].name));
 			TEST_THAT(del->GetObjectID() == uploads[UPLOAD_DELETE_EN].allocated_objid);
 			TEST_THAT(check_num_files(UPLOAD_NUM - 4, 3, 2, 1));
@@ -1305,7 +1308,7 @@
 			}
 			// query index and test
 			std::auto_ptr<BackupProtocolSuccess> getblockindex(apProtocol->QueryGetBlockIndexByName(
-				BackupProtocolListDirectory::RootDirectory, uploads[UPLOAD_DELETE_EN].name));
+				BACKUPSTORE_ROOT_DIRECTORY_ID, uploads[UPLOAD_DELETE_EN].name));
 			TEST_THAT(getblockindex->GetObjectID() == uploads[UPLOAD_DELETE_EN].allocated_objid);
 			std::auto_ptr<IOStream> blockIndexStream(apProtocol->ReceiveStream());
 			TEST_THAT(check_block_index("testfiles/downloaddelobj", *blockIndexStream));
@@ -1315,7 +1318,7 @@
 		for(int t = 0; t < UPLOAD_NUM; ++t)
 		{
 			printf("%d\n", t);
-			std::auto_ptr<BackupProtocolSuccess> getFile(apProtocol->QueryGetFile(BackupProtocolListDirectory::RootDirectory, uploads[t].allocated_objid));
+			std::auto_ptr<BackupProtocolSuccess> getFile(apProtocol->QueryGetFile(BACKUPSTORE_ROOT_DIRECTORY_ID, uploads[t].allocated_objid));
 			TEST_THAT(getFile->GetObjectID() == uploads[t].allocated_objid);
 			std::auto_ptr<IOStream> filestream(apProtocol->ReceiveStream());
 			test_test_file(t, *filestream);
@@ -1377,7 +1380,7 @@
 		{
 			// Fetch the block index for this one
 			std::auto_ptr<BackupProtocolSuccess> getblockindex(apProtocol->QueryGetBlockIndexByName(
-				BackupProtocolListDirectory::RootDirectory, uploads[UPLOAD_PATCH_EN].name));
+				BACKUPSTORE_ROOT_DIRECTORY_ID, uploads[UPLOAD_PATCH_EN].name));
 			TEST_THAT(getblockindex->GetObjectID() == uploads[UPLOAD_PATCH_EN].allocated_objid);
 			std::auto_ptr<IOStream> blockIndexStream(apProtocol->ReceiveStream());
 			
@@ -1387,7 +1390,7 @@
 			std::auto_ptr<IOStream> patchstream(
 				BackupStoreFile::EncodeFileDiff(
 					TEST_FILE_FOR_PATCHING ".mod", 
-					BackupProtocolListDirectory::RootDirectory,
+					BACKUPSTORE_ROOT_DIRECTORY_ID,
 					uploads[UPLOAD_PATCH_EN].name, 
 					uploads[UPLOAD_PATCH_EN].allocated_objid, 
 					*blockIndexStream,
@@ -1407,7 +1410,7 @@
 			{
 				std::auto_ptr<IOStream> uploadpatch(new FileStream(TEST_FILE_FOR_PATCHING ".patch"));
 				std::auto_ptr<BackupProtocolSuccess> stored(apProtocol->QueryStoreFile(
-					BackupProtocolListDirectory::RootDirectory,
+					BACKUPSTORE_ROOT_DIRECTORY_ID,
 					modtime,
 					modtime, /* use it for attr hash too */
 					uploads[UPLOAD_PATCH_EN].allocated_objid,		/* diff from ID */
@@ -1421,7 +1424,7 @@
 			set_refcount(patchedID, 1);
 
 			// Then download it to check it's OK
-			std::auto_ptr<BackupProtocolSuccess> getFile(apProtocol->QueryGetFile(BackupProtocolListDirectory::RootDirectory, patchedID));
+			std::auto_ptr<BackupProtocolSuccess> getFile(apProtocol->QueryGetFile(BACKUPSTORE_ROOT_DIRECTORY_ID, patchedID));
 			TEST_THAT(getFile->GetObjectID() == patchedID);
 			std::auto_ptr<IOStream> filestream(apProtocol->ReceiveStream());
 			BackupStoreFile::DecodeFile(*filestream,
@@ -1439,12 +1442,13 @@
 		int64_t subdirfileid = create_file(*apProtocol, subdirid);
 		TEST_THAT(check_num_files(UPLOAD_NUM - 3, 4, 2, 2));
 
-		printf("\n==== Checking upload using read-only connection\n");
+		BOX_TRACE("Checking upload using read-only connection");
 		// Check the directories on the read only connection
 		{
 			// Command
-			std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory(
-					BackupProtocolListDirectory::RootDirectory,
+			std::auto_ptr<BackupProtocolSuccess> dirreply(
+				protocolReadOnly.QueryListDirectory(
+					BACKUPSTORE_ROOT_DIRECTORY_ID,
 					BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
 					BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes! */)); // Stream
 			BackupStoreDirectory dir(protocolReadOnly.ReceiveStream(),
@@ -1468,7 +1472,8 @@
 				}
 				en = t;
 			}
-			// Does it look right?
+
+			// Check that the last entry looks right
 			TEST_THAT(en->GetName() == dirname);
 			TEST_THAT(en->GetFlags() == BackupProtocolListDirectory::Flags_Dir);
 			TEST_THAT(en->GetObjectID() == subdirid);
@@ -1475,9 +1480,11 @@
 			TEST_THAT(en->GetModificationTime() == 0);	// dirs don't have modification times.
 		}
 
+		BOX_TRACE("Checking subdirectory using read-only connection");
 		{
 			// Command
-			std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory(
+			std::auto_ptr<BackupProtocolSuccess> dirreply(
+				protocolReadOnly.QueryListDirectory(
 					subdirid,
 					BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
 					BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, true /* get attributes */));
@@ -1506,9 +1513,8 @@
 			StreamableMemBlock attr(attr1, sizeof(attr1));
 			TEST_THAT(dir.GetAttributes() == attr);
 		}
-		printf("done.\n\n");
 
-		// Check that we don't get attributes if we don't ask for them
+		BOX_TRACE("Checking that we don't get attributes if we don't ask for them");
 		{
 			// Command
 			std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory(
@@ -1556,7 +1562,11 @@
 			TEST_THAT(dir.GetAttributes() == attrtest);
 		}
 		
-		// sleep to ensure that the timestamp on the file will change
+		// Sleep before modifying the root directory, to ensure that
+		// the timestamp on the file it's stored in will change when
+		// we modify it, invalidating the read-only connection's cache
+		// and forcing it to reload the root directory, next time we
+		// ask for its contents.
 		::safe_sleep(1);
 
 		// Test moving a file
@@ -1564,7 +1574,7 @@
 			BackupStoreFilenameClear newName("moved-files");
 		
 			std::auto_ptr<BackupProtocolSuccess> rep(apProtocol->QueryMoveObject(uploads[UPLOAD_FILE_TO_MOVE].allocated_objid,
-				BackupProtocolListDirectory::RootDirectory,
+				BACKUPSTORE_ROOT_DIRECTORY_ID,
 				subdirid, BackupProtocolMoveObject::Flags_MoveAllWithSameName, newName));
 			TEST_THAT(rep->GetObjectID() == uploads[UPLOAD_FILE_TO_MOVE].allocated_objid);
 		}
@@ -1619,10 +1629,11 @@
 					subdirid,
 					BackupProtocolListDirectory::Flags_INCLUDE_EVERYTHING,
 					BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
+
 			// Stream
-			BackupStoreDirectory dir;
-			std::auto_ptr<IOStream> dirstream(protocolReadOnly.ReceiveStream());
-			dir.ReadFromStream(*dirstream, SHORT_TIMEOUT);
+			BackupStoreDirectory dir(protocolReadOnly.ReceiveStream(),
+				SHORT_TIMEOUT);
+
 			// Check entries
 			BackupStoreDirectory::Iterator i(dir);
 			BackupStoreDirectory::Entry *en = 0;
@@ -1658,7 +1669,7 @@
 			BackupStoreFilenameClear file2("file2");
 			std::auto_ptr<IOStream> upload(
 				BackupStoreFile::EncodeFile("testfiles/test2",
-					BackupProtocolListDirectory::RootDirectory, file2));
+					BACKUPSTORE_ROOT_DIRECTORY_ID, file2));
 			std::auto_ptr<BackupProtocolSuccess> stored(apProtocol->QueryStoreFile(
 				subsubdirid,
 				0x123456789abcdefLL,		/* modification time */
@@ -1738,7 +1749,7 @@
 		// Create some nice recursive directories
 		TEST_THAT(check_reference_counts());
 		int64_t dirtodelete = create_test_data_subdirs(*apProtocol,
-			BackupProtocolListDirectory::RootDirectory,
+			BACKUPSTORE_ROOT_DIRECTORY_ID,
 			"test_delete", 6 /* depth */, apRefCount.get());
 		TEST_THAT(check_reference_counts());
 		
@@ -1764,7 +1775,7 @@
 		{
 			// Command
 			std::auto_ptr<BackupProtocolSuccess> dirreply(protocolReadOnly.QueryListDirectory(
-					BackupProtocolListDirectory::RootDirectory,
+					BACKUPSTORE_ROOT_DIRECTORY_ID,
 					BackupProtocolListDirectory::Flags_Dir | BackupProtocolListDirectory::Flags_Deleted,
 					BackupProtocolListDirectory::Flags_EXCLUDE_NOTHING, false /* no attributes */));
 			// Stream
@@ -1785,7 +1796,7 @@
 			}
 			
 			// Then... check everything's deleted
-			test_everything_deleted(protocolReadOnly, dirtodelete);
+			assert_everything_deleted(protocolReadOnly, dirtodelete);
 		}
 
 		// Finish the connections
@@ -1847,7 +1858,9 @@
 	TEST_EQUAL(old_size, get_object_size(protocolReadOnly, subdirid,
 		BACKUPSTORE_ROOT_DIRECTORY_ID));
 
-	// TODO FIXME Sleep to ensure that file timestamp changes (win32?)
+	// Sleep to ensure that the directory file timestamp changes, so that
+	// the read-only connection will discard its cached copy.
+	safe_sleep(1);
 
 	// Start adding files until the size on disk increases. This is
 	// guaranteed to happen eventually :)
@@ -2363,17 +2376,9 @@
 		TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION);
 
 		// Login
-		TEST_CHECK_THROWS(std::auto_ptr<BackupProtocolLoginConfirmed>
-			loginConf(protocol.QueryLogin(0x01234567, 0)),
-			ConnectionException, Protocol_UnexpectedReply);
-		int type, subType;
-		TEST_EQUAL_LINE(true, protocol.GetLastError(type, subType),
-			"expected a protocol error");
-		TEST_EQUAL_LINE(BackupProtocolError::ErrorType, type,
-			"expected a BackupProtocolError");
-		TEST_EQUAL_LINE(BackupProtocolError::Err_DisabledAccount, subType,
-			"expected an Err_DisabledAccount");
-		
+		TEST_COMMAND_RETURNS_ERROR(protocol, QueryLogin(0x01234567, 0),
+			BackupProtocolError::Err_DisabledAccount);
+
 		// Finish the connection
 		protocol.QueryFinished();
 	}
@@ -2403,6 +2408,7 @@
 		"test", "backup/01234567/", 0, false), // Not read-only
 		BackupStoreException, CorruptReferenceCountDatabase);
 
+	// Run housekeeping, check that it fixes the refcount db
 	std::auto_ptr<BackupStoreAccountDatabase> apAccounts(
 		BackupStoreAccountDatabase::Read("testfiles/accounts.txt"));
 	BackupStoreAccountDatabase::Entry account =
@@ -2458,20 +2464,20 @@
 	// Create some nice recursive directories
 	write_test_file(1);
 	int64_t dirtodelete = create_test_data_subdirs(protocolLocal,
-		BackupProtocolListDirectory::RootDirectory, "test_delete", 6 /* depth */,
+		BACKUPSTORE_ROOT_DIRECTORY_ID, "test_delete", 6 /* depth */,
 		NULL /* pRefCount */);
 
 	TEST_EQUAL(dirtodelete,
 		protocolLocal.QueryDeleteDirectory(dirtodelete)->GetObjectID());
-	test_everything_deleted(protocolLocal, dirtodelete);
+	assert_everything_deleted(protocolLocal, dirtodelete);
 	protocolLocal.QueryFinished();
 
 	// First, things as they are now.
 	TEST_THAT_ABORTONFAIL(StartServer());
 	recursive_count_objects_results before = {0,0,0};
-	recursive_count_objects("localhost", BackupProtocolListDirectory::RootDirectory, before);
+	recursive_count_objects("localhost", BACKUPSTORE_ROOT_DIRECTORY_ID, before);
 	
-	TEST_THAT(before.objectsNotDel == 0);
+	TEST_EQUAL(0, before.objectsNotDel);
 	TEST_THAT(before.deleted != 0);
 	TEST_THAT(before.old != 0);
 
@@ -2478,9 +2484,9 @@
 	// Kill it
 	TEST_THAT(StopServer());
 
-	// Set a new limit on the account -- leave the hard limit 
-	// high to make sure the target for freeing space is the 
-	// soft limit.
+	// Reduce the store limits, so housekeeping will remove all old files.
+	// Leave the hard limit high, so we know that housekeeping's target
+	// for freeing space is the soft limit.
 	TEST_THAT_ABORTONFAIL(::system(BBSTOREACCOUNTS 
 		" -c testfiles/bbstored.conf setlimit 01234567 "
 		"10B 20000B") == 0);
@@ -2560,7 +2566,7 @@
 		std::auto_ptr<IOStream> attr(new MemBlockStream(&modtime, sizeof(modtime)));
 		BackupStoreFilenameClear fnxd("exceed-limit-dir");
 		TEST_CHECK_THROWS(protocol.QueryCreateDirectory(
-				BackupProtocolListDirectory::RootDirectory,
+				BACKUPSTORE_ROOT_DIRECTORY_ID,
 				FAKE_ATTR_MODIFICATION_TIME, fnxd, attr),
 			ConnectionException, Protocol_UnexpectedReply);
 

Modified: box/trunk/test/basicserver/TestCommands.cpp
===================================================================
--- box/trunk/test/basicserver/TestCommands.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/test/basicserver/TestCommands.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -72,8 +72,9 @@
 	return std::auto_ptr<TestProtocolMessage>(new TestProtocolGetStream(mStartingValue, mUncertainSize));
 }
 
-std::auto_ptr<TestProtocolMessage> TestProtocolSendStream::DoCommand(TestProtocolReplyable &rProtocol,
-	TestContext &rContext, IOStream& rDataStream) const
+std::auto_ptr<TestProtocolMessage> TestProtocolSendStream::DoCommand(
+	TestProtocolReplyable &rProtocol, TestContext &rContext,
+	IOStream& rDataStream) const
 {
 	if(mValue != 0x73654353298ffLL)
 	{

Modified: box/trunk/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/trunk/test/bbackupd/testbbackupd.cpp	2014-09-04 01:35:59 UTC (rev 3376)
+++ box/trunk/test/bbackupd/testbbackupd.cpp	2014-09-04 01:36:08 UTC (rev 3377)
@@ -690,7 +690,7 @@
 #endif // !WIN32
 
 #ifdef WIN32
-bool set_file_time(const char* filename, FILETIME creationTime, 
+bool set_file_time(const char* filename, FILETIME creationTime,
 	FILETIME lastModTime, FILETIME lastAccessTime)
 {
 	HANDLE handle = openfile(filename, O_RDWR, 0);
@@ -706,7 +706,7 @@
 }
 #endif
 
-void intercept_setup_delay(const char *filename, unsigned int delay_after, 
+void intercept_setup_delay(const char *filename, unsigned int delay_after,
 	int delay_ms, int syscall_to_delay);
 bool intercept_triggered();
 
@@ -714,7 +714,7 @@
 	const std::string& rChildName)
 {
 	BackupStoreDirectory::Iterator i(rDir);
-	BackupStoreFilenameClear child(rChildName.c_str());
+	BackupStoreFilenameClear child(rChildName);
 	BackupStoreDirectory::Entry *en = i.FindMatchingClearName(child);
 	if (en == 0) return 0;
 	int64_t id = en->GetObjectID();
@@ -1184,8 +1184,7 @@
 			std::string line;
 			TEST_THAT(reader.GetLine(line));
 			std::string comp = "Receive Success(0x";
-			TEST_EQUAL_LINE(comp, line.substr(0, comp.size()),
-				line);
+			TEST_EQUAL_LINE(comp, line.substr(0, comp.size()), line);
 			TEST_THAT(reader.GetLine(line));
 			TEST_EQUAL("Receiving stream, size 124", line);
 			TEST_THAT(reader.GetLine(line));
@@ -1459,7 +1458,10 @@
 	// 0000000c f----- 00002 Test1/spacetest/d3/d4/f5
 	// 0000000d -d---- 00002 Test1/spacetest/d6
 	// 0000000e -d---- 00002 Test1/spacetest/d7
-	// This is 28 blocks total.
+	// 0000000f f--o-- 00002 Test1/spacetest/f1
+	// 00000010 f--o-- 00002 Test1/spacetest/f1
+	// 00000011 f----- 00002 Test1/spacetest/f1
+	// This is 34 blocks total.
 
 	// BLOCK
 	{
@@ -1520,7 +1522,7 @@
 		TEST_THAT(::unlink("testfiles/TestDir1/spacetest/f1") == 0);
 		TEST_THAT(::system("rm -rf testfiles/TestDir1/spacetest/d7") == 0);
 
-		// The following files should be on the server:
+		// The following files should be in the backup directory:
 		// 00000001 -d---- 00002 (root)
 		// 00000002 -d---- 00002 Test1
 		// 00000003 -d---- 00002 Test1/spacetest
@@ -1530,22 +1532,26 @@
 		// 00000007 f----- 00002 Test1/spacetest/d1/f3
 		// 00000008 f----- 00002 Test1/spacetest/d1/f4
 		// 00000009 -d---- 00002 Test1/spacetest/d2
+		// 00000009 -d---- 00002 Test1/spacetest/d6
 		// 0000000a -d---- 00002 Test1/spacetest/d3
 		// 0000000b -d---- 00002 Test1/spacetest/d3/d4
 		// 0000000c f----- 00002 Test1/spacetest/d3/d4/f5
 		// 0000000d -d---- 00002 Test1/spacetest/d6
+		// 0000000d -d---- 00002 Test1/spacetest/d6/d8
+		// 0000000d -d---- 00002 Test1/spacetest/d6/d8/f7
 		// 0000000e -dX--- 00002 Test1/spacetest/d7
-		// This is 28 blocks total, of which 2 in deleted files
+		//
+		// root + location + spacetest1 + spacetest2 = 17 files
+		// = 34 blocks with raidfile. Of which 2 in deleted files
 		// and 18 in directories. Note that f1 and d7 may or may
 		// not be deleted yet.
 		//
-		// spacetest1 + spacetest2 = 16 files = 32 blocks with raidfile
-		// minus one file and one dir is 28 blocks
-		//
-		// d2/f6, d6/d8 and d6/d8/f7 are new
-		// even if the client marks f1 and d7 as deleted, and
-		// housekeeping deleted them, the backup cannot complete
-		// if the limit is 20 blocks.
+		// The files and dirs from spacetest1 are already on the server
+		// (28 blocks). If we set the limit to 20 then the client will
+		// notice as soon as it tries to create the new files and dirs
+		// from spacetest2. It should still delete f1 and d7, but that
+		// won't bring it back under the hard limit, so no files from
+		// spacetest2 should be uploaded.
 
 		BOX_TRACE("Waiting for sync for bbackupd to notice that the "
 			"store is full");
@@ -1554,7 +1560,6 @@
 
 		BOX_TRACE("Compare to check that there are differences");
 		TEST_COMPARE(Compare_Different);
-		BOX_TRACE("Compare finished.");
 
 		// Check that the notify script was run
 		TEST_THAT(TestFileExists("testfiles/notifyran.store-full.1"));
@@ -1619,16 +1624,13 @@
 		// But only twice!
 		// TEST_THAT(!TestFileExists("testfiles/notifyran.store-full.3"));
 
-		// All these should be marked as deleted but hopefully
-		// not removed by housekeeping yet:
+		// All these should be marked as deleted but not removed by
+		// housekeeping yet:
 		// f1		deleted
 		// f2		excluded
-		// d1		excluded (why?)
-		// d1/f3	excluded (why?)
 		// d3		excluded
 		// d3/d4	excluded
 		// d3/d4/f5	excluded
-		// d7		deleted
 		// Careful with timing here, these files will be removed by
 		// housekeeping the next time it runs. On Win32, housekeeping
 		// runs immediately after disconnect, but only if enough time
@@ -1697,7 +1699,6 @@
 			// Log out.
 			client->QueryFinished();
 		}
-		BOX_TRACE("done.");
 
 		if (failures) return 1;
 
@@ -1711,7 +1712,7 @@
 			"deleted files");
 #endif
 
-		BOX_TRACE("Check that the files were removed");
+		BOX_INFO("Checking that the files were removed");
 		{
 			std::auto_ptr<BackupProtocolCallable> client =
 				connect_and_login(context, 0 /* read-write */);
@@ -1737,7 +1738,6 @@
 			TEST_THAT(SearchDir(*spacetest_dir, "d3") == 0);
 			TEST_THAT(SearchDir(*spacetest_dir, "d7") == 0);
 
-
 			// f2, d3, d3/d4 and d3/d4/f5 have been removed.
 			// The files were counted as deleted files before, the
 			// deleted directories just as directories.
@@ -1987,10 +1987,12 @@
 		char buf[PATH_MAX];
 		TEST_THAT(getcwd(buf, sizeof(buf)) == buf);
 		std::string path = buf;
-		path += DIRECTORY_SEPARATOR SYM_DIR 
+		// testfiles/TestDir1/symlink_test/a/subdir ->
+		// testfiles/TestDir1/symlink_test/b/link
+		path += DIRECTORY_SEPARATOR SYM_DIR
 			DIRECTORY_SEPARATOR "a"
 			DIRECTORY_SEPARATOR "subdir";
-		TEST_THAT(symlink(path.c_str(), SYM_DIR 
+		TEST_THAT(symlink(path.c_str(), SYM_DIR
 			DIRECTORY_SEPARATOR "b"
 			DIRECTORY_SEPARATOR "link") == 0);
 
@@ -2267,6 +2269,7 @@
 
 		{
 			#ifdef WIN32
+				// Cygwin chmod changes Windows file attributes
 				TEST_THAT(::system("chmod 0555 testfiles/"
 					"TestDir1/x1") == 0);
 			#else
@@ -2607,7 +2610,6 @@
 			TEST_THAT(unlink(sync_control_file) == 0);
 			wait_for_sync_start();
 			long end_time = time(NULL);
-
 			long wait_time = end_time - start_time + 2;
 
 			// should be about 10 seconds
@@ -2645,15 +2647,15 @@
 
 		#ifndef WIN32
 			// New symlink
-			TEST_THAT(::symlink("does-not-exist", 
+			TEST_THAT(::symlink("does-not-exist",
 				"testfiles/TestDir1/symlink-to-dir") == 0);
 		#endif		
 
 		// Update a file (will be uploaded as a diff)
 		{
-			// Check that the file is over the diffing 
+			// Check that the file is over the diffing
 			// threshold in the bbackupd.conf file
-			TEST_THAT(TestGetFileSize("testfiles/TestDir1/f45.df") 
+			TEST_THAT(TestGetFileSize("testfiles/TestDir1/f45.df")
 				> 1024);
 			
 			// Add a bit to the end
@@ -2661,7 +2663,7 @@
 			TEST_THAT(f != 0);
 			::fprintf(f, "EXTRA STUFF");
 			::fclose(f);
-			TEST_THAT(TestGetFileSize("testfiles/TestDir1/f45.df") 
+			TEST_THAT(TestGetFileSize("testfiles/TestDir1/f45.df")
 				> 1024);
 		}
 
@@ -2685,8 +2687,7 @@
 
 		// Check that store errors are reported neatly
 		printf("\n==== Create store error\n");
-		TEST_THAT(system("rm -f testfiles/notifyran.backup-error.*")
-			== 0);
+		TEST_THAT(system("rm -f testfiles/notifyran.backup-error.*") == 0);
 
 		// Break the store. We need a write lock on the account
 		// while we do this, otherwise housekeeping might be running
@@ -2896,12 +2897,12 @@
 				== 0);
 		#endif
 
-		TEST_THAT(::mkdir("testfiles/TestDir1/symlink-to-dir", 0755) 
+		TEST_THAT(::mkdir("testfiles/TestDir1/symlink-to-dir", 0755)
 			== 0);
-		TEST_THAT(::mkdir("testfiles/TestDir1/x1/dir-to-file", 0755) 
+		TEST_THAT(::mkdir("testfiles/TestDir1/x1/dir-to-file", 0755)
 			== 0);
 
-		// NOTE: create a file within the directory to 
+		// NOTE: create a file within the directory to
 		// avoid deletion by the housekeeping process later
 
 		#ifndef WIN32
@@ -2945,8 +2946,7 @@
 		if (failures) return 1;
 
 		// And then, put it back to how it was before.
-		printf("\n==== Replace symlink with directory "
-			"(which was a symlink)\n");
+		BOX_INFO("Replace symlink with directory (which was a symlink)");
 
 		#ifndef WIN32
 			TEST_THAT(::unlink("testfiles/TestDir1/x1"
@@ -3047,8 +3047,8 @@
 
 		// case which went wrong: rename a tracked file over an
 		// existing tracked file
-		printf("\n==== Rename over existing tracked file\n");
-		fd1 = open("testfiles/TestDir1/tracked-1", 
+		BOX_INFO("Rename over existing tracked file");
+		fd1 = open("testfiles/TestDir1/tracked-1",
 			O_CREAT | O_EXCL | O_WRONLY, 0700);
 		fd2 = open("testfiles/TestDir1/tracked-2",
 			O_CREAT | O_EXCL | O_WRONLY, 0700);
@@ -3079,7 +3079,7 @@
 				== 0);
 		#endif
 
-		TEST_THAT(::rename("testfiles/TestDir1/tracked-1", 
+		TEST_THAT(::rename("testfiles/TestDir1/tracked-1",
 			"testfiles/TestDir1/tracked-2") == 0);
 		TEST_THAT(!TestFileExists("testfiles/TestDir1/tracked-1"));
 		TEST_THAT( TestFileExists("testfiles/TestDir1/tracked-2"));
@@ -3095,7 +3095,7 @@
 		if (!ServerIsAlive(bbstored_pid)) return 1;
 		if (failures) return 1;
 
-		// case which went wrong: rename a tracked file 
+		// case which went wrong: rename a tracked file
 		// over a deleted file
 		printf("\n==== Rename an existing file over a deleted file\n");
 		TEST_THAT(!TestFileExists("testfiles/TestDir1/x1/dsfdsfs98.fd"));
@@ -3105,7 +3105,7 @@
 		wait_for_backup_operation("bbackupd to sync");
 
 		TEST_COMPARE(Compare_Same);
-		
+
 		// Check that no read error has been reported yet
 		TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.1"));
 
@@ -3123,7 +3123,7 @@
 			"testfiles/TestDir1/df9834.dsf") == 0);
 		
 		// Add some more files
-		// Because the 'm' option is not used, these files will 
+		// Because the 'm' option is not used, these files will
 		// look very old to the daemon.
 		// Lucky it'll upload them then!
 		TEST_THAT(unpack_files("test2"));
@@ -3227,7 +3227,7 @@
 				connect_and_login(context,
 				BackupProtocolLogin::Flags_ReadOnly);
 			
-			std::auto_ptr<BackupStoreDirectory> dir = 
+			std::auto_ptr<BackupStoreDirectory> dir =
 				ReadDirectory(*client);
 
 			int64_t testDirId = SearchDir(*dir, "Test1");
@@ -3268,8 +3268,8 @@
 			TEST_THAT(!TestFileExists("testfiles/notifyran.read-error.1"));
 
 			// Check that read errors are reported neatly
-			printf("\n==== Add unreadable files\n");
-			
+			BOX_INFO("Add unreadable files");
+
 			{
 				// Dir and file which can't be read
 				TEST_THAT(::mkdir("testfiles/TestDir1/sub23"
@@ -3320,7 +3320,8 @@
 		::safe_sleep(1);
 
 		{
-			// Open a file, then save something to it every second
+			BOX_INFO("Open a file, then save something to it "
+				"every second for 12 seconds");
 			for(int l = 0; l < 12; ++l)
 			{
 				FILE *f = ::fopen("testfiles/TestDir1/continousupdate", "w+");
@@ -3328,13 +3329,8 @@
 				fprintf(f, "Loop iteration %d\n", l);
 				fflush(f);
 				fclose(f);
-
-				printf(".");
-				fflush(stdout);
 				safe_sleep(1);
 			}
-			printf("\n");
-			fflush(stdout);
 			
 			// Check there's a difference
 			compareReturnValue = ::system("perl testfiles/"
@@ -3343,8 +3339,8 @@
 			TEST_RETURN(compareReturnValue, 1);
 			TestRemoteProcessMemLeaks("bbackupquery.memleaks");
 
-			printf("\n==== Keep on continuously updating file, "
-				"check it is uploaded eventually\n");
+			BOX_INFO("Keep on continuously updating file for "
+				"28 seconds, check it is uploaded eventually");
 
 			for(int l = 0; l < 28; ++l)
 			{
@@ -3354,13 +3350,8 @@
 				fprintf(f, "Loop 2 iteration %d\n", l);
 				fflush(f);
 				fclose(f);
-
-				printf(".");
-				fflush(stdout);
 				safe_sleep(1);
 			}
-			printf("\n");
-			fflush(stdout);
 
 			compareReturnValue = ::system("perl testfiles/"
 				"extcheck2.pl");
@@ -3398,12 +3389,12 @@
 					BackupProtocolLogin::Flags_ReadOnly);
 
 			// Find the ID of the Test1 directory
-			restoredirid = GetDirID(*client, "Test1", 
+			restoredirid = GetDirID(*client, "Test1",
 				BackupProtocolListDirectory::RootDirectory);
 			TEST_THAT(restoredirid != 0);
 
 			// Test the restoration
-			TEST_THAT(BackupClientRestore(*client, restoredirid, 
+			TEST_THAT(BackupClientRestore(*client, restoredirid,
 				"Test1" /* remote */,
 				"testfiles/restore-Test1" /* local */,
 				true /* print progress dots */,
@@ -3417,8 +3408,8 @@
 			// to the server, so we'll compare later.
 
 			// Make sure you can't restore a restored directory
-			TEST_THAT(BackupClientRestore(*client, restoredirid, 
-				"Test1", "testfiles/restore-Test1", 
+			TEST_THAT(BackupClientRestore(*client, restoredirid,
+				"Test1", "testfiles/restore-Test1",
 				true /* print progress dots */,
 				false /* restore deleted */,
 				false /* undelete after */,
@@ -3425,16 +3416,16 @@
 				false /* resume */,
 				false /* keep going */) 
 				== Restore_TargetExists);
-			
+
 			// Find ID of the deleted directory
 			deldirid = GetDirID(*client, "x1", restoredirid);
 			TEST_THAT(deldirid != 0);
 
-			// Just check it doesn't bomb out -- will check this 
+			// Just check it doesn't bomb out -- will check this
 			// properly later (when bbackupd is stopped)
-			TEST_THAT(BackupClientRestore(*client, deldirid, 
+			TEST_THAT(BackupClientRestore(*client, deldirid,
 				"Test1", "testfiles/restore-Test1-x1",
-				true /* print progress dots */, 
+				true /* print progress dots */,
 				true /* restore deleted */,
 				false /* undelete after */,
 				false /* resume */,
@@ -3695,7 +3686,7 @@
 			do_interrupted_restore(context, restoredirid);
 			int64_t resumesize = 0;
 			TEST_THAT(FileExists("testfiles/"
-				"restore-interrupt.boxbackupresume", 
+				"restore-interrupt.boxbackupresume",
 				&resumesize));
 			// make sure it has recorded something to resume
 			TEST_THAT(resumesize > 16);	
@@ -3708,8 +3699,8 @@
 
 			// Check that the restore fn returns resume possible,
 			// rather than doing anything
-			TEST_THAT(BackupClientRestore(*client, restoredirid, 
-				"Test1", "testfiles/restore-interrupt", 
+			TEST_THAT(BackupClientRestore(*client, restoredirid,
+				"Test1", "testfiles/restore-interrupt",
 				true /* print progress dots */, 
 				false /* restore deleted */, 
 				false /* undelete after */, 
@@ -3718,8 +3709,8 @@
 				== Restore_ResumePossible);
 
 			// Then resume it
-			TEST_THAT(BackupClientRestore(*client, restoredirid, 
-				"Test1", "testfiles/restore-interrupt", 
+			TEST_THAT(BackupClientRestore(*client, restoredirid,
+				"Test1", "testfiles/restore-interrupt",
 				true /* print progress dots */, 
 				false /* restore deleted */, 
 				false /* undelete after */, 
@@ -3748,8 +3739,8 @@
 				connect_and_login(context, 0 /* read-write */);
 
 			// Do restore and undelete
-			TEST_THAT(BackupClientRestore(*client, deldirid, 
-				"Test1", "testfiles/restore-Test1-x1-2", 
+			TEST_THAT(BackupClientRestore(*client, deldirid,
+				"Test1", "testfiles/restore-Test1-x1-2",
 				true /* print progress dots */, 
 				true /* deleted files */, 
 				true /* undelete after */,




More information about the Boxbackup-commit mailing list