diff options
Diffstat (limited to 'lib/common')
-rw-r--r-- | lib/common/BannerText.h | 2 | ||||
-rw-r--r-- | lib/common/Box.h | 43 | ||||
-rw-r--r-- | lib/common/BoxPlatform.h | 8 | ||||
-rw-r--r-- | lib/common/BoxPortsAndFiles.h.in | 1 | ||||
-rw-r--r-- | lib/common/FileModificationTime.cpp | 64 | ||||
-rw-r--r-- | lib/common/FileModificationTime.h | 48 | ||||
-rw-r--r-- | lib/common/FileStream.cpp | 15 | ||||
-rw-r--r-- | lib/common/FileStream.h | 8 | ||||
-rw-r--r-- | lib/common/InvisibleTempFileStream.cpp | 4 | ||||
-rw-r--r-- | lib/common/Logging.cpp | 23 | ||||
-rw-r--r-- | lib/common/Logging.h | 46 | ||||
-rw-r--r-- | lib/common/Makefile.extra | 4 | ||||
-rw-r--r-- | lib/common/NamedLock.cpp | 9 | ||||
-rw-r--r-- | lib/common/NamedLock.h | 2 | ||||
-rw-r--r-- | lib/common/Test.cpp | 24 | ||||
-rw-r--r-- | lib/common/Test.h | 15 | ||||
-rw-r--r-- | lib/common/Utils.cpp | 12 | ||||
-rw-r--r-- | lib/common/Utils.h | 5 |
18 files changed, 226 insertions, 107 deletions
diff --git a/lib/common/BannerText.h b/lib/common/BannerText.h index c25ac433..e40224da 100644 --- a/lib/common/BannerText.h +++ b/lib/common/BannerText.h @@ -12,7 +12,7 @@ #define BANNER_TEXT(UtilityName) \ "Box " UtilityName " v" BOX_VERSION ", (c) Ben Summers and " \ - "contributors 2003-2008" + "contributors 2003-2010" #endif // BANNERTEXT__H diff --git a/lib/common/Box.h b/lib/common/Box.h index 1124a062..158fab7b 100644 --- a/lib/common/Box.h +++ b/lib/common/Box.h @@ -103,19 +103,28 @@ #define THROW_EXCEPTION(type, subtype) \ { \ - OPTIONAL_DO_BACKTRACE \ - BOX_WARNING("Exception thrown: " #type "(" #subtype ") " \ - "at " __FILE__ "(" << __LINE__ << ")") \ + if(!HideExceptionMessageGuard::ExceptionsHidden()) \ + { \ + OPTIONAL_DO_BACKTRACE \ + BOX_WARNING("Exception thrown: " \ + #type "(" #subtype ") " \ + "at " __FILE__ "(" << __LINE__ << ")") \ + } \ throw type(type::subtype); \ } #define THROW_EXCEPTION_MESSAGE(type, subtype, message) \ { \ - OPTIONAL_DO_BACKTRACE \ - BOX_WARNING("Exception thrown: " #type "(" #subtype ") " \ - " (" message ") at " \ - __FILE__ "(" << __LINE__ << ")") \ - throw type(type::subtype, message); \ + std::ostringstream _box_throw_line; \ + _box_throw_line << message; \ + if(!HideExceptionMessageGuard::ExceptionsHidden()) \ + { \ + OPTIONAL_DO_BACKTRACE \ + BOX_WARNING("Exception thrown: " \ + #type "(" #subtype ") (" << message << \ + ") at " __FILE__ "(" << __LINE__ << ")") \ + } \ + throw type(type::subtype, _box_throw_line.str()); \ } // extra macros for converting to network byte order @@ -154,5 +163,23 @@ inline uint64_t box_swap64(uint64_t x) #define box_ntoh64(x) box_swap64(x) #endif +// overloaded auto-conversion functions +inline uint64_t hton(uint64_t in) { return box_hton64(in); } +inline uint32_t hton(uint32_t in) { return htonl(in); } +inline uint16_t hton(uint16_t in) { return htons(in); } +inline uint8_t hton(uint8_t in) { return in; } +inline int64_t hton(int64_t in) { return box_hton64(in); } +inline int32_t hton(int32_t in) { return htonl(in); } +inline int16_t hton(int16_t in) { return htons(in); } +inline int8_t hton(int8_t in) { return in; } +inline uint64_t ntoh(uint64_t in) { return box_ntoh64(in); } +inline uint32_t ntoh(uint32_t in) { return ntohl(in); } +inline uint16_t ntoh(uint16_t in) { return ntohs(in); } +inline uint8_t ntoh(uint8_t in) { return in; } +inline int64_t ntoh(int64_t in) { return box_ntoh64(in); } +inline int32_t ntoh(int32_t in) { return ntohl(in); } +inline int16_t ntoh(int16_t in) { return ntohs(in); } +inline int8_t ntoh(int8_t in) { return in; } + #endif // BOX__H diff --git a/lib/common/BoxPlatform.h b/lib/common/BoxPlatform.h index c625a7c7..617aa031 100644 --- a/lib/common/BoxPlatform.h +++ b/lib/common/BoxPlatform.h @@ -176,6 +176,14 @@ #include "emu.h" +#ifdef WIN32 + #define INVALID_FILE INVALID_HANDLE_VALUE + typedef HANDLE tOSFileHandle; +#else + #define INVALID_FILE -1 + typedef int tOSFileHandle; +#endif + // Solaris has no dirfd(x) macro or function, and we need one for // intercept tests. We cannot define macros with arguments directly // using AC_DEFINE, so do it here instead of in configure.ac. diff --git a/lib/common/BoxPortsAndFiles.h.in b/lib/common/BoxPortsAndFiles.h.in index e30dcf90..41bad0ba 100644 --- a/lib/common/BoxPortsAndFiles.h.in +++ b/lib/common/BoxPortsAndFiles.h.in @@ -15,6 +15,7 @@ // Backup store daemon #define BOX_PORT_BBSTORED (BOX_PORT_BASE+1) +#define BOX_PORT_BBSTORED_TEST 22011 // directory within the RAIDFILE root for the backup store daemon #define BOX_RAIDFILE_ROOT_BBSTORED "backup" diff --git a/lib/common/FileModificationTime.cpp b/lib/common/FileModificationTime.cpp new file mode 100644 index 00000000..1109b15f --- /dev/null +++ b/lib/common/FileModificationTime.cpp @@ -0,0 +1,64 @@ +// -------------------------------------------------------------------------- +// +// File +// Name: FileModificationTime.cpp +// Purpose: Function for getting file modification time. +// Created: 2010/02/15 +// +// -------------------------------------------------------------------------- + +#include "Box.h" + +#include <sys/stat.h> + +#include "BoxTime.h" +#include "FileModificationTime.h" + +#include "MemLeakFindOn.h" + +box_time_t FileModificationTime(EMU_STRUCT_STAT &st) +{ +#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC + box_time_t datamodified = ((int64_t)st.st_mtime) * (MICRO_SEC_IN_SEC_LL); +#else + box_time_t datamodified = (((int64_t)st.st_mtimespec.tv_nsec) / NANO_SEC_IN_USEC_LL) + + (((int64_t)st.st_mtimespec.tv_sec) * (MICRO_SEC_IN_SEC_LL)); +#endif + + return datamodified; +} + +box_time_t FileAttrModificationTime(EMU_STRUCT_STAT &st) +{ + box_time_t statusmodified = +#ifdef HAVE_STRUCT_STAT_ST_MTIMESPEC + (((int64_t)st.st_ctimespec.tv_nsec) / (NANO_SEC_IN_USEC_LL)) + + (((int64_t)st.st_ctimespec.tv_sec) * (MICRO_SEC_IN_SEC_LL)); +#elif defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC + (((int64_t)st.st_ctim.tv_nsec) / (NANO_SEC_IN_USEC_LL)) + + (((int64_t)st.st_ctim.tv_sec) * (MICRO_SEC_IN_SEC_LL)); +#elif defined HAVE_STRUCT_STAT_ST_ATIMENSEC + (((int64_t)st.st_ctimensec) / (NANO_SEC_IN_USEC_LL)) + + (((int64_t)st.st_ctime) * (MICRO_SEC_IN_SEC_LL)); +#else // no nanoseconds anywhere + (((int64_t)st.st_ctime) * (MICRO_SEC_IN_SEC_LL)); +#endif + + return statusmodified; +} + +box_time_t FileModificationTimeMaxModAndAttr(EMU_STRUCT_STAT &st) +{ +#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC + box_time_t datamodified = ((int64_t)st.st_mtime) * (MICRO_SEC_IN_SEC_LL); + box_time_t statusmodified = ((int64_t)st.st_ctime) * (MICRO_SEC_IN_SEC_LL); +#else + box_time_t datamodified = (((int64_t)st.st_mtimespec.tv_nsec) / NANO_SEC_IN_USEC_LL) + + (((int64_t)st.st_mtimespec.tv_sec) * (MICRO_SEC_IN_SEC_LL)); + box_time_t statusmodified = (((int64_t)st.st_ctimespec.tv_nsec) / NANO_SEC_IN_USEC_LL) + + (((int64_t)st.st_ctimespec.tv_sec) * (MICRO_SEC_IN_SEC_LL)); +#endif + + return (datamodified > statusmodified)?datamodified:statusmodified; +} + diff --git a/lib/common/FileModificationTime.h b/lib/common/FileModificationTime.h index 5f13c015..e6e6c172 100644 --- a/lib/common/FileModificationTime.h +++ b/lib/common/FileModificationTime.h @@ -14,51 +14,9 @@ #include "BoxTime.h" -inline box_time_t FileModificationTime(EMU_STRUCT_STAT &st) -{ -#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC - box_time_t datamodified = ((int64_t)st.st_mtime) * (MICRO_SEC_IN_SEC_LL); -#else - box_time_t datamodified = (((int64_t)st.st_mtimespec.tv_nsec) / NANO_SEC_IN_USEC_LL) - + (((int64_t)st.st_mtimespec.tv_sec) * (MICRO_SEC_IN_SEC_LL)); -#endif - - return datamodified; -} - -inline box_time_t FileAttrModificationTime(EMU_STRUCT_STAT &st) -{ - box_time_t statusmodified = -#ifdef HAVE_STRUCT_STAT_ST_MTIMESPEC - (((int64_t)st.st_ctimespec.tv_nsec) / (NANO_SEC_IN_USEC_LL)) + - (((int64_t)st.st_ctimespec.tv_sec) * (MICRO_SEC_IN_SEC_LL)); -#elif defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC - (((int64_t)st.st_ctim.tv_nsec) / (NANO_SEC_IN_USEC_LL)) + - (((int64_t)st.st_ctim.tv_sec) * (MICRO_SEC_IN_SEC_LL)); -#elif defined HAVE_STRUCT_STAT_ST_ATIMENSEC - (((int64_t)st.st_ctimensec) / (NANO_SEC_IN_USEC_LL)) + - (((int64_t)st.st_ctime) * (MICRO_SEC_IN_SEC_LL)); -#else // no nanoseconds anywhere - (((int64_t)st.st_ctime) * (MICRO_SEC_IN_SEC_LL)); -#endif - - return statusmodified; -} - -inline box_time_t FileModificationTimeMaxModAndAttr(EMU_STRUCT_STAT &st) -{ -#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC - box_time_t datamodified = ((int64_t)st.st_mtime) * (MICRO_SEC_IN_SEC_LL); - box_time_t statusmodified = ((int64_t)st.st_ctime) * (MICRO_SEC_IN_SEC_LL); -#else - box_time_t datamodified = (((int64_t)st.st_mtimespec.tv_nsec) / NANO_SEC_IN_USEC_LL) - + (((int64_t)st.st_mtimespec.tv_sec) * (MICRO_SEC_IN_SEC_LL)); - box_time_t statusmodified = (((int64_t)st.st_ctimespec.tv_nsec) / NANO_SEC_IN_USEC_LL) - + (((int64_t)st.st_ctimespec.tv_sec) * (MICRO_SEC_IN_SEC_LL)); -#endif - - return (datamodified > statusmodified)?datamodified:statusmodified; -} +box_time_t FileModificationTime(EMU_STRUCT_STAT &st); +box_time_t FileAttrModificationTime(EMU_STRUCT_STAT &st); +box_time_t FileModificationTimeMaxModAndAttr(EMU_STRUCT_STAT &st); #endif // FILEMODIFICATIONTIME__H diff --git a/lib/common/FileStream.cpp b/lib/common/FileStream.cpp index d6a3c5da..5be8237c 100644 --- a/lib/common/FileStream.cpp +++ b/lib/common/FileStream.cpp @@ -67,19 +67,20 @@ void FileStream::AfterOpen() { MEMLEAKFINDER_NOT_A_LEAK(this); + #ifdef WIN32 + BOX_LOG_WIN_WARNING_NUMBER("Failed to open file: " << + mFileName, winerrno); + #else + BOX_LOG_SYS_WARNING("Failed to open file: " << + mFileName); + #endif + if(errno == EACCES) { THROW_EXCEPTION(CommonException, AccessDenied) } else { - #ifdef WIN32 - BOX_LOG_WIN_WARNING_NUMBER("Failed to open file: " << - mFileName, winerrno); - #else - BOX_LOG_SYS_WARNING("Failed to open file: " << - mFileName); - #endif THROW_EXCEPTION(CommonException, OSFileOpenError) } } diff --git a/lib/common/FileStream.h b/lib/common/FileStream.h index 7c4118cd..9101a968 100644 --- a/lib/common/FileStream.h +++ b/lib/common/FileStream.h @@ -20,14 +20,6 @@ #include <unistd.h> #endif -#ifdef WIN32 - #define INVALID_FILE INVALID_HANDLE_VALUE - typedef HANDLE tOSFileHandle; -#else - #define INVALID_FILE -1 - typedef int tOSFileHandle; -#endif - class FileStream : public IOStream { public: diff --git a/lib/common/InvisibleTempFileStream.cpp b/lib/common/InvisibleTempFileStream.cpp index a7e19ad3..abfcb5f6 100644 --- a/lib/common/InvisibleTempFileStream.cpp +++ b/lib/common/InvisibleTempFileStream.cpp @@ -24,9 +24,9 @@ // -------------------------------------------------------------------------- InvisibleTempFileStream::InvisibleTempFileStream(const char *Filename, int flags, int mode) #ifdef WIN32 - : FileStream(::openfile(Filename, flags | O_TEMPORARY, mode)) + : FileStream(Filename, flags | O_TEMPORARY, mode) #else - : FileStream(::open(Filename, flags, mode)) + : FileStream(Filename, flags, mode) #endif { #ifndef WIN32 diff --git a/lib/common/Logging.cpp b/lib/common/Logging.cpp index 1666b487..296443ea 100644 --- a/lib/common/Logging.cpp +++ b/lib/common/Logging.cpp @@ -33,6 +33,8 @@ bool Logging::sLogToSyslog = false; bool Logging::sLogToConsole = false; bool Logging::sContextSet = false; +bool HideExceptionMessageGuard::sHiddenState = false; + std::vector<Logger*> Logging::sLoggers; std::string Logging::sContext; Console* Logging::spConsole = NULL; @@ -493,3 +495,24 @@ bool FileLogger::Log(Log::Level Level, const std::string& rFile, Logging::Add(this); return true; } + +std::string PrintEscapedBinaryData(const std::string& rInput) +{ + std::ostringstream output; + + for (size_t i = 0; i < rInput.length(); i++) + { + if (isprint(rInput[i])) + { + output << rInput[i]; + } + else + { + output << "\\x" << std::hex << std::setw(2) << + std::setfill('0') << (int) rInput[i] << + std::dec; + } + } + + return output.str(); +} diff --git a/lib/common/Logging.h b/lib/common/Logging.h index 9bb2cf6c..24863d2c 100644 --- a/lib/common/Logging.h +++ b/lib/common/Logging.h @@ -18,17 +18,6 @@ #include "FileStream.h" -/* -#define BOX_LOG(level, stuff) \ -{ \ - if(Log::sMaxLoggingLevelForAnyOutput >= level) \ - std::ostringstream line; \ - line << stuff; \ - Log::Write(level, __FILE__, __LINE__, line.str()); \ - } \ -} -*/ - #define BOX_LOG(level, stuff) \ { \ std::ostringstream _box_log_line; \ @@ -52,12 +41,20 @@ if (Logging::IsEnabled(Log::TRACE)) \ { BOX_LOG(Log::TRACE, stuff) } +#define BOX_SYS_ERROR(stuff) \ + stuff << ": " << std::strerror(errno) << " (" << errno << ")" + #define BOX_LOG_SYS_WARNING(stuff) \ - BOX_WARNING(stuff << ": " << std::strerror(errno) << " (" << errno << ")") + BOX_WARNING(BOX_SYS_ERROR(stuff)) #define BOX_LOG_SYS_ERROR(stuff) \ - BOX_ERROR(stuff << ": " << std::strerror(errno) << " (" << errno << ")") + BOX_ERROR(BOX_SYS_ERROR(stuff)) #define BOX_LOG_SYS_FATAL(stuff) \ - BOX_FATAL(stuff << ": " << std::strerror(errno) << " (" << errno << ")") + BOX_FATAL(BOX_SYS_ERROR(stuff)) + +#define LOG_AND_THROW_ERROR(message, filename, exception, subtype) \ + BOX_LOG_SYS_ERROR(message << ": " << filename); \ + THROW_EXCEPTION_MESSAGE(exception, subtype, \ + BOX_SYS_ERROR(message << ": " << filename)); inline std::string GetNativeErrorMessage() { @@ -320,4 +317,25 @@ class FileLogger : public Logger virtual void SetProgramName(const std::string& rProgramName) { } }; +class HideExceptionMessageGuard +{ + public: + HideExceptionMessageGuard() + { + mOldHiddenState = sHiddenState; + sHiddenState = true; + } + ~HideExceptionMessageGuard() + { + sHiddenState = mOldHiddenState; + } + static bool ExceptionsHidden() { return sHiddenState; } + + private: + static bool sHiddenState; + bool mOldHiddenState; +}; + +std::string PrintEscapedBinaryData(const std::string& rInput); + #endif // LOGGING__H diff --git a/lib/common/Makefile.extra b/lib/common/Makefile.extra index 04dd8e71..cc3f3a7a 100644 --- a/lib/common/Makefile.extra +++ b/lib/common/Makefile.extra @@ -3,9 +3,9 @@ MAKEEXCEPTION = ../../lib/common/makeexception.pl # AUTOGEN SEEDING autogen_CommonException.h autogen_CommonException.cpp: $(MAKEEXCEPTION) CommonException.txt - $(PERL) $(MAKEEXCEPTION) CommonException.txt + $(_PERL) $(MAKEEXCEPTION) CommonException.txt # AUTOGEN SEEDING autogen_ConversionException.h autogen_ConversionException.cpp: $(MAKEEXCEPTION) ConversionException.txt - $(PERL) $(MAKEEXCEPTION) ConversionException.txt + $(_PERL) $(MAKEEXCEPTION) ConversionException.txt diff --git a/lib/common/NamedLock.cpp b/lib/common/NamedLock.cpp index b3d0009b..f96f80b5 100644 --- a/lib/common/NamedLock.cpp +++ b/lib/common/NamedLock.cpp @@ -65,7 +65,7 @@ NamedLock::~NamedLock() // Created: 2003/08/28 // // -------------------------------------------------------------------------- -bool NamedLock::TryAndGetLock(const char *Filename, int mode) +bool NamedLock::TryAndGetLock(const std::string& rFilename, int mode) { // Check if(mFileDescriptor != -1) @@ -75,7 +75,8 @@ bool NamedLock::TryAndGetLock(const char *Filename, int mode) // See if the lock can be got #if HAVE_DECL_O_EXLOCK - int fd = ::open(Filename, O_WRONLY | O_NONBLOCK | O_CREAT | O_TRUNC | O_EXLOCK, mode); + int fd = ::open(rFilename.c_str(), + O_WRONLY | O_NONBLOCK | O_CREAT | O_TRUNC | O_EXLOCK, mode); if(fd != -1) { // Got a lock, lovely @@ -92,10 +93,10 @@ bool NamedLock::TryAndGetLock(const char *Filename, int mode) return false; #else - int fd = ::open(Filename, O_WRONLY | O_CREAT | O_TRUNC, mode); + int fd = ::open(rFilename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, mode); if(fd == -1) { - BOX_WARNING("Failed to open lockfile: " << Filename); + BOX_WARNING("Failed to open lockfile: " << rFilename); THROW_EXCEPTION(CommonException, OSFileError) } diff --git a/lib/common/NamedLock.h b/lib/common/NamedLock.h index 5eac712a..534115db 100644 --- a/lib/common/NamedLock.h +++ b/lib/common/NamedLock.h @@ -28,7 +28,7 @@ private: NamedLock(const NamedLock &); public: - bool TryAndGetLock(const char *Filename, int mode = 0755); + bool TryAndGetLock(const std::string& rFilename, int mode = 0755); bool GotLock() {return mFileDescriptor != -1;} void ReleaseLock(); diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp index e903f41e..56638058 100644 --- a/lib/common/Test.cpp +++ b/lib/common/Test.cpp @@ -416,7 +416,7 @@ void terminate_bbackupd(int pid) // Wait a given number of seconds for something to complete -void wait_for_operation(int seconds, char* message) +void wait_for_operation(int seconds, const char* message) { if (Logging::GetGlobalLevel() >= Log::TRACE) { @@ -462,10 +462,24 @@ void safe_sleep(int seconds) ts.tv_nsec = 0; while (nanosleep(&ts, &ts) == -1 && errno == EINTR) { - BOX_TRACE("safe_sleep interrupted with " << - ts.tv_sec << "." << ts.tv_nsec << - " secs remaining, sleeping again"); - /* sleep again */ + // FIXME evil hack for OSX, where ts.tv_sec contains + // a negative number interpreted as unsigned 32-bit + // when nanosleep() returns later than expected. + + int32_t secs = (int32_t) ts.tv_sec; + int64_t remain_ns = (secs * 1000000000) + ts.tv_nsec; + + if (remain_ns < 0) + { + BOX_WARNING("nanosleep interrupted " << + ((float)(0 - remain_ns) / 1000000000) << + " secs late"); + return; + } + + BOX_TRACE("nanosleep interrupted with " << + (remain_ns / 1000000000) << " secs remaining, " + "sleeping again"); } #endif } diff --git a/lib/common/Test.h b/lib/common/Test.h index 362b43af..08ba4542 100644 --- a/lib/common/Test.h +++ b/lib/common/Test.h @@ -18,14 +18,14 @@ #define BBSTORED "..\\..\\bin\\bbstored\\bbstored.exe" #define BBACKUPQUERY "..\\..\\bin\\bbackupquery\\bbackupquery.exe" #define BBSTOREACCOUNTS "..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts.exe" -#define TEST_RETURN(actual, expected) TEST_THAT(actual == expected); +#define TEST_RETURN(actual, expected) TEST_EQUAL(expected, actual); #else #define BBACKUPCTL "../../bin/bbackupctl/bbackupctl" #define BBACKUPD "../../bin/bbackupd/bbackupd" #define BBSTORED "../../bin/bbstored/bbstored" #define BBACKUPQUERY "../../bin/bbackupquery/bbackupquery" #define BBSTOREACCOUNTS "../../bin/bbstoreaccounts/bbstoreaccounts" -#define TEST_RETURN(actual, expected) TEST_THAT(actual == expected*256); +#define TEST_RETURN(actual, expected) TEST_EQUAL((expected << 8), actual); #endif extern int failures; @@ -54,6 +54,7 @@ extern std::string bbackupd_args, bbstored_args, bbackupquery_args, test_args; #define TEST_CHECK_THROWS(statement, excepttype, subtype) \ { \ bool didthrow = false; \ + HideExceptionMessageGuard hide; \ try \ { \ statement; \ @@ -90,8 +91,8 @@ extern std::string bbackupd_args, bbstored_args, bbackupquery_args, test_args; \ if(_exp_str != _found_str) \ { \ - printf("Expected <%s> but found <%s>\n", \ - _exp_str.c_str(), _found_str.c_str()); \ + BOX_WARNING("Expected <" << _exp_str << "> but found <" << \ + _found_str << ">"); \ \ std::ostringstream _oss3; \ _oss3 << #_found << " != " << #_expected; \ @@ -113,7 +114,9 @@ extern std::string bbackupd_args, bbstored_args, bbackupquery_args, test_args; \ if(_exp_str != _found_str) \ { \ - std::string _line_str = _line; \ + std::ostringstream _ossl; \ + _ossl << _line; \ + std::string _line_str = _ossl.str(); \ printf("Expected <%s> but found <%s> in <%s>\n", \ _exp_str.c_str(), _found_str.c_str(), _line_str.c_str()); \ \ @@ -158,7 +161,7 @@ void sync_and_wait(); void terminate_bbackupd(int pid); // Wait a given number of seconds for something to complete -void wait_for_operation(int seconds, char* message); +void wait_for_operation(int seconds, const char* message); void safe_sleep(int seconds); #endif // TEST__H diff --git a/lib/common/Utils.cpp b/lib/common/Utils.cpp index f45ed26b..6f21330d 100644 --- a/lib/common/Utils.cpp +++ b/lib/common/Utils.cpp @@ -30,6 +30,11 @@ #include "MemLeakFindOn.h" +std::string GetBoxBackupVersion() +{ + return BOX_VERSION; +} + // -------------------------------------------------------------------------- // // Function @@ -156,15 +161,16 @@ void DumpStackBacktrace() // -------------------------------------------------------------------------- // // Function -// Name: FileExists(const char *) +// Name: FileExists(const std::string& rFilename) // Purpose: Does a file exist? // Created: 20/11/03 // // -------------------------------------------------------------------------- -bool FileExists(const char *Filename, int64_t *pFileSize, bool TreatLinksAsNotExisting) +bool FileExists(const std::string& rFilename, int64_t *pFileSize, + bool TreatLinksAsNotExisting) { EMU_STRUCT_STAT st; - if(EMU_LSTAT(Filename, &st) != 0) + if(EMU_LSTAT(rFilename.c_str(), &st) != 0) { if(errno == ENOENT) { diff --git a/lib/common/Utils.h b/lib/common/Utils.h index d6792077..8d98a520 100644 --- a/lib/common/Utils.h +++ b/lib/common/Utils.h @@ -15,13 +15,16 @@ #include "MemLeakFindOn.h" +std::string GetBoxBackupVersion(); + void SplitString(const std::string &String, char SplitOn, std::vector<std::string> &rOutput); #ifdef SHOW_BACKTRACE_ON_EXCEPTION void DumpStackBacktrace(); #endif -bool FileExists(const char *Filename, int64_t *pFileSize = 0, bool TreatLinksAsNotExisting = false); +bool FileExists(const std::string& rFilename, int64_t *pFileSize = 0, + bool TreatLinksAsNotExisting = false); enum { |