summaryrefslogtreecommitdiff
path: root/lib/common/FileStream.cpp
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2009-01-04 13:43:54 +0000
committerChris Wilson <chris+github@qwirx.com>2009-01-04 13:43:54 +0000
commit6a5fa78ebb1178d97d18ea533f3be0a700667511 (patch)
tree08b2eeba4a37b6fd4e008755052a97a0045ce81c /lib/common/FileStream.cpp
parent4c118b664a47228a06b8cdec94e4d92049c7f78e (diff)
Move stream comparison code out of BackupQueries::Compare to
FileStream class.
Diffstat (limited to 'lib/common/FileStream.cpp')
-rw-r--r--lib/common/FileStream.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/common/FileStream.cpp b/lib/common/FileStream.cpp
index 3e3ace3f..09296d79 100644
--- a/lib/common/FileStream.cpp
+++ b/lib/common/FileStream.cpp
@@ -403,3 +403,44 @@ bool FileStream::StreamClosed()
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;
+}