summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/bbackupd/BackupClientContext.cpp6
-rw-r--r--bin/bbackupd/BackupClientContext.h22
-rw-r--r--bin/bbackupd/BackupClientDirectoryRecord.cpp4
-rw-r--r--bin/bbackupd/BackupClientDirectoryRecord.h63
-rw-r--r--bin/bbackupd/BackupDaemon.cpp59
-rw-r--r--bin/bbackupd/BackupDaemon.h48
-rw-r--r--lib/backupclient/BackupStoreFile.cpp19
-rw-r--r--lib/backupclient/BackupStoreFile.h10
-rw-r--r--lib/backupclient/BackupStoreFileEncodeStream.cpp65
-rw-r--r--lib/backupclient/BackupStoreFileEncodeStream.h10
-rw-r--r--lib/common/ReadLoggingStream.cpp28
-rw-r--r--lib/common/ReadLoggingStream.h19
12 files changed, 267 insertions, 86 deletions
diff --git a/bin/bbackupd/BackupClientContext.cpp b/bin/bbackupd/BackupClientContext.cpp
index 47826211..bf923ce3 100644
--- a/bin/bbackupd/BackupClientContext.cpp
+++ b/bin/bbackupd/BackupClientContext.cpp
@@ -41,7 +41,7 @@
// --------------------------------------------------------------------------
BackupClientContext::BackupClientContext
(
- BackupDaemon &rDaemon,
+ LocationResolver &rResolver,
TLSContext &rTLSContext,
const std::string &rHostname,
int Port,
@@ -51,7 +51,7 @@ BackupClientContext::BackupClientContext
std::string ExtendedLogFile,
ProgressNotifier& rProgressNotifier
)
- : mrDaemon(rDaemon),
+ : mrResolver(rResolver),
mrTLSContext(rTLSContext),
mHostname(rHostname),
mPort(Port),
@@ -470,7 +470,7 @@ bool BackupClientContext::FindFilename(int64_t ObjectID, int64_t ContainingDirec
{
// Location name -- look up in daemon's records
std::string locPath;
- if(!mrDaemon.FindLocationPathName(elementName.GetClearFilename(), locPath))
+ if(!mrResolver.FindLocationPathName(elementName.GetClearFilename(), locPath))
{
// Didn't find the location... so can't give the local filename
return false;
diff --git a/bin/bbackupd/BackupClientContext.h b/bin/bbackupd/BackupClientContext.h
index 0e82cf24..e25c7244 100644
--- a/bin/bbackupd/BackupClientContext.h
+++ b/bin/bbackupd/BackupClientContext.h
@@ -29,6 +29,24 @@ class BackupStoreFilenameClear;
// --------------------------------------------------------------------------
//
// Class
+// Name: LocationResolver
+// Purpose: Interface for classes that can resolve locations to paths,
+// like BackupDaemon
+// Created: 2003/10/08
+//
+// --------------------------------------------------------------------------
+class LocationResolver
+{
+public:
+ virtual ~LocationResolver() { }
+ virtual bool FindLocationPathName(const std::string &rLocationName,
+ std::string &rPathOut) const = 0;
+};
+
+
+// --------------------------------------------------------------------------
+//
+// Class
// Name: BackupClientContext
// Purpose:
// Created: 2003/10/08
@@ -39,7 +57,7 @@ class BackupClientContext : public DiffTimer
public:
BackupClientContext
(
- BackupDaemon &rDaemon,
+ LocationResolver &rResolver,
TLSContext &rTLSContext,
const std::string &rHostname,
int32_t Port,
@@ -207,7 +225,7 @@ public:
}
private:
- BackupDaemon &mrDaemon;
+ LocationResolver &mrResolver;
TLSContext &mrTLSContext;
std::string mHostname;
int mPort;
diff --git a/bin/bbackupd/BackupClientDirectoryRecord.cpp b/bin/bbackupd/BackupClientDirectoryRecord.cpp
index ea5ee973..7e3cc550 100644
--- a/bin/bbackupd/BackupClientDirectoryRecord.cpp
+++ b/bin/bbackupd/BackupClientDirectoryRecord.cpp
@@ -1482,7 +1482,9 @@ int64_t BackupClientDirectoryRecord::UploadFile(
// Prepare to upload, getting a stream which will encode the file as we go along
std::auto_ptr<IOStream> upload(
BackupStoreFile::EncodeFile(rFilename.c_str(),
- mObjectID, rStoreFilename));
+ mObjectID, rStoreFilename, NULL,
+ &rParams,
+ &(rParams.mrRunStatusProvider)));
// Send to store
std::auto_ptr<BackupProtocolClientSuccess> stored(
diff --git a/bin/bbackupd/BackupClientDirectoryRecord.h b/bin/bbackupd/BackupClientDirectoryRecord.h
index 472005b6..9a9cd2cb 100644
--- a/bin/bbackupd/BackupClientDirectoryRecord.h
+++ b/bin/bbackupd/BackupClientDirectoryRecord.h
@@ -13,10 +13,12 @@
#include <string>
#include <map>
-#include "BoxTime.h"
#include "BackupClientFileAttributes.h"
#include "BackupStoreDirectory.h"
+#include "BoxTime.h"
#include "MD5Digest.h"
+#include "ReadLoggingStream.h"
+#include "RunStatusProvider.h"
class Archive;
class BackupClientContext;
@@ -25,6 +27,21 @@ class BackupDaemon;
// --------------------------------------------------------------------------
//
// Class
+// Name: SysadminNotifier
+// Purpose: Provides a NotifySysadmin() method to send mail to the sysadmin
+// Created: 2005/11/15
+//
+// --------------------------------------------------------------------------
+class SysadminNotifier
+{
+ public:
+ virtual ~SysadminNotifier() { }
+ virtual void NotifySysadmin(int Event) = 0;
+};
+
+// --------------------------------------------------------------------------
+//
+// Class
// Name: ProgressNotifier
// Purpose: Provides methods for the backup library to inform the user
// interface about its progress with the backup
@@ -37,6 +54,7 @@ class ProgressNotifier
{
public:
virtual ~ProgressNotifier() { }
+ virtual void NotifyIDMapsSetup(BackupClientContext& rContext) = 0;
virtual void NotifyScanDirectory(
const BackupClientDirectoryRecord* pDirRecord,
const std::string& rLocalPath) = 0;
@@ -102,6 +120,11 @@ class ProgressNotifier
virtual void NotifyFileDeleted(
int64_t ObjectID,
const std::string& rRemotePath) = 0;
+ virtual void NotifyReadProgress(int64_t readSize, int64_t offset,
+ int64_t length, box_time_t elapsed, box_time_t finish) = 0;
+ virtual void NotifyReadProgress(int64_t readSize, int64_t offset,
+ int64_t length) = 0;
+ virtual void NotifyReadProgress(int64_t readSize, int64_t offset) = 0;
};
// --------------------------------------------------------------------------
@@ -138,11 +161,13 @@ public:
// Created: 8/3/04
//
// --------------------------------------------------------------------------
- class SyncParams
+ class SyncParams : public ReadLoggingStream::Logger
{
public:
SyncParams(
- BackupDaemon &rDaemon,
+ RunStatusProvider &rRunStatusProvider,
+ SysadminNotifier &rSysadminNotifier,
+ ProgressNotifier &rProgressNotifier,
BackupClientContext &rContext);
~SyncParams();
private:
@@ -158,13 +183,43 @@ public:
box_time_t mMaxFileTimeInFuture;
int32_t mFileTrackingSizeThreshold;
int32_t mDiffingUploadSizeThreshold;
- BackupDaemon &mrDaemon;
+ RunStatusProvider &mrRunStatusProvider;
+ SysadminNotifier &mrSysadminNotifier;
+ ProgressNotifier &mrProgressNotifier;
BackupClientContext &mrContext;
bool mReadErrorsOnFilesystemObjects;
// Member variables modified by syncing process
box_time_t mUploadAfterThisTimeInTheFuture;
bool mHaveLoggedWarningAboutFutureFileTimes;
+
+ bool StopRun() { return mrRunStatusProvider.StopRun(); }
+ void NotifySysadmin(int Event)
+ {
+ mrSysadminNotifier.NotifySysadmin(Event);
+ }
+ ProgressNotifier& GetProgressNotifier() const
+ {
+ return mrProgressNotifier;
+ }
+
+ /* ReadLoggingStream::Logger implementation */
+ virtual void Log(int64_t readSize, int64_t offset,
+ int64_t length, box_time_t elapsed, box_time_t finish)
+ {
+ mrProgressNotifier.NotifyReadProgress(readSize, offset,
+ length, elapsed, finish);
+ }
+ virtual void Log(int64_t readSize, int64_t offset,
+ int64_t length)
+ {
+ mrProgressNotifier.NotifyReadProgress(readSize, offset,
+ length);
+ }
+ virtual void Log(int64_t readSize, int64_t offset)
+ {
+ mrProgressNotifier.NotifyReadProgress(readSize, offset);
+ }
};
void SyncDirectory(SyncParams &rParams,
diff --git a/bin/bbackupd/BackupDaemon.cpp b/bin/bbackupd/BackupDaemon.cpp
index fe5fa35f..06e23728 100644
--- a/bin/bbackupd/BackupDaemon.cpp
+++ b/bin/bbackupd/BackupDaemon.cpp
@@ -49,34 +49,33 @@
#include "SSLLib.h"
-#include "BackupDaemon.h"
-#include "BackupDaemonConfigVerify.h"
+#include "autogen_BackupProtocolClient.h"
+#include "autogen_ClientException.h"
+#include "autogen_ConversionException.h"
+#include "Archive.h"
#include "BackupClientContext.h"
+#include "BackupClientCryptoKeys.h"
#include "BackupClientDirectoryRecord.h"
-#include "BackupStoreDirectory.h"
#include "BackupClientFileAttributes.h"
-#include "BackupStoreFilenameClear.h"
#include "BackupClientInodeToIDMap.h"
-#include "autogen_BackupProtocolClient.h"
-#include "autogen_ConversionException.h"
-#include "BackupClientCryptoKeys.h"
-#include "BannerText.h"
+#include "BackupClientMakeExcludeList.h"
+#include "BackupDaemon.h"
+#include "BackupDaemonConfigVerify.h"
+#include "BackupStoreConstants.h"
+#include "BackupStoreDirectory.h"
+#include "BackupStoreException.h"
#include "BackupStoreFile.h"
-#include "Random.h"
+#include "BackupStoreFilenameClear.h"
+#include "BannerText.h"
+#include "Conversion.h"
#include "ExcludeList.h"
-#include "BackupClientMakeExcludeList.h"
-#include "IOStreamGetLine.h"
-#include "Utils.h"
#include "FileStream.h"
-#include "BackupStoreException.h"
-#include "BackupStoreConstants.h"
-#include "LocalProcessStream.h"
#include "IOStreamGetLine.h"
-#include "Conversion.h"
-#include "Archive.h"
-#include "Timer.h"
+#include "LocalProcessStream.h"
#include "Logging.h"
-#include "autogen_ClientException.h"
+#include "Random.h"
+#include "Timer.h"
+#include "Utils.h"
#ifdef WIN32
#include "Win32ServiceFunctions.h"
@@ -122,13 +121,23 @@ unsigned int WINAPI HelperThread(LPVOID lpParam)
// --------------------------------------------------------------------------
BackupDaemon::BackupDaemon()
: mState(BackupDaemon::State_Initialising),
+ mDeleteRedundantLocationsAfter(0),
mpCommandSocketInfo(0),
mDeleteUnusedRootDirEntriesAfter(0),
mClientStoreMarker(BackupClientContext::ClientStoreMarker_NotKnown),
mStorageLimitExceeded(false),
mReadErrorsOnFilesystemObjects(false),
mLastSyncTime(0),
- mLogAllFileAccess(false)
+ mNextSyncTime(0),
+ mCurrentSyncStartTime(0),
+ mUpdateStoreInterval(0),
+ mDeleteStoreObjectInfoFile(false),
+ mDoSyncForcedByPreviousSyncError(false),
+ mLogAllFileAccess(false),
+ mpProgressNotifier(this),
+ mpLocationResolver(this),
+ mpRunStatusProvider(this),
+ mpSysadminNotifier(this)
#ifdef WIN32
, mInstallService(false),
mRemoveService(false),
@@ -1078,14 +1087,14 @@ void BackupDaemon::RunSyncNow()
// just connect, as this may be unnecessary)
BackupClientContext clientContext
(
- *this,
+ *mpLocationResolver,
mTlsContext,
conf.GetKeyValue("StoreHostname"),
conf.GetKeyValueInt("StorePort"),
conf.GetKeyValueInt("AccountNumber"),
conf.GetKeyValueBool("ExtendedLogging"),
conf.KeyExists("ExtendedLogFile"),
- extendedLogFile, *this
+ extendedLogFile, *mpProgressNotifier
);
// The minimum age a file needs to be before it will be
@@ -1158,8 +1167,8 @@ void BackupDaemon::RunSyncNow()
}
// Set up the sync parameters
- BackupClientDirectoryRecord::SyncParams params(
- *this, clientContext);
+ BackupClientDirectoryRecord::SyncParams params(*mpRunStatusProvider,
+ *mpSysadminNotifier, *mpProgressNotifier, clientContext);
params.mSyncPeriodStart = syncPeriodStart;
params.mSyncPeriodEnd = syncPeriodEndExtended;
// use potentially extended end time
@@ -1214,6 +1223,8 @@ void BackupDaemon::RunSyncNow()
SetupLocations(clientContext, locations);
}
+ mpProgressNotifier->NotifyIDMapsSetup(clientContext);
+
// Get some ID maps going
SetupIDMapsForSync();
diff --git a/bin/bbackupd/BackupDaemon.h b/bin/bbackupd/BackupDaemon.h
index ff1839db..f7d61838 100644
--- a/bin/bbackupd/BackupDaemon.h
+++ b/bin/bbackupd/BackupDaemon.h
@@ -14,6 +14,7 @@
#include <string>
#include <memory>
+#include "BackupClientContext.h"
#include "BackupClientDirectoryRecord.h"
#include "BoxTime.h"
#include "Daemon.h"
@@ -45,7 +46,8 @@ class Archive;
// Created: 2003/10/08
//
// --------------------------------------------------------------------------
-class BackupDaemon : public Daemon, ProgressNotifier
+class BackupDaemon : public Daemon, ProgressNotifier, LocationResolver,
+RunStatusProvider, SysadminNotifier
{
public:
BackupDaemon();
@@ -153,7 +155,7 @@ private:
int UseScriptToSeeIfSyncAllowed();
-private:
+public:
class Location
{
public:
@@ -173,7 +175,11 @@ private:
ExcludeList *mpExcludeFiles;
ExcludeList *mpExcludeDirs;
};
-
+
+ typedef const std::vector<Location *> Locations;
+ Locations GetLocations() { return mLocations; }
+
+private:
int mState; // what the daemon is currently doing
std::vector<Location *> mLocations;
@@ -229,8 +235,26 @@ public:
private:
bool mLogAllFileAccess;
+public:
+ ProgressNotifier* GetProgressNotifier() { return mpProgressNotifier; }
+ LocationResolver* GetLocationResolver() { return mpLocationResolver; }
+ RunStatusProvider* GetRunStatusProvider() { return mpRunStatusProvider; }
+ SysadminNotifier* GetSysadminNotifier() { return mpSysadminNotifier; }
+ void SetProgressNotifier (ProgressNotifier* p) { mpProgressNotifier = p; }
+ void SetLocationResolver (LocationResolver* p) { mpLocationResolver = p; }
+ void SetRunStatusProvider(RunStatusProvider* p) { mpRunStatusProvider = p; }
+ void SetSysadminNotifier (SysadminNotifier* p) { mpSysadminNotifier = p; }
+
+private:
+ ProgressNotifier* mpProgressNotifier;
+ LocationResolver* mpLocationResolver;
+ RunStatusProvider* mpRunStatusProvider;
+ SysadminNotifier* mpSysadminNotifier;
+
/* ProgressNotifier implementation */
public:
+ virtual void NotifyIDMapsSetup(BackupClientContext& rContext) { }
+
virtual void NotifyScanDirectory(
const BackupClientDirectoryRecord* pDirRecord,
const std::string& rLocalPath)
@@ -467,6 +491,24 @@ public:
")");
}
}
+ virtual void NotifyReadProgress(int64_t readSize, int64_t offset,
+ int64_t length, box_time_t elapsed, box_time_t finish)
+ {
+ BOX_TRACE("Read " << readSize << " bytes at " << offset <<
+ ", " << (length - offset) << " remain, eta " <<
+ BoxTimeToSeconds(finish - elapsed) << "s");
+ }
+ virtual void NotifyReadProgress(int64_t readSize, int64_t offset,
+ int64_t length)
+ {
+ BOX_TRACE("Read " << readSize << " bytes at " << offset <<
+ ", " << (length - offset) << " remain");
+ }
+ virtual void NotifyReadProgress(int64_t readSize, int64_t offset)
+ {
+ BOX_TRACE("Read " << readSize << " bytes at " << offset <<
+ ", unknown bytes remaining");
+ }
#ifdef WIN32
public:
diff --git a/lib/backupclient/BackupStoreFile.cpp b/lib/backupclient/BackupStoreFile.cpp
index 7e93d59d..68040d29 100644
--- a/lib/backupclient/BackupStoreFile.cpp
+++ b/lib/backupclient/BackupStoreFile.cpp
@@ -65,22 +65,27 @@ BackupStoreFileStats BackupStoreFile::msStats = {0,0,0};
// Function
// Name: BackupStoreFile::EncodeFile(IOStream &, IOStream &)
// Purpose: Encode a file into something for storing on file server.
-// Requires a real filename so full info can be stored.
+// Requires a real filename so full info can be stored.
//
-// Returns a stream. Most of the work is done by the stream
-// when data is actually requested -- the file will be held
-// open until the stream is deleted or the file finished.
+// Returns a stream. Most of the work is done by the stream
+// when data is actually requested -- the file will be held
+// open until the stream is deleted or the file finished.
// Created: 2003/08/28
//
// --------------------------------------------------------------------------
-std::auto_ptr<IOStream> BackupStoreFile::EncodeFile(const char *Filename, int64_t ContainerID, const BackupStoreFilename &rStoreFilename, int64_t *pModificationTime)
+std::auto_ptr<IOStream> BackupStoreFile::EncodeFile(const char *Filename,
+ int64_t ContainerID, const BackupStoreFilename &rStoreFilename,
+ int64_t *pModificationTime, ReadLoggingStream::Logger* pLogger,
+ RunStatusProvider* pRunStatusProvider)
{
// Create the stream
std::auto_ptr<IOStream> stream(new BackupStoreFileEncodeStream);
// Do the initial setup
- ((BackupStoreFileEncodeStream*)stream.get())->Setup(Filename, 0 /* no recipe, just encode */,
- ContainerID, rStoreFilename, pModificationTime);
+ ((BackupStoreFileEncodeStream*)stream.get())->Setup(Filename,
+ 0 /* no recipe, just encode */,
+ ContainerID, rStoreFilename, pModificationTime, pLogger,
+ pRunStatusProvider);
// Return the stream for the caller
return stream;
diff --git a/lib/backupclient/BackupStoreFile.h b/lib/backupclient/BackupStoreFile.h
index ee482f3e..d7a71318 100644
--- a/lib/backupclient/BackupStoreFile.h
+++ b/lib/backupclient/BackupStoreFile.h
@@ -14,9 +14,11 @@
#include <memory>
-#include "IOStream.h"
#include "BackupClientFileAttributes.h"
#include "BackupStoreFilename.h"
+#include "IOStream.h"
+#include "ReadLoggingStream.h"
+#include "RunStatusProvider.h"
typedef struct
{
@@ -116,7 +118,11 @@ public:
// Main interface
- static std::auto_ptr<IOStream> EncodeFile(const char *Filename, int64_t ContainerID, const BackupStoreFilename &rStoreFilename, int64_t *pModificationTime = 0);
+ static std::auto_ptr<IOStream> EncodeFile(const char *Filename,
+ int64_t ContainerID, const BackupStoreFilename &rStoreFilename,
+ int64_t *pModificationTime = 0,
+ ReadLoggingStream::Logger* pLogger = NULL,
+ RunStatusProvider* pRunStatusProvider = NULL);
static std::auto_ptr<IOStream> EncodeFileDiff
(
const char *Filename, int64_t ContainerID,
diff --git a/lib/backupclient/BackupStoreFileEncodeStream.cpp b/lib/backupclient/BackupStoreFileEncodeStream.cpp
index b9d7745f..3b45e6c0 100644
--- a/lib/backupclient/BackupStoreFileEncodeStream.cpp
+++ b/lib/backupclient/BackupStoreFileEncodeStream.cpp
@@ -11,18 +11,18 @@
#include <string.h>
-#include "BackupStoreFileEncodeStream.h"
+#include "BackupClientFileAttributes.h"
+#include "BackupStoreConstants.h"
+#include "BackupStoreException.h"
#include "BackupStoreFile.h"
-#include "BackupStoreFileWire.h"
#include "BackupStoreFileCryptVar.h"
+#include "BackupStoreFileEncodeStream.h"
+#include "BackupStoreFileWire.h"
#include "BackupStoreObjectMagic.h"
-#include "BackupStoreException.h"
-#include "BackupStoreConstants.h"
#include "BoxTime.h"
-#include "BackupClientFileAttributes.h"
#include "FileStream.h"
-#include "RollingChecksum.h"
#include "Random.h"
+#include "RollingChecksum.h"
#include "MemLeakFindOn.h"
@@ -41,6 +41,7 @@ BackupStoreFileEncodeStream::BackupStoreFileEncodeStream()
: mpRecipe(0),
mpFile(0),
mpLogging(0),
+ mpRunStatusProvider(NULL),
mStatus(Status_Header),
mSendData(true),
mTotalBlocks(0),
@@ -107,8 +108,11 @@ BackupStoreFileEncodeStream::~BackupStoreFileEncodeStream()
// Created: 8/12/03
//
// --------------------------------------------------------------------------
-void BackupStoreFileEncodeStream::Setup(const char *Filename, BackupStoreFileEncodeStream::Recipe *pRecipe,
- int64_t ContainerID, const BackupStoreFilename &rStoreFilename, int64_t *pModificationTime)
+void BackupStoreFileEncodeStream::Setup(const char *Filename,
+ BackupStoreFileEncodeStream::Recipe *pRecipe,
+ int64_t ContainerID, const BackupStoreFilename &rStoreFilename,
+ int64_t *pModificationTime, ReadLoggingStream::Logger* pLogger,
+ RunStatusProvider* pRunStatusProvider)
{
// Pointer to a blank recipe which we might create
BackupStoreFileEncodeStream::Recipe *pblankRecipe = 0;
@@ -128,9 +132,9 @@ void BackupStoreFileEncodeStream::Setup(const char *Filename, BackupStoreFileEnc
pblankRecipe = new BackupStoreFileEncodeStream::Recipe(0, 0);
BackupStoreFileEncodeStream::RecipeInstruction instruction;
- instruction.mSpaceBefore = fileSize; // whole file
- instruction.mBlocks = 0; // no blocks
- instruction.mpStartBlock = 0; // no block
+ instruction.mSpaceBefore = fileSize; // whole file
+ instruction.mBlocks = 0; // no blocks
+ instruction.mpStartBlock = 0; // no block
pblankRecipe->push_back(instruction);
pRecipe = pblankRecipe;
@@ -210,8 +214,18 @@ void BackupStoreFileEncodeStream::Setup(const char *Filename, BackupStoreFileEnc
// Open the file
mpFile = new FileStream(Filename);
- // Create logging stream
- mpLogging = new ReadLoggingStream(*mpFile);
+ if (pLogger)
+ {
+ // Create logging stream
+ mpLogging = new ReadLoggingStream(*mpFile,
+ *pLogger);
+ }
+ else
+ {
+ // re-use FileStream instead
+ mpLogging = mpFile;
+ mpFile = NULL;
+ }
// Work out the largest possible block required for the encoded data
mAllocatedBufferSize = BackupStoreFile::MaxBlockSizeForChunkSize(maxBlockClearSize);
@@ -259,6 +273,8 @@ void BackupStoreFileEncodeStream::Setup(const char *Filename, BackupStoreFileEnc
}
throw;
}
+
+ mpRunStatusProvider = pRunStatusProvider;
}
@@ -316,6 +332,11 @@ int BackupStoreFileEncodeStream::Read(void *pBuffer, int NBytes, int Timeout)
{
return 0;
}
+
+ if(mpRunStatusProvider && mpRunStatusProvider->StopRun())
+ {
+ THROW_EXCEPTION(BackupStoreException, SignalReceived);
+ }
int bytesToRead = NBytes;
uint8_t *buffer = (uint8_t*)pBuffer;
@@ -531,22 +552,25 @@ void BackupStoreFileEncodeStream::EncodeCurrentBlock()
ASSERT(blockRawSize < mAllocatedBufferSize);
// Check file open
- if(mpFile == 0 || mpLogging == 0)
+ if(mpLogging == 0)
{
// File should be open, but isn't. So logical error.
THROW_EXCEPTION(BackupStoreException, Internal)
}
// Read the data in
- if(!mpLogging->ReadFullBuffer(mpRawBuffer, blockRawSize, 0 /* not interested in size if failure */))
+ if(!mpLogging->ReadFullBuffer(mpRawBuffer, blockRawSize,
+ 0 /* not interested in size if failure */))
{
- // TODO: Do something more intelligent, and abort this upload because the file
- // has changed
- THROW_EXCEPTION(BackupStoreException, Temp_FileEncodeStreamDidntReadBuffer)
+ // TODO: Do something more intelligent, and abort
+ // this upload because the file has changed.
+ THROW_EXCEPTION(BackupStoreException,
+ Temp_FileEncodeStreamDidntReadBuffer)
}
// Encode it
- mCurrentBlockEncodedSize = BackupStoreFile::EncodeChunk(mpRawBuffer, blockRawSize, mEncodedBuffer);
+ mCurrentBlockEncodedSize = BackupStoreFile::EncodeChunk(mpRawBuffer,
+ blockRawSize, mEncodedBuffer);
//TRACE2("Encode: Encoded size of block %d is %d\n", (int32_t)mCurrentBlock, (int32_t)mCurrentBlockEncodedSize);
@@ -557,7 +581,8 @@ void BackupStoreFileEncodeStream::EncodeCurrentBlock()
strongChecksum.Finish();
// Add entry to the index
- StoreBlockIndexEntry(mCurrentBlockEncodedSize, blockRawSize, weakChecksum.GetChecksum(), strongChecksum.DigestAsData());
+ StoreBlockIndexEntry(mCurrentBlockEncodedSize, blockRawSize,
+ weakChecksum.GetChecksum(), strongChecksum.DigestAsData());
// Set vars to reading this block
mPositionInCurrentBlock = 0;
diff --git a/lib/backupclient/BackupStoreFileEncodeStream.h b/lib/backupclient/BackupStoreFileEncodeStream.h
index fb5d0851..c5fa780a 100644
--- a/lib/backupclient/BackupStoreFileEncodeStream.h
+++ b/lib/backupclient/BackupStoreFileEncodeStream.h
@@ -18,6 +18,7 @@
#include "MD5Digest.h"
#include "BackupStoreFile.h"
#include "ReadLoggingStream.h"
+#include "RunStatusProvider.h"
namespace BackupStoreFileCreation
{
@@ -74,7 +75,11 @@ public:
int64_t mOtherFileID;
};
- void Setup(const char *Filename, Recipe *pRecipe, int64_t ContainerID, const BackupStoreFilename &rStoreFilename, int64_t *pModificationTime);
+ void Setup(const char *Filename, Recipe *pRecipe, int64_t ContainerID,
+ const BackupStoreFilename &rStoreFilename,
+ int64_t *pModificationTime,
+ ReadLoggingStream::Logger* pLogger = NULL,
+ RunStatusProvider* pRunStatusProvider = NULL);
virtual int Read(void *pBuffer, int NBytes, int Timeout);
virtual void Write(const void *pBuffer, int NBytes);
@@ -101,7 +106,8 @@ private:
Recipe *mpRecipe;
IOStream *mpFile; // source file
CollectInBufferStream mData; // buffer for header and index entries
- ReadLoggingStream *mpLogging;
+ IOStream *mpLogging;
+ RunStatusProvider* mpRunStatusProvider;
int mStatus;
bool mSendData; // true if there's file data to send (ie not a symlink)
int64_t mTotalBlocks; // Total number of blocks in the file
diff --git a/lib/common/ReadLoggingStream.cpp b/lib/common/ReadLoggingStream.cpp
index 9023f827..54c99c95 100644
--- a/lib/common/ReadLoggingStream.cpp
+++ b/lib/common/ReadLoggingStream.cpp
@@ -25,12 +25,13 @@
// Created: 2007/01/16
//
// --------------------------------------------------------------------------
-ReadLoggingStream::ReadLoggingStream(IOStream& rSource)
+ReadLoggingStream::ReadLoggingStream(IOStream& rSource, Logger& rLogger)
: mrSource(rSource),
mOffset(0),
mLength(mrSource.BytesLeftToRead()),
mTotalRead(0),
- mStartTime(GetCurrentBoxTime())
+ mStartTime(GetCurrentBoxTime()),
+ mrLogger(rLogger)
{ }
@@ -52,26 +53,21 @@ int ReadLoggingStream::Read(void *pBuffer, int NBytes, int Timeout)
mOffset += numBytesRead;
}
- if (mLength >= 0 && mTotalRead > 0)
+ if (mLength == 0)
{
- box_time_t timeNow = GetCurrentBoxTime();
- box_time_t elapsed = timeNow - mStartTime;
- box_time_t finish = (elapsed * mLength) / mTotalRead;
- box_time_t remain = finish - elapsed;
-
- BOX_TRACE("Read " << numBytesRead << " bytes at " << mOffset <<
- ", " << (mLength - mOffset) << " remain, eta " <<
- BoxTimeToSeconds(remain) << "s");
+ mrLogger.Log(numBytesRead, mOffset);
}
- else if (mLength >= 0 && mTotalRead == 0)
+ else if (mTotalRead == 0)
{
- BOX_TRACE("Read " << numBytesRead << " bytes at " << mOffset <<
- ", " << (mLength - mOffset) << " remain");
+ mrLogger.Log(numBytesRead, mOffset, mLength);
}
else
{
- BOX_TRACE("Read " << numBytesRead << " bytes at " << mOffset <<
- ", unknown bytes remaining");
+ box_time_t timeNow = GetCurrentBoxTime();
+ box_time_t elapsed = timeNow - mStartTime;
+ box_time_t finish = (elapsed * mLength) / mTotalRead;
+ // box_time_t remain = finish - elapsed;
+ mrLogger.Log(numBytesRead, mOffset, mLength, elapsed, finish);
}
return numBytesRead;
diff --git a/lib/common/ReadLoggingStream.h b/lib/common/ReadLoggingStream.h
index 15c3ef48..b23b542c 100644
--- a/lib/common/ReadLoggingStream.h
+++ b/lib/common/ReadLoggingStream.h
@@ -15,13 +15,27 @@
class ReadLoggingStream : public IOStream
{
+public:
+ class Logger
+ {
+ public:
+ virtual ~Logger() { }
+ virtual void Log(int64_t readSize, int64_t offset,
+ int64_t length, box_time_t elapsed,
+ box_time_t finish) = 0;
+ virtual void Log(int64_t readSize, int64_t offset,
+ int64_t length) = 0;
+ virtual void Log(int64_t readSize, int64_t offset) = 0;
+ };
+
private:
IOStream& mrSource;
IOStream::pos_type mOffset, mLength, mTotalRead;
box_time_t mStartTime;
+ Logger& mrLogger;
public:
- ReadLoggingStream(IOStream& rSource);
+ ReadLoggingStream(IOStream& rSource, Logger& rLogger);
virtual int Read(void *pBuffer, int NBytes, int Timeout = IOStream::TimeOutInfinite);
virtual pos_type BytesLeftToRead();
@@ -35,7 +49,8 @@ public:
private:
ReadLoggingStream(const ReadLoggingStream &rToCopy)
- : mrSource(rToCopy.mrSource) { /* do not call */ }
+ : mrSource(rToCopy.mrSource), mrLogger(rToCopy.mrLogger)
+ { /* do not call */ }
};
#endif // READLOGGINGSTREAM__H