diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-04-09 22:15:36 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2014-04-09 22:15:36 +0000 |
commit | 3b324ca62004b8ed56c3cba3ebdf61ef97b66324 (patch) | |
tree | c437fa90b904a060af17ae2ea8da446052ce6238 | |
parent | 44ed218f0b219392a9e89647840c5a61c40858de (diff) |
Remove NoObject reply, and adapt BackupQueries accordingly.
-rw-r--r-- | bin/bbackupquery/BackupQueries.cpp | 24 | ||||
-rw-r--r-- | lib/backupstore/backupprotocol.txt | 3 | ||||
-rw-r--r-- | test/bbackupd/testbbackupd.cpp | 28 |
3 files changed, 44 insertions, 11 deletions
diff --git a/bin/bbackupquery/BackupQueries.cpp b/bin/bbackupquery/BackupQueries.cpp index 413b5c1c..2c4c13d8 100644 --- a/bin/bbackupquery/BackupQueries.cpp +++ b/bin/bbackupquery/BackupQueries.cpp @@ -875,21 +875,27 @@ void BackupQueries::CommandGetObject(const std::vector<std::string> &args, const { // 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(...) { diff --git a/lib/backupstore/backupprotocol.txt b/lib/backupstore/backupprotocol.txt index be037313..a151df9b 100644 --- a/lib/backupstore/backupprotocol.txt +++ b/lib/backupstore/backupprotocol.txt @@ -77,8 +77,7 @@ SetClientStoreMarker 6 Command(Success) 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) diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp index 827e3ea0..46289808 100644 --- a/test/bbackupd/testbbackupd.cpp +++ b/test/bbackupd/testbbackupd.cpp @@ -888,6 +888,34 @@ int test_bbackupd() 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); |