summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2015-08-15 10:57:59 +0000
committerChris Wilson <chris+github@qwirx.com>2015-08-15 10:57:59 +0000
commitfeade829d345bd6e34f39dfc32498696e6f588a1 (patch)
tree84faf18ef5e1cc9c9bd6eba36946db6a7dfff0f2
parent62c0689012de2786ed2fae3da84b5301d6b49a55 (diff)
Improve exception handling on backup store side.
Add a new exception code to represent an object being completely missing (not found on the store at all), separate from not being found in a particular directory. Improve mapping of server-side exceptions to protocol error messages returned to the client. Add handling for missing exceptions, such as BackupStoreException::PatchChainInfoBadInDirectory, and the new BackupStoreException::ObjectDoesNotExist. Fix mapping for BackupStoreException::CouldNotFindEntryInDirectory to make it distinguistable from BackupStoreException::ObjectDoesNotExist.
-rw-r--r--lib/backupstore/BackupCommands.cpp33
-rw-r--r--lib/backupstore/BackupStoreException.txt1
-rw-r--r--test/backupstore/testbackupstore.cpp8
3 files changed, 36 insertions, 6 deletions
diff --git a/lib/backupstore/BackupCommands.cpp b/lib/backupstore/BackupCommands.cpp
index ab0dc4b8..22ef0215 100644
--- a/lib/backupstore/BackupCommands.cpp
+++ b/lib/backupstore/BackupCommands.cpp
@@ -85,12 +85,20 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolReplyable::HandleException(Bo
}
else if(e.GetSubType() == BackupStoreException::CouldNotFindEntryInDirectory)
{
- return PROTOCOL_ERROR(Err_DoesNotExist);
+ return PROTOCOL_ERROR(Err_DoesNotExistInDirectory);
}
else if(e.GetSubType() == BackupStoreException::NameAlreadyExistsInDirectory)
{
return PROTOCOL_ERROR(Err_TargetNameExists);
}
+ else if(e.GetSubType() == BackupStoreException::ObjectDoesNotExist)
+ {
+ return PROTOCOL_ERROR(Err_DoesNotExist);
+ }
+ else if(e.GetSubType() == BackupStoreException::PatchChainInfoBadInDirectory)
+ {
+ return PROTOCOL_ERROR(Err_PatchConsistencyError);
+ }
}
throw;
@@ -779,7 +787,28 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolGetObjectName::DoCommand(Back
}
// Load up the directory
- const BackupStoreDirectory &rdir(rContext.GetDirectory(dirID));
+ const BackupStoreDirectory *pDir;
+
+ try
+ {
+ pDir = &rContext.GetDirectory(dirID);
+ }
+ catch(BackupStoreException &e)
+ {
+ if(e.GetSubType() == BackupStoreException::ObjectDoesNotExist)
+ {
+ // If this can't be found, then there is a problem...
+ // tell the caller it can't be found.
+ return std::auto_ptr<BackupProtocolMessage>(
+ new BackupProtocolObjectName(
+ BackupProtocolObjectName::NumNameElements_ObjectDoesntExist,
+ 0, 0, 0));
+ }
+
+ throw;
+ }
+
+ const BackupStoreDirectory& rdir(*pDir);
// Find the element in this directory and store it's name
if(objectID != ObjectID_DirectoryOnly)
diff --git a/lib/backupstore/BackupStoreException.txt b/lib/backupstore/BackupStoreException.txt
index b49a9cf2..40232a8e 100644
--- a/lib/backupstore/BackupStoreException.txt
+++ b/lib/backupstore/BackupStoreException.txt
@@ -72,3 +72,4 @@ UnknownObjectRefCountRequested 68 A reference count was requested for an object
MultiplyReferencedObject 69 Attempted to modify an object with multiple references, should be uncloned first
CorruptReferenceCountDatabase 70 The account's refcount database is corrupt and must be rebuilt by housekeeping.
CancelledByBackgroundTask 71 The current task was cancelled on request by the background task.
+ObjectDoesNotExist 72 The specified object ID does not exist in the store.
diff --git a/test/backupstore/testbackupstore.cpp b/test/backupstore/testbackupstore.cpp
index f30fd42a..c3798bf2 100644
--- a/test/backupstore/testbackupstore.cpp
+++ b/test/backupstore/testbackupstore.cpp
@@ -1723,7 +1723,7 @@ bool test_server_commands()
BACKUPSTORE_ROOT_DIRECTORY_ID, subdirid,
BackupProtocolMoveObject::Flags_MoveAllWithSameName,
newName),
- Err_DoesNotExist);
+ Err_DoesNotExistInDirectory);
BackupStoreFilenameClear newName("moved-files");
TEST_COMMAND_RETURNS_ERROR(*apProtocol,
QueryMoveObject(
@@ -1732,7 +1732,7 @@ bool test_server_commands()
subdirid,
BackupProtocolMoveObject::Flags_MoveAllWithSameName,
newName),
- Err_DoesNotExist);
+ Err_DoesNotExistInDirectory);
TEST_COMMAND_RETURNS_ERROR(*apProtocol,
QueryMoveObject(
uploads[UPLOAD_FILE_TO_MOVE].allocated_objid,
@@ -1740,7 +1740,7 @@ bool test_server_commands()
subdirid,
BackupProtocolMoveObject::Flags_MoveAllWithSameName,
newName),
- Err_DoesNotExist);
+ Err_DoesNotExistInDirectory);
}
// File exists, but not in this directory (we just moved it)
@@ -1750,7 +1750,7 @@ bool test_server_commands()
subdirid,
BackupProtocolMoveObject::Flags_MoveAllWithSameName,
newName),
- Err_DoesNotExist);
+ Err_DoesNotExistInDirectory);
// Moving file to same directory that it's already in,
// with the same name