From 882c246415297ac8c66047b91f3dfaa059c4645e Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 26 Nov 2015 23:44:16 +0000 Subject: [PATCH] Allow constructing a BackupProtocolLocal with an existing BackupStoreContext. Together with previous changes to BackupStoreContext, this allows the use of BackupProtocolLocal with S3BackupFileSystem, mainly for testing. --- lib/backupstore/BackupProtocol.h | 35 ++++++++++++++++++++++---------- lib/server/makeprotocol.pl.in | 7 +++++++ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/lib/backupstore/BackupProtocol.h b/lib/backupstore/BackupProtocol.h index d9070c73d..9e0895c8e 100644 --- a/lib/backupstore/BackupProtocol.h +++ b/lib/backupstore/BackupProtocol.h @@ -25,27 +25,40 @@ class BackupProtocolLocal2 : public BackupProtocolLocal { private: - BackupStoreContext mContext; + std::auto_ptr mapLocalContext; int32_t mAccountNumber; bool mReadOnly; -protected: - BackupStoreContext& GetContext() { return mContext; } - public: BackupProtocolLocal2(int32_t AccountNumber, const std::string& ConnectionDetails, const std::string& AccountRootDir, int DiscSetNumber, bool ReadOnly) - // This is rather ugly: the BackupProtocolLocal constructor must not - // touch the Context, because it's not initialised yet! - : BackupProtocolLocal(mContext), - mContext(AccountNumber, (HousekeepingInterface *)NULL, - ConnectionDetails), + // This is rather ugly: we need to pass a reference to a context to + // BackupProtocolLocal(), and we want it to be one that we've created ourselves, + // so we create one with new(), dereference it to pass the reference to the + // superclass, and then get the reference out again, take its address and stick + // that into the auto_ptr, which will delete it when we are destroyed. + : BackupProtocolLocal( + *(new BackupStoreContext(AccountNumber, (HousekeepingInterface *)NULL, + ConnectionDetails)) + ), + mapLocalContext(&GetContext()), + mAccountNumber(AccountNumber), + mReadOnly(ReadOnly) + { + GetContext().SetClientHasAccount(AccountRootDir, DiscSetNumber); + QueryVersion(BACKUP_STORE_SERVER_VERSION); + QueryLogin(AccountNumber, + ReadOnly ? BackupProtocolLogin::Flags_ReadOnly : 0); + } + BackupProtocolLocal2(BackupStoreContext& rContext, int32_t AccountNumber, + bool ReadOnly) + : BackupProtocolLocal(rContext), mAccountNumber(AccountNumber), mReadOnly(ReadOnly) { - mContext.SetClientHasAccount(AccountRootDir, DiscSetNumber); + GetContext().SetClientHasAccount(); QueryVersion(BACKUP_STORE_SERVER_VERSION); QueryLogin(AccountNumber, ReadOnly ? BackupProtocolLogin::Flags_ReadOnly : 0); @@ -56,7 +69,7 @@ class BackupProtocolLocal2 : public BackupProtocolLocal { std::auto_ptr finished = BackupProtocolLocal::Query(rQuery); - mContext.ReleaseWriteLock(); + GetContext().ReleaseWriteLock(); return finished; } diff --git a/lib/server/makeprotocol.pl.in b/lib/server/makeprotocol.pl.in index afc25ffdf..fab993fdf 100755 --- a/lib/server/makeprotocol.pl.in +++ b/lib/server/makeprotocol.pl.in @@ -887,6 +887,13 @@ __E private: $context_class &mrContext; std::auto_ptr<$message_base_class> mapLastReply; + +protected: + $context_class& GetContext() + { + return mrContext; + } + public: virtual std::auto_ptr ReceiveStream() {