summaryrefslogtreecommitdiff
path: root/lib/backupstore
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-02-13 23:29:27 +0000
committerChris Wilson <chris+github@qwirx.com>2014-02-13 23:29:27 +0000
commitba952ab7cd6fddd1a7754544e4322ceb707e2244 (patch)
tree6dcbededdcc49197626391b9b09ae72ff86f7e7e /lib/backupstore
parent7350aca3277d84d4818ecb34fb38bc24f9f72710 (diff)
Add a shortcut interface to uploading a new file.
Useful in tests.
Diffstat (limited to 'lib/backupstore')
-rw-r--r--lib/backupstore/BackupStoreFile.cpp39
-rw-r--r--lib/backupstore/BackupStoreFile.h15
2 files changed, 52 insertions, 2 deletions
diff --git a/lib/backupstore/BackupStoreFile.cpp b/lib/backupstore/BackupStoreFile.cpp
index 519305ff..e011f8f4 100644
--- a/lib/backupstore/BackupStoreFile.cpp
+++ b/lib/backupstore/BackupStoreFile.cpp
@@ -1556,3 +1556,42 @@ DiffTimer::DiffTimer()
DiffTimer::~DiffTimer()
{
}
+
+// Shortcut interface
+int64_t BackupStoreFile::QueryStoreFileDiff(BackupProtocolCallable& protocol,
+ const std::string& LocalFilename, int64_t DirectoryObjectID,
+ int64_t DiffFromFileID, int64_t AttributesHash,
+ const BackupStoreFilenameClear& StoreFilename, int Timeout,
+ DiffTimer *pDiffTimer, ReadLoggingStream::Logger* pLogger,
+ RunStatusProvider* pRunStatusProvider)
+{
+ int64_t ModificationTime;
+ std::auto_ptr<BackupStoreFileEncodeStream> pStream;
+
+ if(DiffFromFileID)
+ {
+ // Fetch the block index for this one
+ std::auto_ptr<BackupProtocolSuccess> getblockindex =
+ protocol.QueryGetBlockIndexByName(DirectoryObjectID,
+ StoreFilename);
+ ASSERT(getblockindex->GetObjectID() == DiffFromFileID);
+ std::auto_ptr<IOStream> blockIndexStream(protocol.ReceiveStream());
+
+ pStream = EncodeFileDiff(LocalFilename,
+ DirectoryObjectID, StoreFilename, DiffFromFileID,
+ *(blockIndexStream.get()), Timeout, pDiffTimer,
+ &ModificationTime, NULL // pIsCompletelyDifferent
+ );
+ }
+ else
+ {
+ pStream = BackupStoreFile::EncodeFile(LocalFilename,
+ DirectoryObjectID, StoreFilename);
+ }
+
+ std::auto_ptr<IOStream> upload(pStream.release());
+ return protocol.QueryStoreFile(DirectoryObjectID,
+ ModificationTime, AttributesHash, DiffFromFileID,
+ StoreFilename, upload)->GetObjectID();
+}
+
diff --git a/lib/backupstore/BackupStoreFile.h b/lib/backupstore/BackupStoreFile.h
index 7c72e010..8e2cefb6 100644
--- a/lib/backupstore/BackupStoreFile.h
+++ b/lib/backupstore/BackupStoreFile.h
@@ -14,6 +14,7 @@
#include <memory>
#include <cstdlib>
+#include "autogen_BackupProtocol.h"
#include "BackupClientFileAttributes.h"
#include "BackupStoreFilename.h"
#include "IOStream.h"
@@ -40,6 +41,8 @@ class RunStatusProvider;
// Have some memory allocation commands, note closing "Off" at end of file.
#include "MemLeakFindOn.h"
+class BackupStoreFileEncodeStream;
+
// --------------------------------------------------------------------------
//
// Class
@@ -60,8 +63,6 @@ public:
virtual bool IsManaged() = 0;
};
-class BackupStoreFileEncodeStream;
-
// --------------------------------------------------------------------------
//
// Class
@@ -139,6 +140,16 @@ public:
int64_t *pModificationTime = 0,
bool *pIsCompletelyDifferent = 0
);
+ // Shortcut interface
+ static int64_t QueryStoreFileDiff(BackupProtocolCallable& protocol,
+ const std::string& LocalFilename, int64_t DirectoryObjectID,
+ int64_t DiffFromFileID, int64_t AttributesHash,
+ const BackupStoreFilenameClear& StoreFilename,
+ int Timeout = IOStream::TimeOutInfinite,
+ DiffTimer *pDiffTimer = NULL,
+ ReadLoggingStream::Logger* pLogger = NULL,
+ RunStatusProvider* pRunStatusProvider = NULL);
+
static bool VerifyEncodedFileFormat(IOStream &rFile, int64_t *pDiffFromObjectIDOut = 0, int64_t *pContainerIDOut = 0);
static void CombineFile(IOStream &rDiff, IOStream &rDiff2, IOStream &rFrom, IOStream &rOut);
static void CombineDiffs(IOStream &rDiff1, IOStream &rDiff2, IOStream &rDiff2b, IOStream &rOut);