[Box Backup-commit] COMMIT r3319 - in box/trunk: bin/bbackupquery lib/backupstore test/bbackupd

subversion at boxbackup.org subversion at boxbackup.org
Wed Apr 9 23:15:36 BST 2014


Author: chris
Date: 2014-04-09 23:15:36 +0100 (Wed, 09 Apr 2014)
New Revision: 3319

Modified:
   box/trunk/bin/bbackupquery/BackupQueries.cpp
   box/trunk/lib/backupstore/backupprotocol.txt
   box/trunk/test/bbackupd/testbbackupd.cpp
Log:
Remove NoObject reply, and adapt BackupQueries accordingly.

Modified: box/trunk/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/trunk/bin/bbackupquery/BackupQueries.cpp	2014-04-09 22:15:31 UTC (rev 3318)
+++ box/trunk/bin/bbackupquery/BackupQueries.cpp	2014-04-09 22:15:36 UTC (rev 3319)
@@ -875,21 +875,27 @@
 	{
 		// Request object
 		std::auto_ptr<BackupProtocolSuccess> getobj(mrConnection.QueryGetObject(id));
-		if(getobj->GetObjectID() != BackupProtocolGetObject::NoObject)
-		{
-			// Stream that object out to the file
-			std::auto_ptr<IOStream> objectStream(mrConnection.ReceiveStream());
-			objectStream->CopyStreamTo(out);
+
+		// Stream that object out to the file
+		std::auto_ptr<IOStream> objectStream(mrConnection.ReceiveStream());
+		objectStream->CopyStreamTo(out);
 			
-			BOX_INFO("Object ID " << BOX_FORMAT_OBJECTID(id) <<
-				" fetched successfully.");
-		}
-		else
+		BOX_INFO("Object ID " << BOX_FORMAT_OBJECTID(id) <<
+			" fetched successfully.");
+	}
+	catch(ConnectionException &e)
+	{
+		if(mrConnection.GetLastErrorType() == BackupProtocolError::Err_DoesNotExist)
 		{
 			BOX_ERROR("Object ID " << BOX_FORMAT_OBJECTID(id) <<
 				" does not exist on store.");
 			::unlink(args[1].c_str());
 		}
+		else
+		{
+			BOX_ERROR("Error occured fetching object.");
+			::unlink(args[1].c_str());
+		}
 	}
 	catch(...)
 	{

Modified: box/trunk/lib/backupstore/backupprotocol.txt
===================================================================
--- box/trunk/lib/backupstore/backupprotocol.txt	2014-04-09 22:15:31 UTC (rev 3318)
+++ box/trunk/lib/backupstore/backupprotocol.txt	2014-04-09 22:15:36 UTC (rev 3319)
@@ -77,8 +77,7 @@
 
 GetObject	10	Command(Success)
 	int64		ObjectID
-	CONSTANT	NoObject	0
-	# reply has stream following, if ObjectID != NoObject
+	# reply has stream following (if successful)
 
 
 MoveObject	11	Command(Success)

Modified: box/trunk/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/trunk/test/bbackupd/testbbackupd.cpp	2014-04-09 22:15:31 UTC (rev 3318)
+++ box/trunk/test/bbackupd/testbbackupd.cpp	2014-04-09 22:15:36 UTC (rev 3319)
@@ -888,6 +888,34 @@
 		client->QueryFinished();
 	}
 
+	printf("\n==== Testing that GetObject on nonexistent file outputs the "
+		"correct error message\n");
+	{
+		std::auto_ptr<BackupProtocolClient> connection = ConnectAndLogin(
+			context, 0 /* read-write */);
+		std::string errs;
+		std::auto_ptr<Configuration> config(
+			Configuration::LoadAndVerify
+				("testfiles/bbackupd.conf", &BackupDaemonConfigVerify, errs));
+		BackupQueries query(*connection, *config, false); // read-only
+		std::vector<std::string> args;
+		args.push_back("2"); // object ID
+		args.push_back("testfiles/2.obj"); // output file
+		bool opts[256];
+
+		Capture capture;
+		Logging::TempLoggerGuard guard(&capture);
+		query.CommandGetObject(args, opts);
+		std::vector<Capture::Message> messages = capture.GetMessages();
+		TEST_THAT(!messages.empty());
+		if (!messages.empty())
+		{
+			std::string last_message = messages.back().message;
+			TEST_EQUAL("Object ID 0x2 does not exist on store.",
+				last_message);
+		}
+	}
+		
 	// unpack the files for the initial test
 	TEST_THAT(::system("rm -rf testfiles/TestDir1") == 0);
 	TEST_THAT(::mkdir("testfiles/TestDir1", 0777) == 0);




More information about the Boxbackup-commit mailing list