[Box Backup-commit] COMMIT r3348 - in box/trunk/lib: backupstore common raidfile

subversion at boxbackup.org subversion at boxbackup.org
Tue Apr 29 20:22:54 BST 2014


Author: chris
Date: 2014-04-29 20:22:54 +0100 (Tue, 29 Apr 2014)
New Revision: 3348

Modified:
   box/trunk/lib/backupstore/BackupStoreDirectory.cpp
   box/trunk/lib/common/BufferedStream.h
   box/trunk/lib/common/FileStream.h
   box/trunk/lib/common/IOStream.cpp
   box/trunk/lib/common/IOStream.h
   box/trunk/lib/raidfile/RaidFileRead.cpp
   box/trunk/lib/raidfile/RaidFileRead.h
Log:
Add a ToString method to IOStream and some subclasses.

Useful to help debug problems such as invalid file headers when the source
of the stream might not be too obvious.

Modified: box/trunk/lib/backupstore/BackupStoreDirectory.cpp
===================================================================
--- box/trunk/lib/backupstore/BackupStoreDirectory.cpp	2014-04-29 19:22:46 UTC (rev 3347)
+++ box/trunk/lib/backupstore/BackupStoreDirectory.cpp	2014-04-29 19:22:54 UTC (rev 3348)
@@ -133,11 +133,11 @@
 	if(OBJECTMAGIC_DIR_MAGIC_VALUE != ntohl(hdr.mMagicValue))
 	{
 		THROW_EXCEPTION_MESSAGE(BackupStoreException, BadDirectoryFormat,
-			"Wrong magic number in directory object " << 
-			BOX_FORMAT_OBJECTID(mObjectID) << ": expected " <<
+			"Wrong magic number for directory: expected " <<
 			BOX_FORMAT_HEX32(OBJECTMAGIC_DIR_MAGIC_VALUE) <<
 			" but found " <<
-			BOX_FORMAT_HEX32(ntohl(hdr.mMagicValue)));
+			BOX_FORMAT_HEX32(ntohl(hdr.mMagicValue)) << " in " <<
+			rStream.ToString());
 	}
 	
 	// Get data

Modified: box/trunk/lib/common/BufferedStream.h
===================================================================
--- box/trunk/lib/common/BufferedStream.h	2014-04-29 19:22:46 UTC (rev 3347)
+++ box/trunk/lib/common/BufferedStream.h	2014-04-29 19:22:54 UTC (rev 3348)
@@ -33,6 +33,10 @@
 	virtual bool StreamDataLeft();
 	virtual bool StreamClosed();
 
+	virtual std::string ToString() const
+	{
+		return std::string("Buffered ") + mrSource.ToString();
+	}
 private:
 	BufferedStream(const BufferedStream &rToCopy) 
 	: mrSource(rToCopy.mrSource) { /* do not call */ }

Modified: box/trunk/lib/common/FileStream.h
===================================================================
--- box/trunk/lib/common/FileStream.h	2014-04-29 19:22:46 UTC (rev 3347)
+++ box/trunk/lib/common/FileStream.h	2014-04-29 19:22:54 UTC (rev 3348)
@@ -49,6 +49,10 @@
 	virtual bool StreamClosed();
 
 	bool CompareWith(IOStream& rOther, int Timeout = IOStream::TimeOutInfinite);
+	std::string ToString() const
+	{
+		return std::string("local file ") + mFileName;
+	}
 
 private:
 	tOSFileHandle mOSFileHandle;

Modified: box/trunk/lib/common/IOStream.cpp
===================================================================
--- box/trunk/lib/common/IOStream.cpp	2014-04-29 19:22:46 UTC (rev 3347)
+++ box/trunk/lib/common/IOStream.cpp	2014-04-29 19:22:54 UTC (rev 3348)
@@ -245,7 +245,30 @@
 	}
 }
 
+// --------------------------------------------------------------------------
+//
+// Function
+//		Name:    IOStream::Write
+//		Purpose: Convenience method for writing a null-terminated
+//			 C string to a protocol buffer.
+//
+// --------------------------------------------------------------------------
 void IOStream::Write(const char *pBuffer)
 {
 	Write(pBuffer, strlen(pBuffer));
 }
+
+// --------------------------------------------------------------------------
+//
+// Function
+//		Name:    IOStream::ToString()
+//		Purpose: Returns a string which describes this stream. Useful
+//			 when reporting exceptions about a stream of unknown
+//			 origin, for example in BackupStoreDirectory().
+//		Created: 2014/04/28
+//
+// --------------------------------------------------------------------------
+std::string IOStream::ToString() const
+{
+	return "unknown IOStream";
+}

Modified: box/trunk/lib/common/IOStream.h
===================================================================
--- box/trunk/lib/common/IOStream.h	2014-04-29 19:22:46 UTC (rev 3347)
+++ box/trunk/lib/common/IOStream.h	2014-04-29 19:22:54 UTC (rev 3348)
@@ -65,6 +65,7 @@
 	void Flush(int Timeout = IOStream::TimeOutInfinite);
 	
 	static int ConvertSeekTypeToOSWhence(int SeekType);
+	virtual std::string ToString() const;
 };
 
 

Modified: box/trunk/lib/raidfile/RaidFileRead.cpp
===================================================================
--- box/trunk/lib/raidfile/RaidFileRead.cpp	2014-04-29 19:22:46 UTC (rev 3347)
+++ box/trunk/lib/raidfile/RaidFileRead.cpp	2014-04-29 19:22:54 UTC (rev 3348)
@@ -1767,6 +1767,7 @@
 	return RaidFileUtil::DiscUsageInBlocks(GetFileSize(), rdiscSet);
 }
 
-
-
-
+std::string RaidFileRead::ToString() const
+{
+	return std::string("RaidFile ") + mFilename;
+}

Modified: box/trunk/lib/raidfile/RaidFileRead.h
===================================================================
--- box/trunk/lib/raidfile/RaidFileRead.h	2014-04-29 19:22:46 UTC (rev 3347)
+++ box/trunk/lib/raidfile/RaidFileRead.h	2014-04-29 19:22:54 UTC (rev 3348)
@@ -61,6 +61,7 @@
 	virtual pos_type BytesLeftToRead();
 
 	pos_type GetDiscUsageInBlocks();
+	std::string ToString() const;
 
 	typedef int64_t FileSizeType;
 




More information about the Boxbackup-commit mailing list