diff options
author | Chris Wilson <chris+github@qwirx.com> | 2013-08-22 00:17:34 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2013-08-22 00:17:34 +0000 |
commit | c8af9906b692de24dbf1b03c563d85fa85d3a4dc (patch) | |
tree | 16c97aa693fb5e7133b4e10c826c901bdcddbe10 /lib/backupstore/BackupCommands.cpp | |
parent | 410c85a13d5812efeadb13e3ffa82b9629331100 (diff) |
Pass std::auto_ptr objects to Protocol for upload.
Passing raw pointers is bad C++ style, and dangerous, because Protocol
will free the passed-in pointers after uploading them, so we should not
keep using them.
Reduce code duplication in BackupClientDirectoryRecord patch/normal upload.
Return a std::auto_ptr<BackupStoreFileEncodeStream> instead of a
std::auto_ptr<IOStream> from BackupStoreFile::EncodeFile* functions.
Diffstat (limited to 'lib/backupstore/BackupCommands.cpp')
-rw-r--r-- | lib/backupstore/BackupCommands.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/backupstore/BackupCommands.cpp b/lib/backupstore/BackupCommands.cpp index aa4d3823..341c7368 100644 --- a/lib/backupstore/BackupCommands.cpp +++ b/lib/backupstore/BackupCommands.cpp @@ -207,7 +207,7 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolListDirectory::DoCommand(Back stream->SetForReading(); // Get the protocol to send the stream - rProtocol.SendStreamAfterCommand(stream.release()); + rProtocol.SendStreamAfterCommand(static_cast< std::auto_ptr<IOStream> > (stream)); return std::auto_ptr<BackupProtocolMessage>( new BackupProtocolSuccess(mObjectID)); @@ -300,7 +300,7 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolGetObject::DoCommand(BackupPr std::auto_ptr<IOStream> object(rContext.OpenObject(mObjectID)); // Stream it to the peer - rProtocol.SendStreamAfterCommand(object.release()); + rProtocol.SendStreamAfterCommand(object); // Tell the caller what the file was return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); @@ -463,11 +463,8 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolGetFile::DoCommand(BackupProt } // Stream the reordered stream to the peer - rProtocol.SendStreamAfterCommand(stream.get()); + rProtocol.SendStreamAfterCommand(stream); - // Don't delete the stream here - stream.release(); - // Tell the caller what the file was return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); } @@ -831,7 +828,7 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolGetObjectName::DoCommand(Back // Get the stream ready to go stream->SetForReading(); // Tell the protocol to send the stream - rProtocol.SendStreamAfterCommand(stream.release()); + rProtocol.SendStreamAfterCommand(static_cast< std::auto_ptr<IOStream> >(stream)); } // Make reply @@ -859,7 +856,7 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolGetBlockIndexByID::DoCommand( BackupStoreFile::MoveStreamPositionToBlockIndex(*stream); // Return the stream to the client - rProtocol.SendStreamAfterCommand(stream.release()); + rProtocol.SendStreamAfterCommand(stream); // Return the object ID return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(mObjectID)); @@ -911,7 +908,7 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolGetBlockIndexByName::DoComman BackupStoreFile::MoveStreamPositionToBlockIndex(*stream); // Return the stream to the client - rProtocol.SendStreamAfterCommand(stream.release()); + rProtocol.SendStreamAfterCommand(stream); // Return the object ID return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(objectID)); |