From c7662795f519d2b6797e4b1ac7fa4a22afa26310 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 27 Jul 2006 23:18:35 +0000 Subject: * merge - This is my current patch queue. I think that all of these are safe to apply. This is just under half of the pending changes in chris/general (the easy half). --- lib/backupclient/BackupClientFileAttributes.cpp | 2 ++ lib/backupclient/BackupStoreFile.cpp | 2 ++ lib/backupclient/BackupStoreObjectDump.cpp | 8 +++++++- 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientFileAttributes.cpp b/lib/backupclient/BackupClientFileAttributes.cpp index 974db3c9..ace72cf8 100644 --- a/lib/backupclient/BackupClientFileAttributes.cpp +++ b/lib/backupclient/BackupClientFileAttributes.cpp @@ -642,6 +642,7 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename) const } // If working as root, set user IDs + #ifndef WIN32 if(::geteuid() == 0) { #ifndef HAVE_LCHOWN @@ -661,6 +662,7 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename) const } #endif } + #endif if(static_cast(xattrOffset+sizeof(u_int32_t))<=mpClearAttributes->GetSize()) { diff --git a/lib/backupclient/BackupStoreFile.cpp b/lib/backupclient/BackupStoreFile.cpp index f5a55207..278bf50a 100644 --- a/lib/backupclient/BackupStoreFile.cpp +++ b/lib/backupclient/BackupStoreFile.cpp @@ -289,6 +289,8 @@ void BackupStoreFile::DecodeFile(IOStream &rEncodedFile, const char *DecodedFile // Copy it out to the file stream->CopyStreamTo(out); } + + out.Close(); // Write the attributes stream->GetAttributes().WriteAttributes(DecodedFilename); diff --git a/lib/backupclient/BackupStoreObjectDump.cpp b/lib/backupclient/BackupStoreObjectDump.cpp index b4ccc731..d3d9cc17 100644 --- a/lib/backupclient/BackupStoreObjectDump.cpp +++ b/lib/backupclient/BackupStoreObjectDump.cpp @@ -113,7 +113,13 @@ void BackupStoreDirectory::Dump(void *clibFileHandle, bool ToTrace) // Output item int16_t f = (*i)->GetFlags(); - OutputLine(file, ToTrace, "%06llx %4lld %016llx %4d %3d %4d%s%s%s%s%s%s\n", +#ifdef WIN32 + OutputLine(file, ToTrace, + "%06I64x %4I64d %016I64x %4d %3d %4d%s%s%s%s%s%s\n", +#else + OutputLine(file, ToTrace, + "%06llx %4lld %016llx %4d %3d %4d%s%s%s%s%s%s\n", +#endif (*i)->GetObjectID(), (*i)->GetSizeInBlocks(), (*i)->GetAttributesHash(), -- cgit v1.2.3 From 04302de443ce25e6cda606bd15c173270ddcf783 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 31 Aug 2006 22:11:50 +0000 Subject: * lib/backupclient/BackupClientFileAttributes.cpp - Revert to trunk --- lib/backupclient/BackupClientFileAttributes.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientFileAttributes.cpp b/lib/backupclient/BackupClientFileAttributes.cpp index ace72cf8..974db3c9 100644 --- a/lib/backupclient/BackupClientFileAttributes.cpp +++ b/lib/backupclient/BackupClientFileAttributes.cpp @@ -642,7 +642,6 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename) const } // If working as root, set user IDs - #ifndef WIN32 if(::geteuid() == 0) { #ifndef HAVE_LCHOWN @@ -662,7 +661,6 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename) const } #endif } - #endif if(static_cast(xattrOffset+sizeof(u_int32_t))<=mpClearAttributes->GetSize()) { -- cgit v1.2.3 From 0ed31fe9c03c894be162974e3c7139f5c0f7f040 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 31 Aug 2006 22:14:22 +0000 Subject: * lib/backupclient/BackupClientFileAttributes.cpp Don't call geteuid() on Win32, since it's emulated, always returns 0, and I want to remove it entirely (refs #3) --- lib/backupclient/BackupClientFileAttributes.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientFileAttributes.cpp b/lib/backupclient/BackupClientFileAttributes.cpp index 974db3c9..49bae665 100644 --- a/lib/backupclient/BackupClientFileAttributes.cpp +++ b/lib/backupclient/BackupClientFileAttributes.cpp @@ -642,7 +642,11 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename) const } // If working as root, set user IDs + #ifdef WIN32 + if(0) + #else if(::geteuid() == 0) + #endif { #ifndef HAVE_LCHOWN // only if not a link, can't set their owner on this platform -- cgit v1.2.3 From 6737cc23c9b9cd71060b06f41283dca9549898ef Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 31 Aug 2006 22:15:09 +0000 Subject: * lib/backupclient/BackupStoreFile.cpp - Revert to trunk --- lib/backupclient/BackupStoreFile.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupStoreFile.cpp b/lib/backupclient/BackupStoreFile.cpp index 278bf50a..f5a55207 100644 --- a/lib/backupclient/BackupStoreFile.cpp +++ b/lib/backupclient/BackupStoreFile.cpp @@ -289,8 +289,6 @@ void BackupStoreFile::DecodeFile(IOStream &rEncodedFile, const char *DecodedFile // Copy it out to the file stream->CopyStreamTo(out); } - - out.Close(); // Write the attributes stream->GetAttributes().WriteAttributes(DecodedFilename); -- cgit v1.2.3 From 3a30b42c228ae481bd95a4363c853f477573b20d Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 31 Aug 2006 22:16:17 +0000 Subject: * lib/backupclient/BackupStoreFile.cpp Close file before trying to apply attributes to it. Otherwise, when we close it the timestamp will be updated on Win32 (refs #3) --- lib/backupclient/BackupStoreFile.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupStoreFile.cpp b/lib/backupclient/BackupStoreFile.cpp index f5a55207..278bf50a 100644 --- a/lib/backupclient/BackupStoreFile.cpp +++ b/lib/backupclient/BackupStoreFile.cpp @@ -289,6 +289,8 @@ void BackupStoreFile::DecodeFile(IOStream &rEncodedFile, const char *DecodedFile // Copy it out to the file stream->CopyStreamTo(out); } + + out.Close(); // Write the attributes stream->GetAttributes().WriteAttributes(DecodedFilename); -- cgit v1.2.3 From c3e3f974e26957a674729f761e27534c0db2b9d0 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 31 Aug 2006 22:17:12 +0000 Subject: * lib/backupclient/BackupStoreObjectDump.cpp - Revert to trunk --- lib/backupclient/BackupStoreObjectDump.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupStoreObjectDump.cpp b/lib/backupclient/BackupStoreObjectDump.cpp index d3d9cc17..b4ccc731 100644 --- a/lib/backupclient/BackupStoreObjectDump.cpp +++ b/lib/backupclient/BackupStoreObjectDump.cpp @@ -113,13 +113,7 @@ void BackupStoreDirectory::Dump(void *clibFileHandle, bool ToTrace) // Output item int16_t f = (*i)->GetFlags(); -#ifdef WIN32 - OutputLine(file, ToTrace, - "%06I64x %4I64d %016I64x %4d %3d %4d%s%s%s%s%s%s\n", -#else - OutputLine(file, ToTrace, - "%06llx %4lld %016llx %4d %3d %4d%s%s%s%s%s%s\n", -#endif + OutputLine(file, ToTrace, "%06llx %4lld %016llx %4d %3d %4d%s%s%s%s%s%s\n", (*i)->GetObjectID(), (*i)->GetSizeInBlocks(), (*i)->GetAttributesHash(), -- cgit v1.2.3 From 76f120d7ec171c3e0b88bc1fe317a4b0dacf19a5 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 31 Aug 2006 22:18:02 +0000 Subject: * lib/backupclient/BackupStoreObjectDump.cpp Fix format strings on Win32 (refs #3) --- lib/backupclient/BackupStoreObjectDump.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupStoreObjectDump.cpp b/lib/backupclient/BackupStoreObjectDump.cpp index b4ccc731..d3d9cc17 100644 --- a/lib/backupclient/BackupStoreObjectDump.cpp +++ b/lib/backupclient/BackupStoreObjectDump.cpp @@ -113,7 +113,13 @@ void BackupStoreDirectory::Dump(void *clibFileHandle, bool ToTrace) // Output item int16_t f = (*i)->GetFlags(); - OutputLine(file, ToTrace, "%06llx %4lld %016llx %4d %3d %4d%s%s%s%s%s%s\n", +#ifdef WIN32 + OutputLine(file, ToTrace, + "%06I64x %4I64d %016I64x %4d %3d %4d%s%s%s%s%s%s\n", +#else + OutputLine(file, ToTrace, + "%06llx %4lld %016llx %4d %3d %4d%s%s%s%s%s%s\n", +#endif (*i)->GetObjectID(), (*i)->GetSizeInBlocks(), (*i)->GetAttributesHash(), -- cgit v1.2.3 From f95f7bc1616c954043e3e5b06e2dac1f0530b5ad Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 16 Oct 2006 23:12:24 +0000 Subject: Remove #ifdefs around geteuid(), re-enable use of fake version under Win32 as requested by Ben. Restore serialised AttrModificationTime under Win32 by passing to emu_utimes(). (refs #3) --- lib/backupclient/BackupClientFileAttributes.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientFileAttributes.cpp b/lib/backupclient/BackupClientFileAttributes.cpp index 49bae665..ba65d57a 100644 --- a/lib/backupclient/BackupClientFileAttributes.cpp +++ b/lib/backupclient/BackupClientFileAttributes.cpp @@ -642,11 +642,7 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename) const } // If working as root, set user IDs - #ifdef WIN32 - if(0) - #else if(::geteuid() == 0) - #endif { #ifndef HAVE_LCHOWN // only if not a link, can't set their owner on this platform @@ -683,10 +679,24 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename) const { // Work out times as timevals struct timeval times[2]; + + #ifdef WIN32 + BoxTimeToTimeval(box_ntoh64(pattr->ModificationTime), + times[1]); + BoxTimeToTimeval(box_ntoh64(pattr->AttrModificationTime), + times[0]); + // Because stat() returns the creation time in the ctime + // field under Windows, and this gets saved in the + // AttrModificationTime field of the serialised attributes, + // we subvert the first parameter of emu_utimes() to allow + // it to be reset to the right value on the restored file. + #else BoxTimeToTimeval(modtime, times[1]); // Copy access time as well, why not, got to set it to something times[0] = times[1]; - // Attr modification time will be changed anyway, nothing that can be done about it + // Attr modification time will be changed anyway, + // nothing that can be done about it + #endif // Try to apply if(::utimes(Filename, times) != 0) -- cgit v1.2.3 From 3a9d95bd011a8a5a39f0ad9aaaf682a926cfeccf Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 16 Oct 2006 23:13:00 +0000 Subject: Delete existing entries to allow reuse of a BackupStoreDirectory object. (refs #3) --- lib/backupclient/BackupStoreDirectory.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupStoreDirectory.cpp b/lib/backupclient/BackupStoreDirectory.cpp index 61e6461d..0d06da34 100644 --- a/lib/backupclient/BackupStoreDirectory.cpp +++ b/lib/backupclient/BackupStoreDirectory.cpp @@ -149,6 +149,11 @@ void BackupStoreDirectory::ReadFromStream(IOStream &rStream, int Timeout) int count = ntohl(hdr.mNumEntries); // Clear existing list + for(std::vector::iterator i = mEntries.begin(); + i != mEntries.end(); i++) + { + delete (*i); + } mEntries.clear(); // Read them in! -- cgit v1.2.3 From 29da720afeebbb7c618355a588a1e36a7620c9a6 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 16 Oct 2006 23:13:30 +0000 Subject: Add new return codes from BackupClientRestore for use on Win32. (refs #3) --- lib/backupclient/BackupClientRestore.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientRestore.h b/lib/backupclient/BackupClientRestore.h index 4b382771..f7724030 100644 --- a/lib/backupclient/BackupClientRestore.h +++ b/lib/backupclient/BackupClientRestore.h @@ -16,7 +16,9 @@ enum { Restore_Complete = 0, Restore_ResumePossible = 1, - Restore_TargetExists = 2 + Restore_TargetExists = 2, + Restore_TargetPathNotFound = 3, + Restore_UnknownError = 4, }; int BackupClientRestore(BackupProtocolClient &rConnection, int64_t DirectoryID, const char *LocalDirectoryName, -- cgit v1.2.3 From ca0c40ce216de416cd8ada05ab369c2971ee4a71 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 14 Nov 2006 05:12:03 +0000 Subject: Add ExtendedLogFile option to bbackupd config (refs #9) --- lib/backupclient/BackupDaemonConfigVerify.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupDaemonConfigVerify.cpp b/lib/backupclient/BackupDaemonConfigVerify.cpp index 89ad4d54..34167227 100644 --- a/lib/backupclient/BackupDaemonConfigVerify.cpp +++ b/lib/backupclient/BackupDaemonConfigVerify.cpp @@ -81,7 +81,8 @@ static const ConfigurationVerifyKey verifyrootkeys[] = {"FileTrackingSizeThreshold", 0, ConfigTest_Exists | ConfigTest_IsInt, 0}, {"DiffingUploadSizeThreshold", 0, ConfigTest_Exists | ConfigTest_IsInt, 0}, {"StoreHostname", 0, ConfigTest_Exists, 0}, - {"ExtendedLogging", "no", ConfigTest_IsBool, 0}, // make value "yes" to enable in config file + {"ExtendedLogging", "no", ConfigTest_IsBool, 0}, // extended log to syslog + {"ExtendedLogFile", NULL, 0, 0}, // extended log to a file {"CommandSocket", 0, 0, 0}, // not compulsory to have this {"KeepAliveTime", 0, ConfigTest_IsInt, 0}, // optional -- cgit v1.2.3 From 0acac971b2c2ed7ef04e64152d63cbbe2a4c66b1 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 28 Nov 2006 20:34:57 +0000 Subject: Replace old-style setitimers for KeepAliveTime and MaximumDiffingTime with new Timer objects. (refs #3, refs #9) --- lib/backupclient/BackupStoreFile.h | 6 +-- lib/backupclient/BackupStoreFileDiff.cpp | 74 +++++++++----------------------- 2 files changed, 24 insertions(+), 56 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupStoreFile.h b/lib/backupclient/BackupStoreFile.h index 437b4232..784320b6 100644 --- a/lib/backupclient/BackupStoreFile.h +++ b/lib/backupclient/BackupStoreFile.h @@ -51,16 +51,16 @@ public: virtual ~DiffTimer(); public: virtual void DoKeepAlive() = 0; - virtual time_t GetTimeMgmtEpoch() = 0; virtual int GetMaximumDiffingTime() = 0; - virtual int GetKeepaliveTime() = 0; + virtual int GetKeepAliveTime() = 0; + virtual bool IsManaged() = 0; }; // -------------------------------------------------------------------------- // // Class // Name: BackupStoreFile -// Purpose: Class to hold together utils for maniplating files. +// Purpose: Class to hold together utils for manipulating files. // Created: 2003/08/28 // // -------------------------------------------------------------------------- diff --git a/lib/backupclient/BackupStoreFileDiff.cpp b/lib/backupclient/BackupStoreFileDiff.cpp index ee09f1c8..d04cda6c 100644 --- a/lib/backupclient/BackupStoreFileDiff.cpp +++ b/lib/backupclient/BackupStoreFileDiff.cpp @@ -29,6 +29,7 @@ #include "RollingChecksum.h" #include "MD5Digest.h" #include "CommonException.h" +#include "Timer.h" #include "MemLeakFindOn.h" @@ -52,31 +53,6 @@ static bool SecondStageMatch(BlocksAvailableEntry *pFirstInHashList, RollingChec BlocksAvailableEntry *pIndex, std::map &rFoundBlocks); static void GenerateRecipe(BackupStoreFileEncodeStream::Recipe &rRecipe, BlocksAvailableEntry *pIndex, int64_t NumBlocks, std::map &rFoundBlocks, int64_t SizeOfInputFile); -// sDiffTimerExpired flags when the diff timer has expired. When true, the -// diff routine should check the wall clock as soon as possible, to determine -// whether it's time for a keepalive to be sent, or whether the diff has been -// running for too long and should be terminated. -static bool sDiffTimerExpired = false; - - -// -------------------------------------------------------------------------- -// -// Function -// Name: BackupStoreFile::DiffTimerExpired() -// Purpose: Notifies BackupStoreFile object that the diff operation -// timer has expired, which may mean that a keepalive should -// be sent, or the diff should be terminated. Called from an -// external timer, so it should not do more than set a flag. -// -// Created: 19/1/06 -// -// -------------------------------------------------------------------------- -void BackupStoreFile::DiffTimerExpired() -{ - sDiffTimerExpired = true; -} - - // -------------------------------------------------------------------------- // // Function @@ -483,15 +459,13 @@ static void SearchForMatchingBlocks(IOStream &rFile, std::map BlocksAvailableEntry *pIndex, int64_t NumBlocks, int32_t Sizes[BACKUP_FILE_DIFF_MAX_BLOCK_SIZES], DiffTimer *pDiffTimer) { - time_t TimeMgmtEpoch = 0; - int MaximumDiffingTime = 0; - int KeepAliveTime = 0; + Timer maximumDiffingTime(0); + Timer keepAliveTime(0); - if (pDiffTimer) + if (pDiffTimer && pDiffTimer->IsManaged()) { - TimeMgmtEpoch = pDiffTimer->GetTimeMgmtEpoch(); - MaximumDiffingTime = pDiffTimer->GetMaximumDiffingTime(); - KeepAliveTime = pDiffTimer->GetKeepaliveTime(); + maximumDiffingTime = Timer(pDiffTimer->GetMaximumDiffingTime()); + keepAliveTime = Timer(pDiffTimer->GetKeepAliveTime()); } std::map goodnessOfFit; @@ -577,29 +551,23 @@ static void SearchForMatchingBlocks(IOStream &rFile, std::map int rollOverInitialBytes = 0; while(true) { - if(sDiffTimerExpired) + if(maximumDiffingTime.HasExpired()) { - ASSERT(TimeMgmtEpoch > 0); ASSERT(pDiffTimer != NULL); - - time_t tTotalRunIntvl = time(NULL) - TimeMgmtEpoch; - - if(MaximumDiffingTime > 0 && - tTotalRunIntvl >= MaximumDiffingTime) - { - TRACE0("MaximumDiffingTime reached - " - "suspending file diff\n"); - abortSearch = true; - break; - } - else if(KeepAliveTime > 0) - { - TRACE0("KeepAliveTime reached - " - "initiating keep-alive\n"); - pDiffTimer->DoKeepAlive(); - } - - sDiffTimerExpired = false; + TRACE0("MaximumDiffingTime reached - " + "suspending file diff\n"); + abortSearch = true; + break; + } + + if(keepAliveTime.HasExpired()) + { + ASSERT(pDiffTimer != NULL); + TRACE0("KeepAliveTime reached - " + "initiating keep-alive\n"); + pDiffTimer->DoKeepAlive(); + keepAliveTime = Timer( + pDiffTimer->GetKeepAliveTime()); } // Load in another block of data, and record how big it is -- cgit v1.2.3 From e0a80f0da840849a5cdb38bcfea7a7e240a2aa2d Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 3 Dec 2006 10:40:26 +0000 Subject: Moved KeepAlive timer to BackupClientContext object. Made timeout initialisation non-static, and a property of the context object. (perhaps should be in rParams, I know). (refs #3, refs #9) --- lib/backupclient/BackupStoreFile.h | 7 +++---- lib/backupclient/BackupStoreFileDiff.cpp | 13 +++---------- 2 files changed, 6 insertions(+), 14 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupStoreFile.h b/lib/backupclient/BackupStoreFile.h index 784320b6..3ee5ddb0 100644 --- a/lib/backupclient/BackupStoreFile.h +++ b/lib/backupclient/BackupStoreFile.h @@ -50,10 +50,9 @@ public: DiffTimer(); virtual ~DiffTimer(); public: - virtual void DoKeepAlive() = 0; - virtual int GetMaximumDiffingTime() = 0; - virtual int GetKeepAliveTime() = 0; - virtual bool IsManaged() = 0; + virtual void DoKeepAlive() = 0; + virtual int GetMaximumDiffingTime() = 0; + virtual bool IsManaged() = 0; }; // -------------------------------------------------------------------------- diff --git a/lib/backupclient/BackupStoreFileDiff.cpp b/lib/backupclient/BackupStoreFileDiff.cpp index d04cda6c..3a3f1a5e 100644 --- a/lib/backupclient/BackupStoreFileDiff.cpp +++ b/lib/backupclient/BackupStoreFileDiff.cpp @@ -460,12 +460,10 @@ static void SearchForMatchingBlocks(IOStream &rFile, std::map int32_t Sizes[BACKUP_FILE_DIFF_MAX_BLOCK_SIZES], DiffTimer *pDiffTimer) { Timer maximumDiffingTime(0); - Timer keepAliveTime(0); - if (pDiffTimer && pDiffTimer->IsManaged()) + if(pDiffTimer && pDiffTimer->IsManaged()) { maximumDiffingTime = Timer(pDiffTimer->GetMaximumDiffingTime()); - keepAliveTime = Timer(pDiffTimer->GetKeepAliveTime()); } std::map goodnessOfFit; @@ -560,16 +558,11 @@ static void SearchForMatchingBlocks(IOStream &rFile, std::map break; } - if(keepAliveTime.HasExpired()) + if(pDiffTimer) { - ASSERT(pDiffTimer != NULL); - TRACE0("KeepAliveTime reached - " - "initiating keep-alive\n"); pDiffTimer->DoKeepAlive(); - keepAliveTime = Timer( - pDiffTimer->GetKeepAliveTime()); } - + // Load in another block of data, and record how big it is int bytesInEndings = rFile.Read(endings, Sizes[s]); int tmp; -- cgit v1.2.3 From 4201fdff12c3aea7d65b17ee2a0319c81fc41799 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 11 Jan 2007 22:47:35 +0000 Subject: Added a new config option, LogAllFileAccess, which will log access to every file and scanning every directory. The current implementation is taken straight from the Boxi branch. To be extended shortly. (refs #3) --- lib/backupclient/BackupDaemonConfigVerify.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupDaemonConfigVerify.cpp b/lib/backupclient/BackupDaemonConfigVerify.cpp index 34167227..9000ec6d 100644 --- a/lib/backupclient/BackupDaemonConfigVerify.cpp +++ b/lib/backupclient/BackupDaemonConfigVerify.cpp @@ -83,6 +83,7 @@ static const ConfigurationVerifyKey verifyrootkeys[] = {"StoreHostname", 0, ConfigTest_Exists, 0}, {"ExtendedLogging", "no", ConfigTest_IsBool, 0}, // extended log to syslog {"ExtendedLogFile", NULL, 0, 0}, // extended log to a file + {"LogAllFileAccess", "no", ConfigTest_IsBool, 0}, {"CommandSocket", 0, 0, 0}, // not compulsory to have this {"KeepAliveTime", 0, ConfigTest_IsInt, 0}, // optional -- cgit v1.2.3 From b01211dc4b77264d9042f9a3d6223710953d24dd Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 13 Jan 2007 01:01:27 +0000 Subject: Fix spelling (refs #3) --- lib/backupclient/BackupClientRestore.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index fbb4ee47..b752b6a2 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -254,7 +254,8 @@ static void BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Di break; } - // Fetch the directory listing from the server -- getting a list of files which is approparite to the restore type + // Fetch the directory listing from the server -- getting a list + // of files which is appropriate to the restore type rConnection.QueryListDirectory( DirectoryID, Params.RestoreDeleted?(BackupProtocolClientListDirectory::Flags_Deleted):(BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING), -- cgit v1.2.3 From 6779d3cb4ffcc9fa7d860a6f4abaa5bed009098c Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 9 Feb 2007 22:30:15 +0000 Subject: Catch errors during restore (refs #3) --- lib/backupclient/BackupClientRestore.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index b752b6a2..65ee377c 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "BackupClientRestore.h" #include "autogen_BackupProtocolClient.h" @@ -225,9 +226,36 @@ static void BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Di // Save the resumption information Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename); + + // Create the local directory, if not already done. + // Path and owner set later, just use restrictive owner mode. + + int exists; + + try + { + exists = ObjectExists(rLocalDirectoryName.c_str()); + } + catch (BoxException &e) + { + ::syslog(LOG_ERR, "Failed to check existence for %s: %s", + rLocalDirectoryName.c_str(), e.what()); + return Restore_UnknownError; + } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Failed to check existence for %s: %s", + rLocalDirectoryName.c_str(), e.what()); + return Restore_UnknownError; + } + catch(...) + { + ::syslog(LOG_ERR, "Failed to check existence for %s: " + "unknown error", rLocalDirectoryName.c_str()); + return Restore_UnknownError; + } - // Create the local directory (if not already done) -- path and owner set later, just use restrictive owner mode - switch(ObjectExists(rLocalDirectoryName.c_str())) + switch(exists) { case ObjectExists_Dir: // Do nothing -- cgit v1.2.3 From 57a36f04af1ae81cec83ab706cdfd76ff445c664 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 9 Feb 2007 22:34:21 +0000 Subject: Check whether the restore target parent directory exists before trying to create the target directory or save restore info in the parent (refs #3) --- lib/backupclient/BackupClientRestore.cpp | 101 ++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 8 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index 65ee377c..9c1a5346 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -224,9 +224,6 @@ static void BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Di rLevel.RemoveLevel(); } - // Save the resumption information - Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename); - // Create the local directory, if not already done. // Path and owner set later, just use restrictive owner mode. @@ -270,17 +267,105 @@ static void BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Di } TRACE1("In restore, directory name collision with file %s", rLocalDirectoryName.c_str()); } - // follow through to... (no break) + break; case ObjectExists_NoObject: - if(::mkdir(rLocalDirectoryName.c_str(), S_IRWXU) != 0) - { - THROW_EXCEPTION(CommonException, OSFileError); - } + // we'll create it in a second, after checking + // whether the parent directory exists break; default: ASSERT(false); break; } + + std::string parentDirectoryName(rLocalDirectoryName); + if(parentDirectoryName[parentDirectoryName.size() - 1] == + DIRECTORY_SEPARATOR_ASCHAR) + { + parentDirectoryName.resize(parentDirectoryName.size() - 1); + } + + int lastSlash = parentDirectoryName.rfind(DIRECTORY_SEPARATOR_ASCHAR); + + if(lastSlash == std::string::npos) + { + // might be a forward slash separator, + // especially in the unit tests! + lastSlash = parentDirectoryName.rfind('/'); + } + + if(lastSlash != std::string::npos) + { + // the target directory is a deep path, remove the last + // directory name and check that the resulting parent + // exists, otherwise the restore should fail. + parentDirectoryName.resize(lastSlash); + + int parentExists; + + try + { + parentExists = ObjectExists(parentDirectoryName.c_str()); + } + catch (BoxException &e) + { + ::syslog(LOG_ERR, "Failed to check existence for %s: " + "%s", parentDirectoryName.c_str(), e.what()); + return Restore_UnknownError; + } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Failed to check existence for %s: " + "%s", parentDirectoryName.c_str(), e.what()); + return Restore_UnknownError; + } + catch(...) + { + ::syslog(LOG_ERR, "Failed to check existence for %s: " + "unknown error", parentDirectoryName.c_str()); + return Restore_UnknownError; + } + + switch(parentExists) + { + case ObjectExists_Dir: + // this is fine, do nothing + break; + + case ObjectExists_File: + fprintf(stderr, "Failed to restore: '%s' " + "is a file, but should be a " + "directory.\n", + parentDirectoryName.c_str()); + return Restore_TargetPathNotFound; + + case ObjectExists_NoObject: + fprintf(stderr, "Failed to restore: " + "parent '%s' of target directory " + "does not exist.\n", + parentDirectoryName.c_str()); + return Restore_TargetPathNotFound; + + default: + fprintf(stderr, "Failed to restore: " + "unknown result from " + "ObjectExists('%s').\n", + parentDirectoryName.c_str()); + return Restore_UnknownError; + } + } + + if((exists == ObjectExists_NoObject || + exists == ObjectExists_File) && + ::mkdir(rLocalDirectoryName.c_str(), S_IRWXU) != 0) + { + ::syslog(LOG_ERR, "Failed to create directory %s: %s", + rLocalDirectoryName.c_str(), + strerror(errno)); + return Restore_UnknownError; + } + + // Save the resumption information + Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename); // Fetch the directory listing from the server -- getting a list // of files which is appropriate to the restore type -- cgit v1.2.3 From 786da28ab1f04a2386c9545f106ad0dd1ec65af5 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 9 Feb 2007 22:35:56 +0000 Subject: Make BackupClientRestoreDir return a result code compatible with BackupClientRestore (refs #3) --- lib/backupclient/BackupClientRestore.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index 9c1a5346..019c53dd 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -207,7 +207,7 @@ typedef struct // Created: 23/11/03 // // -------------------------------------------------------------------------- -static void BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t DirectoryID, std::string &rLocalDirectoryName, +static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t DirectoryID, std::string &rLocalDirectoryName, RestoreParams &Params, RestoreResumeInfo &rLevel) { // If we're resuming... check that we haven't got a next level to look at @@ -478,7 +478,14 @@ static void BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Di RestoreResumeInfo &rnextLevel(rLevel.AddLevel(en->GetObjectID(), nm.GetClearFilename())); // Recurse - BackupClientRestoreDir(rConnection, en->GetObjectID(), localDirname, Params, rnextLevel); + int result = BackupClientRestoreDir( + rConnection, en->GetObjectID(), + localDirname, Params, rnextLevel); + + if (result != Restore_Complete) + { + return result; + } // Remove the level for the above call rLevel.RemoveLevel(); @@ -487,7 +494,9 @@ static void BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Di rLevel.mRestoredObjects.insert(en->GetObjectID()); } } - } + } + + return Restore_Complete; } @@ -558,7 +567,12 @@ int BackupClientRestore(BackupProtocolClient &rConnection, int64_t DirectoryID, // Restore the directory std::string localName(LocalDirectoryName); - BackupClientRestoreDir(rConnection, DirectoryID, localName, params, params.mResumeInfo); + int result = BackupClientRestoreDir(rConnection, DirectoryID, + localName, params, params.mResumeInfo); + if (result != Restore_Complete) + { + return result; + } // Undelete the directory on the server? if(RestoreDeleted && UndeleteAfterRestoreDeleted) -- cgit v1.2.3 From 270bdff4312add7816e095d06adf7b58f13fb28b Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 9 Feb 2007 22:36:18 +0000 Subject: Spelling fix (refs #3) --- lib/backupclient/BackupClientRestore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index 019c53dd..baf33002 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -461,7 +461,7 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir } - // Recuse to directories + // Recurse to directories { BackupStoreDirectory::Iterator i(dir); BackupStoreDirectory::Entry *en = 0; -- cgit v1.2.3 From 9341f476c713f44d471083b7f67e31dcd93eb1dd Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 9 Feb 2007 22:51:04 +0000 Subject: Don't throw an exception if we fail to delete a file in the way of restore, just log the error and return an error code (refs #3) --- lib/backupclient/BackupClientRestore.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index baf33002..194c50ad 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -263,7 +263,11 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir ::printf("WARNING: File present with name '%s', removing out of the way of restored directory. Use specific restore with ID to restore this object.", rLocalDirectoryName.c_str()); if(::unlink(rLocalDirectoryName.c_str()) != 0) { - THROW_EXCEPTION(CommonException, OSFileError); + ::syslog(LOG_ERR, "Failed to delete " + "directory %s: %s", + rLocalDirectoryName.c_str(), + strerror(errno)); + return Restore_UnknownError; } TRACE1("In restore, directory name collision with file %s", rLocalDirectoryName.c_str()); } -- cgit v1.2.3 From a80d8dd666cb0476ac4b9c60ad8b5ad991c25a9d Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 9 Feb 2007 23:06:53 +0000 Subject: Catch exceptions while writing files, attributes, resume info and checking file existence (refs #3) --- lib/backupclient/BackupClientRestore.cpp | 192 ++++++++++++++++++++++++++++--- 1 file changed, 174 insertions(+), 18 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index 194c50ad..8f29f8ba 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -367,12 +367,34 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir strerror(errno)); return Restore_UnknownError; } - - // Save the resumption information - Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename); - - // Fetch the directory listing from the server -- getting a list - // of files which is appropriate to the restore type + + // Save the restore info, in case it's needed later + try + { + Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename); + } + catch (BoxException &e) + { + ::syslog(LOG_ERR, "Failed to save resume info file %s: %s", + Params.mRestoreResumeInfoFilename.c_str(), e.what()); + return Restore_UnknownError; + } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Failed to save resume info file %s: %s", + Params.mRestoreResumeInfoFilename.c_str(), e.what()); + return Restore_UnknownError; + } + catch(...) + { + ::syslog(LOG_ERR, "Failed to save resume info file %s: " + "unknown error", + Params.mRestoreResumeInfoFilename.c_str()); + return Restore_UnknownError; + } + + // Fetch the directory listing from the server -- getting a + // list of files which is appropriate to the restore type rConnection.QueryListDirectory( DirectoryID, Params.RestoreDeleted?(BackupProtocolClientListDirectory::Flags_Deleted):(BackupProtocolClientListDirectory::Flags_INCLUDE_EVERYTHING), @@ -387,7 +409,29 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir // Apply attributes to the directory const StreamableMemBlock &dirAttrBlock(dir.GetAttributes()); BackupClientFileAttributes dirAttr(dirAttrBlock); - dirAttr.WriteAttributes(rLocalDirectoryName.c_str()); + + try + { + dirAttr.WriteAttributes(rLocalDirectoryName.c_str()); + } + catch (BoxException &e) + { + ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s", + rLocalDirectoryName.c_str(), e.what()); + return Restore_UnknownError; + } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s", + rLocalDirectoryName.c_str(), e.what()); + return Restore_UnknownError; + } + catch(...) + { + ::syslog(LOG_ERR, "Failed to restore attributes for %s: " + "unknown error", rLocalDirectoryName.c_str()); + return Restore_UnknownError; + } int64_t bytesWrittenSinceLastRestoreInfoSave = 0; @@ -415,17 +459,43 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir // Decode the file -- need to do different things depending on whether // the directory entry has additional attributes - if(en->HasAttributes()) + try { - // Use these attributes - const StreamableMemBlock &storeAttr(en->GetAttributes()); - BackupClientFileAttributes attr(storeAttr); - BackupStoreFile::DecodeFile(*objectStream, localFilename.c_str(), rConnection.GetTimeout(), &attr); + if(en->HasAttributes()) + { + // Use these attributes + const StreamableMemBlock &storeAttr(en->GetAttributes()); + BackupClientFileAttributes attr(storeAttr); + BackupStoreFile::DecodeFile(*objectStream, localFilename.c_str(), rConnection.GetTimeout(), &attr); + } + else + { + // Use attributes stored in file + BackupStoreFile::DecodeFile(*objectStream, localFilename.c_str(), rConnection.GetTimeout()); + } + } + catch (BoxException &e) + { + ::syslog(LOG_ERR, "Failed to restore " + "file %s: %s", + localFilename.c_str(), + e.what()); + return Restore_UnknownError; } - else + catch(std::exception &e) { - // Use attributes stored in file - BackupStoreFile::DecodeFile(*objectStream, localFilename.c_str(), rConnection.GetTimeout()); + ::syslog(LOG_ERR, "Failed to restore " + "file %s: %s", + localFilename.c_str(), + e.what()); + return Restore_UnknownError; + } + catch(...) + { + ::syslog(LOG_ERR, "Failed to restore " + "file %s: unknown error", + localFilename.c_str()); + return Restore_UnknownError; } // Progress display? @@ -440,7 +510,42 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir // Save restore info? int64_t fileSize; - if(FileExists(localFilename.c_str(), &fileSize, true /* treat links as not existing */)) + int exists; + + try + { + exists = FileExists( + localFilename.c_str(), + &fileSize, + true /* treat links as not + existing */); + } + catch (BoxException &e) + { + ::syslog(LOG_ERR, "Failed to determine " + "whether file exists: %s: %s", + localFilename.c_str(), + e.what()); + return Restore_UnknownError; + } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Failed to determine " + "whether file exists: %s: %s", + localFilename.c_str(), + e.what()); + return Restore_UnknownError; + } + catch(...) + { + ::syslog(LOG_ERR, "Failed to determine " + "whether file exists: %s: " + "unknown error", + localFilename.c_str()); + return Restore_UnknownError; + } + + if(exists) { // File exists... bytesWrittenSinceLastRestoreInfoSave += fileSize; @@ -448,7 +553,30 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir if(bytesWrittenSinceLastRestoreInfoSave > MAX_BYTES_WRITTEN_BETWEEN_RESTORE_INFO_SAVES) { // Save the restore info, in case it's needed later - Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename); + try + { + Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename); + } + catch (BoxException &e) + { + ::syslog(LOG_ERR, "Failed to save resume info file %s: %s", + Params.mRestoreResumeInfoFilename.c_str(), e.what()); + return Restore_UnknownError; + } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Failed to save resume info file %s: %s", + Params.mRestoreResumeInfoFilename.c_str(), e.what()); + return Restore_UnknownError; + } + catch(...) + { + ::syslog(LOG_ERR, "Failed to save resume info file %s: " + "unknown error", + Params.mRestoreResumeInfoFilename.c_str()); + return Restore_UnknownError; + } + bytesWrittenSinceLastRestoreInfoSave = 0; } } @@ -460,7 +588,35 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir if(bytesWrittenSinceLastRestoreInfoSave != 0) { // Save the restore info, in case it's needed later - Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename); + try + { + Params.mResumeInfo.Save( + Params.mRestoreResumeInfoFilename); + } + catch (BoxException &e) + { + ::syslog(LOG_ERR, "Failed to save resume info file " + "%s: %s", + Params.mRestoreResumeInfoFilename.c_str(), + e.what()); + return Restore_UnknownError; + } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Failed to save resume info file " + "%s: %s", + Params.mRestoreResumeInfoFilename.c_str(), + e.what()); + return Restore_UnknownError; + } + catch(...) + { + ::syslog(LOG_ERR, "Failed to save resume info file " + "%s: unknown error", + Params.mRestoreResumeInfoFilename.c_str()); + return Restore_UnknownError; + } + bytesWrittenSinceLastRestoreInfoSave = 0; } -- cgit v1.2.3 From e429add69506b45e73123990f38667551acbe3ec Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 9 Feb 2007 23:10:25 +0000 Subject: Log failure to delete files and directories (refs #3) --- lib/backupclient/BackupClientRestore.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index 8f29f8ba..e7fdd5fa 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -264,7 +264,7 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir if(::unlink(rLocalDirectoryName.c_str()) != 0) { ::syslog(LOG_ERR, "Failed to delete " - "directory %s: %s", + "file %s: %s", rLocalDirectoryName.c_str(), strerror(errno)); return Restore_UnknownError; @@ -449,7 +449,14 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir std::string localFilename(rLocalDirectoryName + DIRECTORY_SEPARATOR_ASCHAR + nm.GetClearFilename()); // Unlink anything which already exists -- for resuming restores, we can't overwrite files already there. - ::unlink(localFilename.c_str()); + if(::unlink(localFilename.c_str()) == 0) + { + ::syslog(LOG_ERR, "Failed to delete " + "file %s: %s", + localFilename.c_str(), + strerror(errno)); + return Restore_UnknownError; + } // Request it from the store rConnection.QueryGetFile(DirectoryID, en->GetObjectID()); -- cgit v1.2.3 From 4106a7dd54f442a009cadbf5a9ee1bf823d70b32 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 9 Feb 2007 23:10:47 +0000 Subject: Fix compile warning --- lib/backupclient/BackupClientRestore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index e7fdd5fa..ec4ca681 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -288,7 +288,7 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir parentDirectoryName.resize(parentDirectoryName.size() - 1); } - int lastSlash = parentDirectoryName.rfind(DIRECTORY_SEPARATOR_ASCHAR); + size_t lastSlash = parentDirectoryName.rfind(DIRECTORY_SEPARATOR_ASCHAR); if(lastSlash == std::string::npos) { -- cgit v1.2.3 From e9f3450fb12f26b20ae06816a01fb9f78c613857 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 24 Mar 2007 22:56:13 +0000 Subject: Use logging framework to reduce noise for those who don't want it (refs #3, merges [1439] [1440] [1443]) --- lib/backupclient/BackupStoreFile.cpp | 6 +++--- lib/backupclient/BackupStoreFilenameClear.cpp | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupStoreFile.cpp b/lib/backupclient/BackupStoreFile.cpp index 278bf50a..5c621f38 100644 --- a/lib/backupclient/BackupStoreFile.cpp +++ b/lib/backupclient/BackupStoreFile.cpp @@ -46,6 +46,7 @@ #include "ReadGatherStream.h" #include "Random.h" #include "BackupStoreFileEncodeStream.h" +#include "Logging.h" #include "MemLeakFindOn.h" @@ -1485,9 +1486,8 @@ void BackupStoreFile::EncodingBuffer::Allocate(int Size) // -------------------------------------------------------------------------- void BackupStoreFile::EncodingBuffer::Reallocate(int NewSize) { -#ifndef WIN32 - TRACE2("Reallocating EncodingBuffer from %d to %d\n", mBufferSize, NewSize); -#endif + BOX_TRACE("Reallocating EncodingBuffer from " << mBufferSize << + " to " << NewSize); ASSERT(mpBuffer != 0); uint8_t *buffer = (uint8_t*)BackupStoreFile::CodingChunkAlloc(NewSize); if(buffer == 0) diff --git a/lib/backupclient/BackupStoreFilenameClear.cpp b/lib/backupclient/BackupStoreFilenameClear.cpp index c415b9bb..9114fdd1 100644 --- a/lib/backupclient/BackupStoreFilenameClear.cpp +++ b/lib/backupclient/BackupStoreFilenameClear.cpp @@ -13,6 +13,7 @@ #include "CipherContext.h" #include "CipherBlowfish.h" #include "Guards.h" +#include "Logging.h" #include "MemLeakFindOn.h" @@ -203,9 +204,9 @@ static void EnsureEncDecBufferSize(int BufSize) { if(sEncDecBufferSize < BufSize) { -#ifndef WIN32 - TRACE2("Reallocating filename encoding/decoding buffer from %d to %d\n", sEncDecBufferSize, BufSize); -#endif + BOX_TRACE("Reallocating filename encoding/decoding " + "buffer from " << sEncDecBufferSize << + " to " << BufSize); spEncDecBuffer->Resize(BufSize); sEncDecBufferSize = BufSize; MEMLEAKFINDER_NOT_A_LEAK(*spEncDecBuffer); -- cgit v1.2.3 From 41b16f3b27f87d2f84e59387e78644c05756e307 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 28 Apr 2007 17:31:38 +0000 Subject: Use ReadLoggingStream to log progress of file uploads. (refs #3) --- lib/backupclient/BackupStoreFileEncodeStream.cpp | 17 ++++++++++++++--- lib/backupclient/BackupStoreFileEncodeStream.h | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupStoreFileEncodeStream.cpp b/lib/backupclient/BackupStoreFileEncodeStream.cpp index c692f18e..cda18855 100644 --- a/lib/backupclient/BackupStoreFileEncodeStream.cpp +++ b/lib/backupclient/BackupStoreFileEncodeStream.cpp @@ -38,6 +38,7 @@ using namespace BackupStoreFileCryptVar; BackupStoreFileEncodeStream::BackupStoreFileEncodeStream() : mpRecipe(0), mpFile(0), + mpLogging(0), mStatus(Status_Header), mSendData(true), mTotalBlocks(0), @@ -79,6 +80,13 @@ BackupStoreFileEncodeStream::~BackupStoreFileEncodeStream() mpFile = 0; } + // Clear up logging stream + if(mpLogging) + { + delete mpLogging; + mpLogging = 0; + } + // Free the recipe if(mpRecipe != 0) { @@ -199,6 +207,9 @@ void BackupStoreFileEncodeStream::Setup(const char *Filename, BackupStoreFileEnc { // Open the file mpFile = new FileStream(Filename); + + // Create logging stream + mpLogging = new ReadLoggingStream(*mpFile); // Work out the largest possible block required for the encoded data mAllocatedBufferSize = BackupStoreFile::MaxBlockSizeForChunkSize(maxBlockClearSize); @@ -474,7 +485,7 @@ void BackupStoreFileEncodeStream::SkipPreviousBlocksInInstruction() } // Move forward in the stream - mpFile->Seek(sizeToSkip, IOStream::SeekType_Relative); + mpLogging->Seek(sizeToSkip, IOStream::SeekType_Relative); } @@ -518,14 +529,14 @@ void BackupStoreFileEncodeStream::EncodeCurrentBlock() ASSERT(blockRawSize < mAllocatedBufferSize); // Check file open - if(mpFile == 0) + if(mpFile == 0 || mpLogging == 0) { // File should be open, but isn't. So logical error. THROW_EXCEPTION(BackupStoreException, Internal) } // Read the data in - if(!mpFile->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 diff --git a/lib/backupclient/BackupStoreFileEncodeStream.h b/lib/backupclient/BackupStoreFileEncodeStream.h index 1c748798..fb5d0851 100644 --- a/lib/backupclient/BackupStoreFileEncodeStream.h +++ b/lib/backupclient/BackupStoreFileEncodeStream.h @@ -17,6 +17,7 @@ #include "CollectInBufferStream.h" #include "MD5Digest.h" #include "BackupStoreFile.h" +#include "ReadLoggingStream.h" namespace BackupStoreFileCreation { @@ -100,6 +101,7 @@ private: Recipe *mpRecipe; IOStream *mpFile; // source file CollectInBufferStream mData; // buffer for header and index entries + ReadLoggingStream *mpLogging; 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 -- cgit v1.2.3 From 4f98aedc41c41afa7ed0388ec838b96829d0577f Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 28 Apr 2007 19:57:24 +0000 Subject: Fix getting files with uncertain size (over 2GB) from the store. Failure to drain the stream will leave the EOF byte in it, which breaks further communications with the store over the same connection. (refs #2, refs #3) --- lib/backupclient/BackupStoreFile.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupStoreFile.cpp b/lib/backupclient/BackupStoreFile.cpp index 5c621f38..5e800970 100644 --- a/lib/backupclient/BackupStoreFile.cpp +++ b/lib/backupclient/BackupStoreFile.cpp @@ -292,6 +292,14 @@ void BackupStoreFile::DecodeFile(IOStream &rEncodedFile, const char *DecodedFile } out.Close(); + + // The stream might have uncertain size, in which case + // we need to drain it to get the + // Protocol::ProtocolStreamHeader_EndOfStream byte + // out of our connection stream. + char buffer[1]; + int drained = rEncodedFile.Read(buffer, 1); + ASSERT(drained == 0); // Write the attributes stream->GetAttributes().WriteAttributes(DecodedFilename); -- cgit v1.2.3 From 5939cfae21c84cc587bec541808ae121a3536737 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 28 Apr 2007 20:42:45 +0000 Subject: Fix bbackupd choosing an invalid (too large) block size for large files (over 2GB) which will cause compare to fail: when rBlockSizeOut == BACKUP_FILE_MAX_BLOCK_SIZE we would have proceeded around the loop one more time and doubled the block size again. (refs #2, refs #3) --- lib/backupclient/BackupStoreFileEncodeStream.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupStoreFileEncodeStream.cpp b/lib/backupclient/BackupStoreFileEncodeStream.cpp index cda18855..423c11a3 100644 --- a/lib/backupclient/BackupStoreFileEncodeStream.cpp +++ b/lib/backupclient/BackupStoreFileEncodeStream.cpp @@ -278,7 +278,7 @@ void BackupStoreFileEncodeStream::CalculateBlockSizes(int64_t DataSize, int64_t rNumBlocksOut = (DataSize + rBlockSizeOut - 1) / rBlockSizeOut; - } while(rBlockSizeOut <= BACKUP_FILE_MAX_BLOCK_SIZE && rNumBlocksOut > BACKUP_FILE_INCREASE_BLOCK_SIZE_AFTER); + } while(rBlockSizeOut < BACKUP_FILE_MAX_BLOCK_SIZE && rNumBlocksOut > BACKUP_FILE_INCREASE_BLOCK_SIZE_AFTER); // Last block size rLastBlockSizeOut = DataSize - ((rNumBlocksOut - 1) * rBlockSizeOut); -- cgit v1.2.3 From 9ddebaa7d9534fae58cc9cca6f8fdd5139bccf69 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 29 Apr 2007 13:46:22 +0000 Subject: Make directories user-writable while restoring them, so that restoring read-only directories as a non-root user doesn't crash. Restore the correct permissions after restoring the directory's contents. (refs #3) --- lib/backupclient/BackupClientFileAttributes.cpp | 10 ++++++++-- lib/backupclient/BackupClientFileAttributes.h | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientFileAttributes.cpp b/lib/backupclient/BackupClientFileAttributes.cpp index ba65d57a..9918c0d6 100644 --- a/lib/backupclient/BackupClientFileAttributes.cpp +++ b/lib/backupclient/BackupClientFileAttributes.cpp @@ -578,7 +578,8 @@ void BackupClientFileAttributes::FillExtendedAttr(StreamableMemBlock &outputBloc // Created: 2003/10/07 // // -------------------------------------------------------------------------- -void BackupClientFileAttributes::WriteAttributes(const char *Filename) const +void BackupClientFileAttributes::WriteAttributes(const char *Filename, + bool MakeUserWritable) const { // Got something loaded if(GetSize() <= 0) @@ -704,7 +705,12 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename) const THROW_EXCEPTION(CommonException, OSFileError) } } - + + if (MakeUserWritable) + { + mode |= S_IRWXU; + } + // Apply everything else... (allowable mode flags only) if(::chmod(Filename, mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX)) != 0) // mode must be done last (think setuid) { diff --git a/lib/backupclient/BackupClientFileAttributes.h b/lib/backupclient/BackupClientFileAttributes.h index 62ba2184..fa56ff65 100644 --- a/lib/backupclient/BackupClientFileAttributes.h +++ b/lib/backupclient/BackupClientFileAttributes.h @@ -45,7 +45,8 @@ public: void ReadAttributes(const char *Filename, bool ZeroModificationTimes = false, box_time_t *pModTime = 0, box_time_t *pAttrModTime = 0, int64_t *pFileSize = 0, InodeRefType *pInodeNumber = 0, bool *pHasMultipleLinks = 0); - void WriteAttributes(const char *Filename) const; + void WriteAttributes(const char *Filename, + bool MakeUserWritable = false) const; bool IsSymLink() const; -- cgit v1.2.3 From 649214baa3166aec940f17a8f93dd234111f2044 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 29 Apr 2007 13:47:03 +0000 Subject: Make directories user-writable while restoring them, so that restoring read-only directories as a non-root user doesn't crash. Restore the correct permissions after restoring the directory's contents. (refs #3) --- lib/backupclient/BackupClientRestore.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index ec4ca681..0b2b6d84 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -412,7 +412,7 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir try { - dirAttr.WriteAttributes(rLocalDirectoryName.c_str()); + dirAttr.WriteAttributes(rLocalDirectoryName.c_str(), true); } catch (BoxException &e) { @@ -591,6 +591,7 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir } } + // Make sure the restore info has been saved if(bytesWrittenSinceLastRestoreInfoSave != 0) { @@ -663,6 +664,30 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir } } + // now remove the user writable flag, if we added it earlier + try + { + dirAttr.WriteAttributes(rLocalDirectoryName.c_str(), false); + } + catch (BoxException &e) + { + ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s", + rLocalDirectoryName.c_str(), e.what()); + return Restore_UnknownError; + } + catch(std::exception &e) + { + ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s", + rLocalDirectoryName.c_str(), e.what()); + return Restore_UnknownError; + } + catch(...) + { + ::syslog(LOG_ERR, "Failed to restore attributes for %s: " + "unknown error", rLocalDirectoryName.c_str()); + return Restore_UnknownError; + } + return Restore_Complete; } -- cgit v1.2.3 From 1e0c90956567752044545f3ef4876415da9e9700 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 29 Apr 2007 13:47:48 +0000 Subject: Remove unwanted blank line. (refs #3) --- lib/backupclient/BackupClientRestore.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index 0b2b6d84..834bfb9a 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -591,7 +591,6 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir } } - // Make sure the restore info has been saved if(bytesWrittenSinceLastRestoreInfoSave != 0) { -- cgit v1.2.3 From 6d029275a46a9408a797b197c6f31d48c470b065 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 29 Apr 2007 13:48:55 +0000 Subject: Remove assertion that we are at the end of the stream when decoding finishes. This is not true when decoding raw files on disk. (refs #3) --- lib/backupclient/BackupStoreFile.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupStoreFile.cpp b/lib/backupclient/BackupStoreFile.cpp index 5e800970..75095fa4 100644 --- a/lib/backupclient/BackupStoreFile.cpp +++ b/lib/backupclient/BackupStoreFile.cpp @@ -299,7 +299,13 @@ void BackupStoreFile::DecodeFile(IOStream &rEncodedFile, const char *DecodedFile // out of our connection stream. char buffer[1]; int drained = rEncodedFile.Read(buffer, 1); - ASSERT(drained == 0); + + // The Read will return 0 if we are actually at the end + // of the stream, but some tests decode files directly, + // in which case we are actually positioned at the start + // of the block index. I hope that reading an extra byte + // doesn't hurt! + // ASSERT(drained == 0); // Write the attributes stream->GetAttributes().WriteAttributes(DecodedFilename); -- cgit v1.2.3 From 18b71f8cbbdf85907a9e204b9e9f2d056ac43419 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 26 Jul 2007 21:56:06 +0000 Subject: Experimental fix for restore problem reported by Mikael Syska: query > restore Admin "c:\admin\" Failed to read file information: The parameter is incorrect. (87) Failed to get file information for 'c:' Failed to check existence for c:: Common OSFileError (Error accessing a file. Check permissions.) ERROR: Unknown restore result. (refs #3, merges [1659]) --- lib/backupclient/BackupClientRestore.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index 834bfb9a..028c1659 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -304,6 +304,15 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir // exists, otherwise the restore should fail. parentDirectoryName.resize(lastSlash); + #ifdef WIN32 + // if the path is a drive letter, then we need to + // add a a backslash to query the root directory. + if (lastSlash == 2 && parentDirectoryName[1] == ':') + { + parentDirectoryName += '\\'; + } + #endif + int parentExists; try -- cgit v1.2.3 From a436702cdf84264e1176548a4dd0f78f8eeb123a Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 26 Jul 2007 21:58:40 +0000 Subject: Fix restoring to top-level directories (e.g. c:\test) (refs #3, merges [1661]) --- lib/backupclient/BackupClientRestore.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index 028c1659..9b3a3edc 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -311,6 +311,10 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir { parentDirectoryName += '\\'; } + else if (lastSlash == 0) + { + parentDirectoryName += '\\'; + } #endif int parentExists; -- cgit v1.2.3 From 0b2fd98dd63c533e00c0d61ce022f37ee75857cc Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 31 Jul 2007 23:18:05 +0000 Subject: Replace almost all calls to syslog() with logging framework. (refs #3) --- lib/backupclient/BackupClientFileAttributes.cpp | 13 +- lib/backupclient/BackupClientRestore.cpp | 184 +++++++++--------------- lib/backupclient/BackupStoreFile.cpp | 7 +- 3 files changed, 75 insertions(+), 129 deletions(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientFileAttributes.cpp b/lib/backupclient/BackupClientFileAttributes.cpp index 9918c0d6..925d1620 100644 --- a/lib/backupclient/BackupClientFileAttributes.cpp +++ b/lib/backupclient/BackupClientFileAttributes.cpp @@ -344,8 +344,8 @@ void BackupClientFileAttributes::ReadAttributes(const char *Filename, bool ZeroM // to be true (still aborts), but it can at least hold 2^32. if (winTime >= 0x100000000LL || _gmtime64(&winTime) == 0) { - ::syslog(LOG_ERR, "Invalid Modification Time " - "caught for file: %s", Filename); + BOX_ERROR("Invalid Modification Time caught for " + "file: '" << Filename << "'"); pattr->ModificationTime = 0; } @@ -355,8 +355,8 @@ void BackupClientFileAttributes::ReadAttributes(const char *Filename, bool ZeroM if (winTime > 0x100000000LL || _gmtime64(&winTime) == 0) { - ::syslog(LOG_ERR, "Invalid Attribute Modification " - "Time caught for file: %s", Filename); + BOX_ERROR("Invalid Attribute Modification Time " + "caught for file: '" << Filename << "'"); pattr->AttrModificationTime = 0; } #endif @@ -627,9 +627,8 @@ void BackupClientFileAttributes::WriteAttributes(const char *Filename, } #ifdef WIN32 - ::syslog(LOG_WARNING, - "Cannot create symbolic links on Windows: %s", - Filename); + BOX_WARNING("Cannot create symbolic links on Windows: '" << + Filename << "'"); #else // Make a symlink, first deleting anything in the way ::unlink(Filename); diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index 9b3a3edc..92853624 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -235,20 +235,20 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir } catch (BoxException &e) { - ::syslog(LOG_ERR, "Failed to check existence for %s: %s", - rLocalDirectoryName.c_str(), e.what()); + BOX_ERROR("Failed to check existence for " << + rLocalDirectoryName << ": " << e.what()); return Restore_UnknownError; } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to check existence for %s: %s", - rLocalDirectoryName.c_str(), e.what()); + BOX_ERROR("Failed to check existence for " << + rLocalDirectoryName << ": " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to check existence for %s: " - "unknown error", rLocalDirectoryName.c_str()); + BOX_ERROR("Failed to check existence for " << + rLocalDirectoryName << ": unknown error"); return Restore_UnknownError; } @@ -263,13 +263,14 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir ::printf("WARNING: File present with name '%s', removing out of the way of restored directory. Use specific restore with ID to restore this object.", rLocalDirectoryName.c_str()); if(::unlink(rLocalDirectoryName.c_str()) != 0) { - ::syslog(LOG_ERR, "Failed to delete " - "file %s: %s", - rLocalDirectoryName.c_str(), + BOX_ERROR("Failed to delete file " << + rLocalDirectoryName << ": " << strerror(errno)); return Restore_UnknownError; } - TRACE1("In restore, directory name collision with file %s", rLocalDirectoryName.c_str()); + BOX_TRACE("In restore, directory name " + "collision with file " << + rLocalDirectoryName); } break; case ObjectExists_NoObject: @@ -325,20 +326,20 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir } catch (BoxException &e) { - ::syslog(LOG_ERR, "Failed to check existence for %s: " - "%s", parentDirectoryName.c_str(), e.what()); + BOX_ERROR("Failed to check existence for " << + parentDirectoryName << ": " << e.what()); return Restore_UnknownError; } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to check existence for %s: " - "%s", parentDirectoryName.c_str(), e.what()); + BOX_ERROR("Failed to check existence for " << + parentDirectoryName << ": " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to check existence for %s: " - "unknown error", parentDirectoryName.c_str()); + BOX_ERROR("Failed to check existence for " << + parentDirectoryName << ": unknown error"); return Restore_UnknownError; } @@ -349,24 +350,22 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir break; case ObjectExists_File: - fprintf(stderr, "Failed to restore: '%s' " + BOX_ERROR("Failed to restore: '" << + parentDirectoryName << "' " "is a file, but should be a " - "directory.\n", - parentDirectoryName.c_str()); + "directory."); return Restore_TargetPathNotFound; case ObjectExists_NoObject: - fprintf(stderr, "Failed to restore: " - "parent '%s' of target directory " - "does not exist.\n", - parentDirectoryName.c_str()); + BOX_ERROR("Failed to restore: parent '" << + parentDirectoryName << "' of target " + "directory does not exist."); return Restore_TargetPathNotFound; default: - fprintf(stderr, "Failed to restore: " - "unknown result from " - "ObjectExists('%s').\n", - parentDirectoryName.c_str()); + BOX_ERROR("Failed to restore: unknown " + "result from ObjectExists('" << + parentDirectoryName << "')"); return Restore_UnknownError; } } @@ -375,8 +374,8 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir exists == ObjectExists_File) && ::mkdir(rLocalDirectoryName.c_str(), S_IRWXU) != 0) { - ::syslog(LOG_ERR, "Failed to create directory %s: %s", - rLocalDirectoryName.c_str(), + BOX_ERROR("Failed to create directory '" << + rLocalDirectoryName << "': " << strerror(errno)); return Restore_UnknownError; } @@ -386,23 +385,18 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir { Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename); } - catch (BoxException &e) - { - ::syslog(LOG_ERR, "Failed to save resume info file %s: %s", - Params.mRestoreResumeInfoFilename.c_str(), e.what()); - return Restore_UnknownError; - } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to save resume info file %s: %s", - Params.mRestoreResumeInfoFilename.c_str(), e.what()); + BOX_ERROR("Failed to save resume info file '" << + Params.mRestoreResumeInfoFilename << "': " << + e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to save resume info file %s: " - "unknown error", - Params.mRestoreResumeInfoFilename.c_str()); + BOX_ERROR("Failed to save resume info file '" << + Params.mRestoreResumeInfoFilename << + "': unknown error"); return Restore_UnknownError; } @@ -427,22 +421,16 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir { dirAttr.WriteAttributes(rLocalDirectoryName.c_str(), true); } - catch (BoxException &e) - { - ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s", - rLocalDirectoryName.c_str(), e.what()); - return Restore_UnknownError; - } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s", - rLocalDirectoryName.c_str(), e.what()); + BOX_ERROR("Failed to restore attributes for '" << + rLocalDirectoryName << "': " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to restore attributes for %s: " - "unknown error", rLocalDirectoryName.c_str()); + BOX_ERROR("Failed to restore attributes for '" << + rLocalDirectoryName << "': unknown error"); return Restore_UnknownError; } @@ -464,9 +452,8 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir // Unlink anything which already exists -- for resuming restores, we can't overwrite files already there. if(::unlink(localFilename.c_str()) == 0) { - ::syslog(LOG_ERR, "Failed to delete " - "file %s: %s", - localFilename.c_str(), + BOX_ERROR("Failed to delete file '" << + localFilename << "': " << strerror(errno)); return Restore_UnknownError; } @@ -494,27 +481,18 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir BackupStoreFile::DecodeFile(*objectStream, localFilename.c_str(), rConnection.GetTimeout()); } } - catch (BoxException &e) - { - ::syslog(LOG_ERR, "Failed to restore " - "file %s: %s", - localFilename.c_str(), - e.what()); - return Restore_UnknownError; - } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to restore " - "file %s: %s", - localFilename.c_str(), + BOX_ERROR("Failed to restore file '" << + localFilename << "': " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to restore " - "file %s: unknown error", - localFilename.c_str()); + BOX_ERROR("Failed to restore file '" << + localFilename << + "': unknown error"); return Restore_UnknownError; } @@ -540,28 +518,20 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir true /* treat links as not existing */); } - catch (BoxException &e) - { - ::syslog(LOG_ERR, "Failed to determine " - "whether file exists: %s: %s", - localFilename.c_str(), - e.what()); - return Restore_UnknownError; - } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to determine " - "whether file exists: %s: %s", - localFilename.c_str(), + BOX_ERROR("Failed to determine " + "whether file exists: '" << + localFilename << "': " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to determine " - "whether file exists: %s: " - "unknown error", - localFilename.c_str()); + BOX_ERROR("Failed to determine " + "whether file exists: '" << + localFilename << "': " + "unknown error"); return Restore_UnknownError; } @@ -577,23 +547,18 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir { Params.mResumeInfo.Save(Params.mRestoreResumeInfoFilename); } - catch (BoxException &e) - { - ::syslog(LOG_ERR, "Failed to save resume info file %s: %s", - Params.mRestoreResumeInfoFilename.c_str(), e.what()); - return Restore_UnknownError; - } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to save resume info file %s: %s", - Params.mRestoreResumeInfoFilename.c_str(), e.what()); + BOX_ERROR("Failed to save resume info file '" << + Params.mRestoreResumeInfoFilename << + "': " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to save resume info file %s: " - "unknown error", - Params.mRestoreResumeInfoFilename.c_str()); + BOX_ERROR("Failed to save resume info file '" << + Params.mRestoreResumeInfoFilename << + "': unknown error"); return Restore_UnknownError; } @@ -613,27 +578,18 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir Params.mResumeInfo.Save( Params.mRestoreResumeInfoFilename); } - catch (BoxException &e) - { - ::syslog(LOG_ERR, "Failed to save resume info file " - "%s: %s", - Params.mRestoreResumeInfoFilename.c_str(), - e.what()); - return Restore_UnknownError; - } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to save resume info file " - "%s: %s", - Params.mRestoreResumeInfoFilename.c_str(), + BOX_ERROR("Failed to save resume info file '" << + Params.mRestoreResumeInfoFilename << "': " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to save resume info file " - "%s: unknown error", - Params.mRestoreResumeInfoFilename.c_str()); + BOX_ERROR("Failed to save resume info file '" << + Params.mRestoreResumeInfoFilename << + "': unknown error"); return Restore_UnknownError; } @@ -681,22 +637,16 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir { dirAttr.WriteAttributes(rLocalDirectoryName.c_str(), false); } - catch (BoxException &e) - { - ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s", - rLocalDirectoryName.c_str(), e.what()); - return Restore_UnknownError; - } catch(std::exception &e) { - ::syslog(LOG_ERR, "Failed to restore attributes for %s: %s", - rLocalDirectoryName.c_str(), e.what()); + BOX_ERROR("Failed to restore attributes for '" << + rLocalDirectoryName << "': " << e.what()); return Restore_UnknownError; } catch(...) { - ::syslog(LOG_ERR, "Failed to restore attributes for %s: " - "unknown error", rLocalDirectoryName.c_str()); + BOX_ERROR("Failed to restore attributes for '" << + rLocalDirectoryName << "': unknown error"); return Restore_UnknownError; } diff --git a/lib/backupclient/BackupStoreFile.cpp b/lib/backupclient/BackupStoreFile.cpp index 75095fa4..7e93d59d 100644 --- a/lib/backupclient/BackupStoreFile.cpp +++ b/lib/backupclient/BackupStoreFile.cpp @@ -17,10 +17,8 @@ #include #include #include + #ifndef BOX_DISABLE_BACKWARDS_COMPATIBILITY_BACKUPSTOREFILE - #ifndef WIN32 - #include - #endif #include #endif @@ -758,8 +756,7 @@ int BackupStoreFile::DecodedStream::Read(void *pBuffer, int NBytes, int Timeout) // Warn and log this issue if(!sWarnedAboutBackwardsCompatiblity) { - ::printf("WARNING: Decoded one or more files using backwards compatibility mode for block index.\n"); - ::syslog(LOG_ERR, "WARNING: Decoded one or more files using backwards compatibility mode for block index.\n"); + BOX_WARNING("WARNING: Decoded one or more files using backwards compatibility mode for block index."); sWarnedAboutBackwardsCompatiblity = true; } } -- cgit v1.2.3 From 747589f03a1ba61273d21ed6446ad47841a1f46a Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 2 Aug 2007 23:28:17 +0000 Subject: Convert most printf() and fprintf() calls to use logging framework instead. (refs #3) --- lib/backupclient/BackupClientRestore.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/backupclient') diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index 92853624..3c03c87c 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -260,7 +260,11 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir case ObjectExists_File: { // File exists with this name, which is fun. Get rid of it. - ::printf("WARNING: File present with name '%s', removing out of the way of restored directory. Use specific restore with ID to restore this object.", rLocalDirectoryName.c_str()); + BOX_WARNING("File present with name '" << + rLocalDirectoryName << "', removing " << + "out of the way of restored directory. " + "Use specific restore with ID to " + "restore this object."); if(::unlink(rLocalDirectoryName.c_str()) != 0) { BOX_ERROR("Failed to delete file " << -- cgit v1.2.3