[Box Backup-commit] COMMIT r1590 - box/chris/merge/lib/backupclient

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Sat, 28 Apr 2007 18:31:39 +0100


Author: chris
Date: 2007-04-28 18:31:38 +0100 (Sat, 28 Apr 2007)
New Revision: 1590

Modified:
   box/chris/merge/lib/backupclient/BackupStoreFileEncodeStream.cpp
   box/chris/merge/lib/backupclient/BackupStoreFileEncodeStream.h
Log:
Use ReadLoggingStream to log progress of file uploads. (refs #3)


Modified: box/chris/merge/lib/backupclient/BackupStoreFileEncodeStream.cpp
===================================================================
--- box/chris/merge/lib/backupclient/BackupStoreFileEncodeStream.cpp	2007-04-28 17:30:58 UTC (rev 1589)
+++ box/chris/merge/lib/backupclient/BackupStoreFileEncodeStream.cpp	2007-04-28 17:31:38 UTC (rev 1590)
@@ -38,6 +38,7 @@
 BackupStoreFileEncodeStream::BackupStoreFileEncodeStream()
 	: mpRecipe(0),
 	  mpFile(0),
+	  mpLogging(0),
 	  mStatus(Status_Header),
 	  mSendData(true),
 	  mTotalBlocks(0),
@@ -79,6 +80,13 @@
 		mpFile = 0;
 	}
 	
+	// Clear up logging stream
+	if(mpLogging)
+	{
+		delete mpLogging;
+		mpLogging = 0;
+	}
+	
 	// Free the recipe
 	if(mpRecipe != 0)
 	{
@@ -199,6 +207,9 @@
 		{
 			// Open the file
 			mpFile = new FileStream(Filename);
+
+			// Create logging stream
+			mpLogging = new ReadLoggingStream(*mpFile);
 		
 			// Work out the largest possible block required for the encoded data
 			mAllocatedBufferSize = BackupStoreFile::MaxBlockSizeForChunkSize(maxBlockClearSize);
@@ -474,7 +485,7 @@
 	}
 	
 	// Move forward in the stream
-	mpFile->Seek(sizeToSkip, IOStream::SeekType_Relative);
+	mpLogging->Seek(sizeToSkip, IOStream::SeekType_Relative);
 }
 
 
@@ -518,14 +529,14 @@
 	ASSERT(blockRawSize < mAllocatedBufferSize);
 
 	// Check file open
-	if(mpFile == 0)
+	if(mpFile == 0 || mpLogging == 0)
 	{
 		// File should be open, but isn't. So logical error.
 		THROW_EXCEPTION(BackupStoreException, Internal)
 	}
 	
 	// Read the data in
-	if(!mpFile->ReadFullBuffer(mpRawBuffer, blockRawSize, 0 /* not interested in size if failure */))
+	if(!mpLogging->ReadFullBuffer(mpRawBuffer, blockRawSize, 0 /* not interested in size if failure */))
 	{
 		// TODO: Do something more intelligent, and abort this upload because the file
 		// has changed

Modified: box/chris/merge/lib/backupclient/BackupStoreFileEncodeStream.h
===================================================================
--- box/chris/merge/lib/backupclient/BackupStoreFileEncodeStream.h	2007-04-28 17:30:58 UTC (rev 1589)
+++ box/chris/merge/lib/backupclient/BackupStoreFileEncodeStream.h	2007-04-28 17:31:38 UTC (rev 1590)
@@ -17,6 +17,7 @@
 #include "CollectInBufferStream.h"
 #include "MD5Digest.h"
 #include "BackupStoreFile.h"
+#include "ReadLoggingStream.h"
 
 namespace BackupStoreFileCreation
 {
@@ -100,6 +101,7 @@
 	Recipe *mpRecipe;
 	IOStream *mpFile;					// source file
 	CollectInBufferStream mData;		// buffer for header and index entries
+	ReadLoggingStream *mpLogging;
 	int mStatus;
 	bool mSendData;						// true if there's file data to send (ie not a symlink)
 	int64_t mTotalBlocks;				// Total number of blocks in the file