summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2007-08-02 23:28:17 +0000
committerChris Wilson <chris+github@qwirx.com>2007-08-02 23:28:17 +0000
commit747589f03a1ba61273d21ed6446ad47841a1f46a (patch)
treec354364468b80aaf25b4522ebbe5e45a97911822 /bin
parentc0f0b74c04054ddab5610cba9d2268c04c6a7e9f (diff)
Convert most printf() and fprintf() calls to use logging framework
instead. (refs #3)
Diffstat (limited to 'bin')
-rw-r--r--bin/bbackupctl/bbackupctl.cpp47
-rw-r--r--bin/bbackupquery/BackupQueries.cpp280
-rw-r--r--bin/bbackupquery/bbackupquery.cpp34
-rw-r--r--bin/bbstoreaccounts/bbstoreaccounts.cpp66
4 files changed, 230 insertions, 197 deletions
diff --git a/bin/bbackupctl/bbackupctl.cpp b/bin/bbackupctl/bbackupctl.cpp
index a5dc4c10..edbc252f 100644
--- a/bin/bbackupctl/bbackupctl.cpp
+++ b/bin/bbackupctl/bbackupctl.cpp
@@ -109,8 +109,7 @@ int main(int argc, const char *argv[])
}
// Read in the configuration file
- if(!quiet) printf("Using configuration file %s\n",
- configFilename.c_str());
+ if(!quiet) BOX_NOTICE("Using configuration file " << configFilename);
std::string errs;
std::auto_ptr<Configuration> config(
@@ -119,7 +118,7 @@ int main(int argc, const char *argv[])
if(config.get() == 0 || !errs.empty())
{
- printf("Invalid configuration file:\n%s", errs.c_str());
+ BOX_ERROR("Invalid configuration file: " << errs);
return 1;
}
// Easier coding
@@ -128,10 +127,10 @@ int main(int argc, const char *argv[])
// Check there's a socket defined in the config file
if(!conf.KeyExists("CommandSocket"))
{
- printf("Daemon isn't using a control socket, "
+ BOX_ERROR("Daemon isn't using a control socket, "
"could not execute command.\n"
"Add a CommandSocket declaration to the "
- "bbackupd.conf file.\n");
+ "bbackupd.conf file.");
return 1;
}
@@ -153,18 +152,14 @@ int main(int argc, const char *argv[])
}
catch(...)
{
- printf("Failed to connect to daemon control socket.\n"
+ BOX_ERROR("Failed to connect to daemon control socket.\n"
"Possible causes:\n"
" * Daemon not running\n"
" * Daemon busy syncing with store server\n"
" * Another bbackupctl process is communicating with the daemon\n"
- " * Daemon is waiting to recover from an error\n"
+ " * Daemon is waiting to recover from an error"
);
-#if defined WIN32 && ! defined NDEBUG
- BOX_ERROR("Failed to connect to the command socket");
-#endif
-
return 1;
}
@@ -193,19 +188,19 @@ int main(int argc, const char *argv[])
if(::sscanf(configSummary.c_str(), "bbackupd: %d %d %d %d", &autoBackup,
&updateStoreInterval, &minimumFileAge, &maxUploadWait) != 4)
{
- printf("Config summary didn't decode\n");
+ BOX_ERROR("Config summary didn't decode.");
return 1;
}
// Print summary?
if(!quiet)
{
- printf("Daemon configuration summary:\n"
- " AutomaticBackup = %s\n"
- " UpdateStoreInterval = %d seconds\n"
- " MinimumFileAge = %d seconds\n"
- " MaxUploadWait = %d seconds\n",
- autoBackup?"true":"false", updateStoreInterval,
- minimumFileAge, maxUploadWait);
+ BOX_INFO("Daemon configuration summary:\n"
+ " AutomaticBackup = " <<
+ (autoBackup?"true":"false") << "\n"
+ " UpdateStoreInterval = " << updateStoreInterval <<
+ " seconds\n"
+ " MinimumFileAge = " << minimumFileAge << " seconds\n"
+ " MaxUploadWait = " << maxUploadWait << " seconds\n");
}
std::string stateLine;
@@ -266,8 +261,8 @@ int main(int argc, const char *argv[])
if (currentState != 0)
{
- printf("Waiting for current sync/error state "
- "to finish...\n");
+ BOX_INFO("Waiting for current sync/error state "
+ "to finish...");
}
}
break;
@@ -310,14 +305,14 @@ int main(int argc, const char *argv[])
{
if(line == "start-sync")
{
- if (!quiet) printf("Sync started...\n");
+ if (!quiet) BOX_INFO("Sync started...");
syncIsRunning = true;
}
else if(line == "finish-sync")
{
if (syncIsRunning)
{
- if (!quiet) printf("Sync finished.\n");
+ if (!quiet) BOX_INFO("Sync finished.\n");
// Send a quit command to finish nicely
connection.Write("quit\n", 5);
@@ -326,7 +321,7 @@ int main(int argc, const char *argv[])
}
else
{
- if (!quiet) printf("Previous sync finished.\n");
+ if (!quiet) BOX_INFO("Previous sync finished.");
}
// daemon must still be busy
}
@@ -340,13 +335,13 @@ int main(int argc, const char *argv[])
{
if(!quiet)
{
- printf("Succeeded.\n");
+ BOX_INFO("Succeeded.\n");
}
finished = true;
}
else if(line == "error")
{
- printf("ERROR. (Check command spelling)\n");
+ BOX_ERROR("Check command spelling");
returnCode = 1;
finished = true;
}
diff --git a/bin/bbackupquery/BackupQueries.cpp b/bin/bbackupquery/BackupQueries.cpp
index 0c5f9c15..09003d4d 100644
--- a/bin/bbackupquery/BackupQueries.cpp
+++ b/bin/bbackupquery/BackupQueries.cpp
@@ -181,7 +181,7 @@ void BackupQueries::DoCommand(const char *Command, bool isFromCommandLine)
if (!ConvertEncoding(*i, CP_ACP, converted,
GetConsoleCP()))
{
- printf("Failed to convert encoding");
+ BOX_ERROR("Failed to convert encoding");
return;
}
*i = converted;
@@ -255,7 +255,7 @@ void BackupQueries::DoCommand(const char *Command, bool isFromCommandLine)
// No such command
if(alias[a] == 0)
{
- printf("Unrecognised command: %s\n", Command);
+ BOX_ERROR("Unrecognised command: " << Command);
return;
}
}
@@ -275,8 +275,8 @@ void BackupQueries::DoCommand(const char *Command, bool isFromCommandLine)
// Valid option?
if(::strchr(commands[cmd].opts, *c) == NULL)
{
- printf("Invalid option '%c' for command %s\n",
- *c, commands[cmd].name);
+ BOX_ERROR("Invalid option '" << *c << "' for "
+ "command " << commands[cmd].name);
return;
}
opts[(int)*c] = true;
@@ -305,9 +305,8 @@ void BackupQueries::DoCommand(const char *Command, bool isFromCommandLine)
case COMMAND_pwd:
{
// Simple implementation, so do it here
- printf("%s (%08llx)\n",
- GetCurrentDirectoryName().c_str(),
- (long long)GetCurrentDirectoryID());
+ BOX_INFO(GetCurrentDirectoryName() << " (" <<
+ BOX_FORMAT_OBJECTID(GetCurrentDirectoryID()));
}
break;
@@ -320,7 +319,7 @@ void BackupQueries::DoCommand(const char *Command, bool isFromCommandLine)
break;
case COMMAND_sh:
- printf("The command to run must be specified as an argument.\n");
+ BOX_ERROR("The command to run must be specified as an argument.");
break;
case COMMAND_GetObject:
@@ -401,8 +400,8 @@ void BackupQueries::CommandList(const std::vector<std::string> &args, const bool
if(rootDir == 0)
{
- printf("Directory '%s' not found on store\n",
- args[0].c_str());
+ BOX_ERROR("Directory '" << args[0] << "' not found "
+ "on store.");
return;
}
}
@@ -747,7 +746,7 @@ void BackupQueries::CommandChangeDir(const std::vector<std::string> &args, const
{
if(args.size() != 1 || args[0].size() == 0)
{
- printf("Incorrect usage.\ncd [-o] [-d] <directory>\n");
+ BOX_ERROR("Incorrect usage. cd [-o] [-d] <directory>");
return;
}
@@ -764,7 +763,7 @@ void BackupQueries::CommandChangeDir(const std::vector<std::string> &args, const
if(id == 0)
{
- printf("Directory '%s' not found\n", args[0].c_str());
+ BOX_ERROR("Directory '" << args[0] << "' not found.");
return;
}
@@ -785,7 +784,7 @@ void BackupQueries::CommandChangeLocalDir(const std::vector<std::string> &args)
{
if(args.size() != 1 || args[0].size() == 0)
{
- printf("Incorrect usage.\nlcd <local-directory>\n");
+ BOX_ERROR("Incorrect usage. lcd <local-directory>");
SetReturnCode(COMMAND_RETURN_ERROR);
return;
}
@@ -795,7 +794,7 @@ void BackupQueries::CommandChangeLocalDir(const std::vector<std::string> &args)
std::string dirName;
if(!ConvertConsoleToUtf8(args[0].c_str(), dirName))
{
- printf("Failed to convert path from console encoding.\n");
+ BOX_ERROR("Failed to convert path from console encoding.");
SetReturnCode(COMMAND_RETURN_ERROR);
return;
}
@@ -805,8 +804,16 @@ void BackupQueries::CommandChangeLocalDir(const std::vector<std::string> &args)
#endif
if(result != 0)
{
- printf((errno == ENOENT || errno == ENOTDIR)?"Directory '%s' does not exist\n":"Error changing dir to '%s'\n",
- args[0].c_str());
+ if(errno == ENOENT || errno == ENOTDIR)
+ {
+ BOX_ERROR("Directory '" << args[0] << "' does not exist.");
+ }
+ else
+ {
+ BOX_ERROR("Error changing to directory '" <<
+ args[0] << ": " << strerror(errno));
+ }
+
SetReturnCode(COMMAND_RETURN_ERROR);
return;
}
@@ -815,7 +822,8 @@ void BackupQueries::CommandChangeLocalDir(const std::vector<std::string> &args)
char wd[PATH_MAX];
if(::getcwd(wd, PATH_MAX) == 0)
{
- printf("Error getting current directory\n");
+ BOX_ERROR("Error getting current directory: " <<
+ strerror(errno));
SetReturnCode(COMMAND_RETURN_ERROR);
return;
}
@@ -823,13 +831,13 @@ void BackupQueries::CommandChangeLocalDir(const std::vector<std::string> &args)
#ifdef WIN32
if(!ConvertUtf8ToConsole(wd, dirName))
{
- printf("Failed to convert new path from console encoding.\n");
+ BOX_ERROR("Failed to convert new path from console encoding.");
SetReturnCode(COMMAND_RETURN_ERROR);
return;
}
- printf("Local current directory is now '%s'\n", dirName.c_str());
+ BOX_INFO("Local current directory is now '" << dirName << "'.");
#else
- printf("Local current directory is now '%s'\n", wd);
+ BOX_INFO("Local current directory is now '" << wd << "'.");
#endif
}
@@ -847,14 +855,15 @@ void BackupQueries::CommandGetObject(const std::vector<std::string> &args, const
// Check args
if(args.size() != 2)
{
- printf("Incorrect usage.\ngetobject <object-id> <local-filename>\n");
+ BOX_ERROR("Incorrect usage. getobject <object-id> "
+ "<local-filename>");
return;
}
int64_t id = ::strtoll(args[0].c_str(), 0, 16);
if(id == std::numeric_limits<long long>::min() || id == std::numeric_limits<long long>::max() || id == 0)
{
- printf("Not a valid object ID (specified in hex)\n");
+ BOX_ERROR("Not a valid object ID (specified in hex).");
return;
}
@@ -862,7 +871,7 @@ void BackupQueries::CommandGetObject(const std::vector<std::string> &args, const
struct stat st;
if(::stat(args[1].c_str(), &st) == 0 || errno != ENOENT)
{
- printf("The local file %s already exists\n", args[1].c_str());
+ BOX_ERROR("The local file '" << args[1] << " already exists.");
return;
}
@@ -880,18 +889,20 @@ void BackupQueries::CommandGetObject(const std::vector<std::string> &args, const
std::auto_ptr<IOStream> objectStream(mrConnection.ReceiveStream());
objectStream->CopyStreamTo(out);
- printf("Object ID %08llx fetched successfully.\n", id);
+ BOX_INFO("Object ID " << BOX_FORMAT_OBJECTID(id) <<
+ " fetched successfully.");
}
else
{
- printf("Object does not exist on store.\n");
+ BOX_ERROR("Object ID " << BOX_FORMAT_OBJECTID(id) <<
+ " does not exist on store.");
::unlink(args[1].c_str());
}
}
catch(...)
{
::unlink(args[1].c_str());
- printf("Error occured fetching object.\n");
+ BOX_ERROR("Error occured fetching object.");
}
}
@@ -911,9 +922,9 @@ void BackupQueries::CommandGet(std::vector<std::string> args, const bool *opts)
// Check args
if(args.size() < 1 || (opts['i'] && args.size() != 2) || args.size() > 2)
{
- printf("Incorrect usage.\n"
+ BOX_ERROR("Incorrect usage.\n"
"get <remote-filename> [<local-filename>] or\n"
- "get -i <object-id> <local-filename>\n");
+ "get -i <object-id> <local-filename>");
return;
}
@@ -931,7 +942,7 @@ void BackupQueries::CommandGet(std::vector<std::string> args, const bool *opts)
std::string out;
if(!ConvertConsoleToUtf8(i->c_str(), out))
{
- fprintf(stderr, "failed to convert encoding\n");
+ BOX_ERROR("Failed to convert encoding.");
return;
}
*i = out;
@@ -952,8 +963,8 @@ void BackupQueries::CommandGet(std::vector<std::string> args, const bool *opts)
dirId = FindDirectoryObjectID(dirName);
if(dirId == 0)
{
- printf("Directory '%s' not found\n",
- dirName.c_str());
+ BOX_ERROR("Directory '" << dirName <<
+ "' not found.");
return;
}
}
@@ -981,18 +992,19 @@ void BackupQueries::CommandGet(std::vector<std::string> args, const bool *opts)
fileId == std::numeric_limits<long long>::max() ||
fileId == 0)
{
- printf("Not a valid object ID (specified in hex)\n");
+ BOX_ERROR("Not a valid object ID (specified in hex).");
return;
}
// Check that the item is actually in the directory
if(dir.FindEntryByID(fileId) == 0)
{
- printf("ID '%08llx' not found in current "
+ BOX_ERROR("File ID " <<
+ BOX_FORMAT_OBJECTID(fileId) <<
+ " not found in current "
"directory on store.\n"
- "(You can only download objects by ID "
- "from the current directory.)\n",
- fileId);
+ "(You can only download files by ID "
+ "from the current directory.)");
return;
}
@@ -1007,10 +1019,11 @@ void BackupQueries::CommandGet(std::vector<std::string> args, const bool *opts)
if(en == 0)
{
- printf("Filename '%s' not found in current "
+ BOX_ERROR("Filename '" << args[0] << "' "
+ "not found in current "
"directory on store.\n"
"(Subdirectories in path not "
- "searched.)\n", args[0].c_str());
+ "searched.)");
return;
}
@@ -1027,8 +1040,8 @@ void BackupQueries::CommandGet(std::vector<std::string> args, const bool *opts)
struct stat st;
if(::stat(localName.c_str(), &st) == 0 || errno != ENOENT)
{
- printf("The local file %s already exists, will not "
- "overwrite it.\n", localName.c_str());
+ BOX_ERROR("The local file " << localName << " already exists, "
+ "will not overwrite it.");
SetReturnCode(COMMAND_RETURN_ERROR);
return;
}
@@ -1046,7 +1059,8 @@ void BackupQueries::CommandGet(std::vector<std::string> args, const bool *opts)
BackupStoreFile::DecodeFile(*objectStream, localName.c_str(), mrConnection.GetTimeout());
// Done.
- printf("Object ID %08llx fetched sucessfully.\n", fileId);
+ BOX_INFO("Object ID " << BOX_FORMAT_OBJECTID(fileId) <<
+ " fetched successfully.");
}
catch (BoxException &e)
{
@@ -1160,14 +1174,16 @@ void BackupQueries::CommandCompare(const std::vector<std::string> &args, const b
}
else
{
- printf("Warning: couldn't determine the time of the last synchronisation -- checks not performed.\n");
+ BOX_WARNING("Failed to determine the time of the last "
+ "synchronisation -- checks not performed.");
}
}
// Quick compare?
if(params.mQuickCompare)
{
- printf("WARNING: Quick compare used -- file attributes are not checked.\n");
+ BOX_WARNING("Quick compare used -- file attributes are not "
+ "checked.");
}
if(!opts['l'] && opts['a'] && args.size() == 0)
@@ -1192,7 +1208,7 @@ void BackupQueries::CommandCompare(const std::vector<std::string> &args, const b
// Can't be bothered to do all the hard work to work out which location it's on, and hence which exclude list
if(!params.mIgnoreExcludes)
{
- printf("Cannot use excludes on directory to directory comparison -- use -E flag to specify ignored excludes\n");
+ BOX_ERROR("Cannot use excludes on directory to directory comparison -- use -E flag to specify ignored excludes.");
return;
}
else
@@ -1203,22 +1219,22 @@ void BackupQueries::CommandCompare(const std::vector<std::string> &args, const b
}
else
{
- printf("Incorrect usage.\ncompare -a\n or compare -l <location-name>\n or compare <store-dir-name> <local-dir-name>\n");
+ BOX_ERROR("Incorrect usage.\ncompare -a\n or compare -l <location-name>\n or compare <store-dir-name> <local-dir-name>");
return;
}
if (!params.mQuietCompare)
{
- printf("\n[ %d (of %d) differences probably due to file "
- "modifications after the last upload ]\n",
- params.mDifferencesExplainedByModTime,
- params.mDifferences);
+ BOX_INFO("[ " <<
+ params.mDifferencesExplainedByModTime << " (of " <<
+ params.mDifferences << ") differences probably "
+ "due to file modifications after the last upload ]");
}
- printf("Differences: %d (%d dirs excluded, %d files excluded, "
- "%d files not checked)\n",
- params.mDifferences, params.mExcludedDirs,
- params.mExcludedFiles, params.mUncheckedFiles);
+ BOX_INFO("Differences: " << params.mDifferences << " (" <<
+ params.mExcludedDirs << " dirs excluded, " <<
+ params.mExcludedFiles << " files excluded, " <<
+ params.mUncheckedFiles << " files not checked)");
// Set return code?
if(opts['c'])
@@ -1253,7 +1269,7 @@ void BackupQueries::CompareLocation(const std::string &rLocation, BackupQueries:
const Configuration &locations(mrConfiguration.GetSubConfiguration("BackupLocations"));
if(!locations.SubConfigurationExists(rLocation.c_str()))
{
- printf("Location %s does not exist.\n", rLocation.c_str());
+ BOX_ERROR("Location " << rLocation << " does not exist.");
return;
}
const Configuration &loc(locations.GetSubConfiguration(rLocation.c_str()));
@@ -1264,9 +1280,9 @@ void BackupQueries::CompareLocation(const std::string &rLocation, BackupQueries:
if (path.size() > 0 && path[path.size()-1] ==
DIRECTORY_SEPARATOR_ASCHAR)
{
- fprintf(stderr, "Warning: location '%s' path ends "
- "with '%s', compare may fail!",
- rLocation.c_str(), DIRECTORY_SEPARATOR);
+ BOX_WARNING("Location '" << rLocation << "' path ends "
+ "with '" DIRECTORY_SEPARATOR "', "
+ "compare may fail!");
}
}
#endif
@@ -1319,9 +1335,9 @@ void BackupQueries::Compare(const std::string &rStoreDir, const std::string &rLo
// Found?
if(dirID == 0)
{
- printf("Local directory '%s' exists, but "
- "server directory '%s' does not exist\n",
- rLocalDir.c_str(), rStoreDir.c_str());
+ BOX_WARNING("Local directory '" << rLocalDir << "' exists, "
+ "but server directory '" << rStoreDir << "' does not "
+ "exist.");
rParams.mDifferences ++;
return;
}
@@ -1369,24 +1385,23 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
// What kind of error?
if(errno == ENOTDIR)
{
- printf("Local object '%s' is a file, "
- "server object '%s' is a directory\n",
- localDirDisplay.c_str(),
- storeDirDisplay.c_str());
+ BOX_WARNING("Local object '" << localDirDisplay << "' "
+ "is a file, server object '" <<
+ storeDirDisplay << "' is a directory.");
rParams.mDifferences ++;
}
else if(errno == ENOENT)
{
- printf("Local directory '%s' does not exist "
- "(compared to server directory '%s')\n",
- localDirDisplay.c_str(),
- storeDirDisplay.c_str());
+ BOX_WARNING("Local directory '" << localDirDisplay <<
+ "' does not exist (compared to server "
+ "directory '" << storeDirDisplay << "').");
rParams.mDifferences ++;
}
else
{
- printf("ERROR: stat on local dir '%s'\n",
- localDirDisplay.c_str());
+ BOX_WARNING("Failed to access local directory '" <<
+ localDirDisplay << ": " << strerror(errno) <<
+ "'.");
rParams.mUncheckedFiles ++;
}
return;
@@ -1407,8 +1422,8 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
// Test out the attributes
if(!dir.HasAttributes())
{
- printf("Store directory '%s' doesn't have attributes.\n",
- storeDirDisplay.c_str());
+ BOX_WARNING("Store directory '" << storeDirDisplay << "' "
+ "doesn't have attributes.");
}
else
{
@@ -1423,10 +1438,9 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
if(!(attr.Compare(localAttr, true, true /* ignore modification times */)))
{
- printf("Local directory '%s' has different attributes "
- "to store directory '%s'.\n",
- localDirDisplay.c_str(),
- storeDirDisplay.c_str());
+ BOX_WARNING("Local directory '" << localDirDisplay <<
+ "' has different attributes to store "
+ "directory '" << storeDirDisplay << "'.");
rParams.mDifferences ++;
}
}
@@ -1435,8 +1449,8 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
DIR *dirhandle = ::opendir(rLocalDir.c_str());
if(dirhandle == 0)
{
- printf("ERROR: opendir on local dir '%s'\n",
- localDirDisplay.c_str());
+ BOX_WARNING("Failed to open local directory '" <<
+ localDirDisplay << "': " << strerror(errno));
rParams.mUncheckedFiles ++;
return;
}
@@ -1457,9 +1471,9 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
#ifdef HAVE_VALID_DIRENT_D_TYPE
if (localDirEn->d_type != DT_DIR)
{
- fprintf(stderr, "ERROR: d_type does "
- "not really work on your "
- "platform. Reconfigure Box!\n");
+ BOX_ERROR("d_type does not really "
+ "work on your platform. "
+ "Reconfigure Box!");
return;
}
#endif
@@ -1504,8 +1518,8 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
// Close directory
if(::closedir(dirhandle) != 0)
{
- printf("ERROR: closedir on local dir '%s'\n",
- localDirDisplay.c_str());
+ BOX_ERROR("Failed to close local directory '" <<
+ localDirDisplay << "': " << strerror(errno));
}
dirhandle = 0;
@@ -1565,10 +1579,10 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
if(local == localFiles.end())
{
// Not found -- report
- printf("Local file '%s' does not exist, "
- "but store file '%s' does.\n",
- localPathDisplay.c_str(),
- storePathDisplay.c_str());
+ BOX_WARNING("Local file '" <<
+ localDirDisplay << "' does not exist, "
+ "but store file '" <<
+ storePathDisplay << "' does.");
rParams.mDifferences ++;
}
else
@@ -1643,20 +1657,21 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
ignoreAttrModTime,
fileOnServerStream->IsSymLink() /* ignore modification time if it's a symlink */))
{
- printf("Local file '%s' "
- "has different attributes "
- "to store file '%s'.\n",
- localPathDisplay.c_str(),
- storePathDisplay.c_str());
+ BOX_WARNING("Local file '" <<
+ localPathDisplay <<
+ "' has different attributes "
+ "to store file '" <<
+ storePathDisplay <<
+ "'.");
rParams.mDifferences ++;
if(modifiedAfterLastSync)
{
rParams.mDifferencesExplainedByModTime ++;
- printf("(the file above was modified after the last sync time -- might be reason for difference)\n");
+ BOX_INFO("(the file above was modified after the last sync time -- might be reason for difference)");
}
else if(i->second->HasAttributes())
{
- printf("(the file above has had new attributes applied)\n");
+ BOX_INFO("(the file above has had new attributes applied)\n");
}
}
@@ -1722,20 +1737,21 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
// Report if not equal.
if(!equal)
{
- printf("Local file '%s' "
+ BOX_WARNING("Local file '" <<
+ localPathDisplay << "' "
"has different contents "
- "to store file '%s'.\n",
- localPathDisplay.c_str(),
- storePathDisplay.c_str());
+ "to store file '" <<
+ storePathDisplay <<
+ "'.");
rParams.mDifferences ++;
if(modifiedAfterLastSync)
{
rParams.mDifferencesExplainedByModTime ++;
- printf("(the file above was modified after the last sync time -- might be reason for difference)\n");
+ BOX_INFO("(the file above was modified after the last sync time -- might be reason for difference)");
}
else if(i->second->HasAttributes())
{
- printf("(the file above has had new attributes applied)\n");
+ BOX_INFO("(the file above has had new attributes applied)\n");
}
}
}
@@ -1794,11 +1810,11 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
if(rParams.mpExcludeFiles == 0 ||
!(rParams.mpExcludeFiles->IsExcluded(localPath)))
{
- printf("Local file '%s' exists, "
- "but store file '%s' "
- "does not exist.\n",
- localPathDisplay.c_str(),
- storePathDisplay.c_str());
+ BOX_WARNING("Local file '" <<
+ localPathDisplay <<
+ "' exists, but store file '" <<
+ storePathDisplay <<
+ "' does not.");
rParams.mDifferences ++;
// Check the file modification time
@@ -1809,7 +1825,7 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
if(FileModificationTime(st) > rParams.mLatestFileUploadTime)
{
rParams.mDifferencesExplainedByModTime ++;
- printf("(the file above was modified after the last sync time -- might be reason for difference)\n");
+ BOX_INFO("(the file above was modified after the last sync time -- might be reason for difference)");
}
}
}
@@ -1852,19 +1868,19 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
rParams.mpExcludeDirs->IsExcluded(localPath))
{
// Not found -- report
- printf("Local directory '%s' is excluded, but "
- "store directory '%s' still exists.\n",
- localPathDisplay.c_str(),
- storePathDisplay.c_str());
+ BOX_WARNING("Local directory '" <<
+ localPathDisplay << "' is excluded, "
+ "but store directory '" <<
+ storePathDisplay << "' still exists.");
rParams.mDifferences ++;
}
else if(local == localDirs.end())
{
// Not found -- report
- printf("Local directory '%s' does not exist, "
- "but store directory '%s' does.\n",
- localPathDisplay.c_str(),
- storePathDisplay.c_str());
+ BOX_WARNING("Local directory '" <<
+ localPathDisplay << "' does not exist, "
+ "but store directory '" <<
+ storePathDisplay << "' does.");
rParams.mDifferences ++;
}
else if(rParams.mpExcludeDirs != NULL &&
@@ -1908,10 +1924,10 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
// Should this be ignored (ie is excluded)?
if(rParams.mpExcludeDirs == 0 || !(rParams.mpExcludeDirs->IsExcluded(localPath)))
{
- printf("Local directory '%s' exists, but "
- "store directory '%s' does not exist.\n",
- localPathDisplay.c_str(),
- storePathDisplay.c_str());
+ BOX_WARNING("Local directory '" <<
+ localPathDisplay << "' exists, but "
+ "store directory '" <<
+ storePathDisplay << "' does not.");
rParams.mDifferences ++;
}
else
@@ -1944,7 +1960,7 @@ void BackupQueries::CommandRestore(const std::vector<std::string> &args, const b
// Check arguments
if(args.size() != 2)
{
- printf("Incorrect usage.\nrestore [-d] [-r] [-i] <directory-name> <local-directory-name>\n");
+ BOX_ERROR("Incorrect usage. restore [-d] [-r] [-i] <remote-name> <local-name>");
return;
}
@@ -1959,7 +1975,7 @@ void BackupQueries::CommandRestore(const std::vector<std::string> &args, const b
dirID = ::strtoll(args[0].c_str(), 0, 16);
if(dirID == std::numeric_limits<long long>::min() || dirID == std::numeric_limits<long long>::max() || dirID == 0)
{
- printf("Not a valid object ID (specified in hex)\n");
+ BOX_ERROR("Not a valid object ID (specified in hex)");
return;
}
}
@@ -1982,12 +1998,12 @@ void BackupQueries::CommandRestore(const std::vector<std::string> &args, const b
// Allowable?
if(dirID == 0)
{
- printf("Directory '%s' not found on server\n", args[0].c_str());
+ BOX_ERROR("Directory '" << args[0] << "' not found on server");
return;
}
if(dirID == BackupProtocolClientListDirectory::RootDirectory)
{
- printf("Cannot restore the root directory -- restore locations individually.\n");
+ BOX_ERROR("Cannot restore the root directory -- restore locations individually.");
return;
}
@@ -2023,31 +2039,31 @@ void BackupQueries::CommandRestore(const std::vector<std::string> &args, const b
switch(result)
{
case Restore_Complete:
- printf("Restore complete\n");
+ BOX_INFO("Restore complete.");
break;
case Restore_ResumePossible:
- printf("Resume possible -- repeat command with -r flag to resume\n");
+ BOX_ERROR("Resume possible -- repeat command with -r flag to resume");
break;
case Restore_TargetExists:
- printf("The target directory exists. You cannot restore over an existing directory.\n");
+ BOX_ERROR("The target directory exists. You cannot restore over an existing directory.");
break;
#ifdef WIN32
case Restore_TargetPathNotFound:
- printf("The target directory path does not exist.\n"
+ BOX_ERROR("The target directory path does not exist.\n"
"To restore to a directory whose parent "
- "does not exist, create the parent first.\n");
+ "does not exist, create the parent first.");
break;
#endif
case Restore_UnknownError:
- printf("Unknown error during restore.\n");
+ BOX_ERROR("Unknown error during restore.");
break;
default:
- printf("ERROR: Unknown restore result %d.\n", result);
+ BOX_ERROR("Unknown restore result " << result << ".");
break;
}
}
@@ -2167,7 +2183,7 @@ void BackupQueries::CommandUndelete(const std::vector<std::string> &args, const
// Check arguments
if(args.size() != 1)
{
- printf("Incorrect usage.\nundelete <directory-name>\n");
+ BOX_ERROR("Incorrect usage. undelete <directory-name>");
return;
}
@@ -2185,12 +2201,12 @@ void BackupQueries::CommandUndelete(const std::vector<std::string> &args, const
// Allowable?
if(dirID == 0)
{
- printf("Directory '%s' not found on server\n", args[0].c_str());
+ BOX_ERROR("Directory '" << args[0] << "' not found on server.");
return;
}
if(dirID == BackupProtocolClientListDirectory::RootDirectory)
{
- printf("Cannot undelete the root directory.\n");
+ BOX_ERROR("Cannot undelete the root directory.");
return;
}
diff --git a/bin/bbackupquery/bbackupquery.cpp b/bin/bbackupquery/bbackupquery.cpp
index 9cc3eb1a..98726843 100644
--- a/bin/bbackupquery/bbackupquery.cpp
+++ b/bin/bbackupquery/bbackupquery.cpp
@@ -12,8 +12,14 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+
+#include <errno.h>
#include <stdio.h>
-#include <sys/types.h>
+
+#ifdef HAVE_SYS_TYPES_H
+ #include <sys/types.h>
+#endif
+
#ifdef HAVE_LIBREADLINE
#ifdef HAVE_READLINE_READLINE_H
#include <readline/readline.h>
@@ -168,7 +174,8 @@ int main(int argc, const char *argv[])
logFile = ::fopen(optarg, "w");
if(logFile == 0)
{
- printf("Can't open log file '%s'\n", optarg);
+ BOX_ERROR("Failed to open log file '" <<
+ optarg << "': " << strerror(errno));
}
break;
@@ -201,14 +208,14 @@ int main(int argc, const char *argv[])
{
if (!SetConsoleCP(CP_UTF8))
{
- fprintf(stderr, "Failed to set input codepage: "
- "error %d\n", GetLastError());
+ BOX_ERROR("Failed to set input codepage: " <<
+ GetErrorMessage(GetLastError()));
}
if (!SetConsoleOutputCP(CP_UTF8))
{
- fprintf(stderr, "Failed to set output codepage: "
- "error %d\n", GetLastError());
+ BOX_ERROR("Failed to set output codepage: " <<
+ GetErrorMessage(GetLastError()));
}
// enable input of Unicode characters
@@ -222,8 +229,7 @@ int main(int argc, const char *argv[])
#endif // WIN32
// Read in the configuration file
- if(!quiet) printf("Using configuration file %s\n",
- configFilename.c_str());
+ if(!quiet) BOX_INFO("Using configuration file " << configFilename);
std::string errs;
std::auto_ptr<Configuration> config(
@@ -232,7 +238,7 @@ int main(int argc, const char *argv[])
if(config.get() == 0 || !errs.empty())
{
- printf("Invalid configuration file:\n%s", errs.c_str());
+ BOX_FATAL("Invalid configuration file: " << errs);
return 1;
}
// Easier coding
@@ -252,12 +258,12 @@ int main(int argc, const char *argv[])
BackupClientCryptoKeys_Setup(conf.GetKeyValue("KeysFile").c_str());
// 2. Connect to server
- if(!quiet) printf("Connecting to store...\n");
+ if(!quiet) BOX_INFO("Connecting to store...");
SocketStreamTLS socket;
socket.Open(tlsContext, Socket::TypeINET, conf.GetKeyValue("StoreHostname").c_str(), BOX_PORT_BBSTORED);
// 3. Make a protocol, and handshake
- if(!quiet) printf("Handshake with store...\n");
+ if(!quiet) BOX_INFO("Handshake with store...");
BackupProtocolClient connection(socket);
connection.Handshake();
@@ -268,7 +274,7 @@ int main(int argc, const char *argv[])
}
// 4. Log in to server
- if(!quiet) printf("Login to store...\n");
+ if(!quiet) BOX_INFO("Login to store...");
// Check the version of the server
{
std::auto_ptr<BackupProtocolClientVersion> serverVersion(connection.QueryVersion(BACKUP_STORE_SERVER_VERSION));
@@ -345,9 +351,9 @@ int main(int argc, const char *argv[])
#endif
// Done... stop nicely
- if(!quiet) printf("Logging off...\n");
+ if(!quiet) BOX_INFO("Logging off...");
connection.QueryFinished();
- if(!quiet) printf("Session finished.\n");
+ if(!quiet) BOX_INFO("Session finished.");
// Return code
returnCode = context.GetReturnCode();
diff --git a/bin/bbstoreaccounts/bbstoreaccounts.cpp b/bin/bbstoreaccounts/bbstoreaccounts.cpp
index 567c5bbc..8a00e3b9 100644
--- a/bin/bbstoreaccounts/bbstoreaccounts.cpp
+++ b/bin/bbstoreaccounts/bbstoreaccounts.cpp
@@ -37,12 +37,13 @@ void CheckSoftHardLimits(int64_t SoftLimit, int64_t HardLimit)
{
if(SoftLimit >= HardLimit)
{
- printf("ERROR: Soft limit must be less than the hard limit.\n");
+ BOX_FATAL("Soft limit must be less than the hard limit.");
exit(1);
}
if(SoftLimit > ((HardLimit * MAX_SOFT_LIMIT_SIZE) / 100))
{
- printf("ERROR: Soft limit must be no more than %d%% of the hard limit.\n", MAX_SOFT_LIMIT_SIZE);
+ BOX_FATAL("Soft limit must be no more than " <<
+ MAX_SOFT_LIMIT_SIZE << "% of the hard limit.");
exit(1);
}
}
@@ -53,7 +54,7 @@ int BlockSizeOfDiscSet(int DiscSet)
RaidFileController &controller(RaidFileController::GetController());
if(DiscSet < 0 || DiscSet >= controller.GetNumDiscSets())
{
- printf("Disc set %d does not exist\n", DiscSet);
+ BOX_FATAL("Disc set " << DiscSet << " does not exist.");
exit(1);
}
@@ -89,7 +90,7 @@ int64_t SizeStringToBlocks(const char *string, int DiscSet)
int64_t number = strtol(string, &endptr, 0);
if(endptr == string || number == LONG_MIN || number == LONG_MAX)
{
- printf("%s is an invalid number\n", string);
+ BOX_FATAL("'" << string << "' is not a valid number.");
exit(1);
}
@@ -116,7 +117,8 @@ int64_t SizeStringToBlocks(const char *string, int DiscSet)
break;
default:
- printf("%s has an invalid units specifier\nUse B for blocks, M for Mb, G for Gb, eg 2Gb\n", string);
+ BOX_FATAL(string << " has an invalid units specifier "
+ "(use B for blocks, M for Mb, G for Gb, eg 2Gb)");
exit(1);
break;
}
@@ -143,7 +145,8 @@ bool GetWriteLockOnAccount(NamedLock &rLock, const std::string rRootDir, int Dis
if(!gotLock)
{
// Couldn't lock the account -- just stop now
- printf("Couldn't lock the account -- did not change the limits\nTry again later.\n");
+ BOX_ERROR("Failed to lock the account, did not change limits. "
+ "Try again later.");
return 1;
}
@@ -168,7 +171,8 @@ int SetLimit(Configuration &rConfig, const std::string &rUsername, int32_t ID, c
// Already exists?
if(!db->EntryExists(ID))
{
- printf("Account %x does not exist\n", ID);
+ BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) <<
+ " does not exist.");
return 1;
}
@@ -198,7 +202,9 @@ int SetLimit(Configuration &rConfig, const std::string &rUsername, int32_t ID, c
// Save
info->Save();
- printf("Limits on account 0x%08x changed to %lld soft, %lld hard\n", ID, softlimit, hardlimit);
+ BOX_NOTICE("Limits on account " << BOX_FORMAT_ACCOUNT(ID) <<
+ " changed to " << softlimit << " soft, " <<
+ hardlimit << " hard.");
return 0;
}
@@ -211,7 +217,8 @@ int AccountInfo(Configuration &rConfig, int32_t ID)
// Exists?
if(!db->EntryExists(ID))
{
- printf("Account %x does not exist\n", ID);
+ BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) <<
+ " does not exist.");
return 1;
}
@@ -241,11 +248,12 @@ int DeleteAccount(Configuration &rConfig, const std::string &rUsername, int32_t
// Check user really wants to do this
if(AskForConfirmation)
{
- ::printf("Really delete account %08x?\n(type 'yes' to confirm)\n", ID);
+ BOX_WARNING("Really delete account " <<
+ BOX_FORMAT_ACCOUNT(ID) << "? (type 'yes' to confirm)");
char response[256];
if(::fgets(response, sizeof(response), stdin) == 0 || ::strcmp(response, "yes\n") != 0)
{
- printf("Deletion cancelled\n");
+ BOX_NOTICE("Deletion cancelled.");
return 0;
}
}
@@ -256,7 +264,8 @@ int DeleteAccount(Configuration &rConfig, const std::string &rUsername, int32_t
// Exists?
if(!db->EntryExists(ID))
{
- printf("Account %x does not exist\n", ID);
+ BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) <<
+ " does not exist.");
return 1;
}
@@ -318,24 +327,27 @@ int DeleteAccount(Configuration &rConfig, const std::string &rUsername, int32_t
toDelete.push_back((*i) + DIRECTORY_SEPARATOR + rootDir);
}
}
-
+
+ int retcode = 0;
+
// Thirdly, delete the directories...
for(std::vector<std::string>::const_iterator d(toDelete.begin()); d != toDelete.end(); ++d)
{
- ::printf("Deleting store directory %s...\n", (*d).c_str());
+ BOX_NOTICE("Deleting store directory " << (*d) << "...");
// Just use the rm command to delete the files
std::string cmd("rm -rf ");
cmd += *d;
// Run command
if(::system(cmd.c_str()) != 0)
{
- ::printf("ERROR: Deletion of %s failed.\n(when cleaning up, remember to delete all raid directories)\n", (*d).c_str());
- return 1;
+ BOX_ERROR("Failed to delete files in " << (*d) <<
+ ", delete them manually.");
+ retcode = 1;
}
}
// Success!
- return 0;
+ return retcode;
}
int CheckAccount(Configuration &rConfig, const std::string &rUsername, int32_t ID, bool FixErrors, bool Quiet)
@@ -346,7 +358,8 @@ int CheckAccount(Configuration &rConfig, const std::string &rUsername, int32_t I
// Exists?
if(!db->EntryExists(ID))
{
- printf("Account %x does not exist\n", ID);
+ BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) <<
+ " does not exist.");
return 1;
}
@@ -381,7 +394,8 @@ int CreateAccount(Configuration &rConfig, const std::string &rUsername, int32_t
// Already exists?
if(db->EntryExists(ID))
{
- printf("Account %x already exists\n", ID);
+ BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) <<
+ " already exists.");
return 1;
}
@@ -389,7 +403,7 @@ int CreateAccount(Configuration &rConfig, const std::string &rUsername, int32_t
BackupStoreAccounts acc(*db);
acc.Create(ID, DiscNumber, SoftLimit, HardLimit, rUsername);
- printf("Account %x created\n", ID);
+ BOX_NOTICE("Account " << BOX_FORMAT_ACCOUNT(ID) << " created.");
return 0;
}
@@ -444,7 +458,8 @@ int main(int argc, const char *argv[])
if(config.get() == 0 || !errs.empty())
{
- printf("Invalid configuration file:\n%s", errs.c_str());
+ BOX_ERROR("Invalid configuration file " << configFilename <<
+ ":" << errs);
}
// Get the user under which the daemon runs
@@ -484,7 +499,8 @@ int main(int argc, const char *argv[])
if(argc < 5
|| ::sscanf(argv[2], "%d", &discnum) != 1)
{
- printf("create requires raid file disc number, soft and hard limits\n");
+ BOX_ERROR("create requires raid file disc number, "
+ "soft and hard limits.");
return 1;
}
@@ -506,7 +522,7 @@ int main(int argc, const char *argv[])
// Change the limits on this account
if(argc < 4)
{
- printf("setlimit requires soft and hard limits\n");
+ BOX_ERROR("setlimit requires soft and hard limits.");
return 1;
}
@@ -540,7 +556,7 @@ int main(int argc, const char *argv[])
}
else
{
- ::printf("Unknown option %s.\n", argv[o]);
+ BOX_ERROR("Unknown option " << argv[o] << ".");
return 2;
}
}
@@ -550,7 +566,7 @@ int main(int argc, const char *argv[])
}
else
{
- printf("Unknown command '%s'\n", argv[0]);
+ BOX_ERROR("Unknown command '" << argv[0] << "'.");
return 1;
}