[Box Backup-commit] COMMIT r2432 - in box/trunk: bin/bbackupquery lib/common

boxbackup-dev at boxbackup.org boxbackup-dev at boxbackup.org
Sun Jan 4 13:43:54 GMT 2009


Author: chris
Date: 2009-01-04 13:43:54 +0000 (Sun, 04 Jan 2009)
New Revision: 2432

Modified:
   box/trunk/bin/bbackupquery/BackupQueries.cpp
   box/trunk/lib/common/FileStream.cpp
   box/trunk/lib/common/FileStream.h
Log:
Move stream comparison code out of BackupQueries::Compare to 
FileStream class.


Modified: box/trunk/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/trunk/bin/bbackupquery/BackupQueries.cpp	2009-01-04 13:42:19 UTC (rev 2431)
+++ box/trunk/bin/bbackupquery/BackupQueries.cpp	2009-01-04 13:43:54 UTC (rev 2432)
@@ -1728,34 +1728,7 @@
 							SelfFlushingStream flushFile(*fileOnServerStream);
 							// Open the local file
 							FileStream l(localPath.c_str());
-							
-							// Size
-							IOStream::pos_type fileSizeLocal = l.BytesLeftToRead();
-							IOStream::pos_type fileSizeServer = 0;
-							
-							// Test the contents
-							char buf1[2048];
-							char buf2[2048];
-							while(fileOnServerStream->StreamDataLeft() && l.StreamDataLeft())
-							{
-								int size = fileOnServerStream->Read(buf1, sizeof(buf1), mrConnection.GetTimeout());
-								fileSizeServer += size;
-								
-								if(l.Read(buf2, size) != size
-										|| ::memcmp(buf1, buf2, size) != 0)
-								{
-									equal = false;
-									break;
-								}
-							}
-	
-							// Check read all the data from the server and file -- can't be equal if local and remote aren't the same length
-							// Can't use StreamDataLeft() test on file, because if it's the same size, it won't know
-							// it's EOF yet.
-							if(fileOnServerStream->StreamDataLeft() || fileSizeServer != fileSizeLocal)
-							{
-								equal = false;
-							}
+							equal = l.CompareWith(fileOnServerStream,  mrConnection.GetTimeout());
 						}
 					}
 

Modified: box/trunk/lib/common/FileStream.cpp
===================================================================
--- box/trunk/lib/common/FileStream.cpp	2009-01-04 13:42:19 UTC (rev 2431)
+++ box/trunk/lib/common/FileStream.cpp	2009-01-04 13:43:54 UTC (rev 2432)
@@ -403,3 +403,44 @@
 	return mIsEOF;
 }
 
+// --------------------------------------------------------------------------
+//
+// Function
+//		Name:    FileStream::CompareWith(IOStream&, int)
+//		Purpose: Compare bytes in this file with other stream's data
+//		Created: 2009/01/03
+//
+// --------------------------------------------------------------------------
+bool FileStream::CompareWith(IOStream& rOther, int Timeout)
+{
+	// Size
+	IOStream::pos_type mySize = BytesLeftToRead();
+	IOStream::pos_type otherSize = 0;
+	
+	// Test the contents
+	char buf1[2048];
+	char buf2[2048];
+	while(StreamDataLeft() && rOther.StreamDataLeft())
+	{
+		int readSize = rOther.Read(buf1, sizeof(buf1), Timeout);
+		otherSize += readSize;
+		
+		if(Read(buf2, readSize) != readSize ||
+			::memcmp(buf1, buf2, readSize) != 0)
+		{
+			return false;
+		}
+	}
+
+	// Check read all the data from the server and file -- can't be
+	// equal if local and remote aren't the same length. Can't use
+	// StreamDataLeft() test on local file, because if it's the same
+	// size, it won't know it's EOF yet.
+	
+	if(rOther.StreamDataLeft() || otherSize != mySize)
+	{
+		return false;
+	}
+
+	return true;
+}

Modified: box/trunk/lib/common/FileStream.h
===================================================================
--- box/trunk/lib/common/FileStream.h	2009-01-04 13:42:19 UTC (rev 2431)
+++ box/trunk/lib/common/FileStream.h	2009-01-04 13:43:54 UTC (rev 2432)
@@ -56,6 +56,8 @@
 	virtual bool StreamDataLeft();
 	virtual bool StreamClosed();
 
+	bool CompareWith(IOStream& rOther, int Timeout = IOStream::TimeOutInfinite);
+
 private:
 	tOSFileHandle mOSFileHandle;
 	bool mIsEOF;




More information about the Boxbackup-commit mailing list