summaryrefslogtreecommitdiff
path: root/bin/bbackupquery
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2006-08-09 18:50:19 +0000
committerChris Wilson <chris+github@qwirx.com>2006-08-09 18:50:19 +0000
commit298e354911fad55469a99c254cf8fc47be77d580 (patch)
treeb292b1a928aa510c9f6d38684a8bb46c5534d605 /bin/bbackupquery
parentd36cf5c650533abc3d940dde160ee1a0c529876d (diff)
* bin/bbackupquery/BackupQueries.cpp
- Revert to trunk
Diffstat (limited to 'bin/bbackupquery')
-rw-r--r--bin/bbackupquery/BackupQueries.cpp168
1 files changed, 37 insertions, 131 deletions
diff --git a/bin/bbackupquery/BackupQueries.cpp b/bin/bbackupquery/BackupQueries.cpp
index 05e34b7e..1e792bdc 100644
--- a/bin/bbackupquery/BackupQueries.cpp
+++ b/bin/bbackupquery/BackupQueries.cpp
@@ -70,11 +70,7 @@ BackupQueries::BackupQueries(BackupProtocolClient &rConnection, const Configurat
mWarnedAboutOwnerAttributes(false),
mReturnCode(0) // default return code
{
- #ifdef WIN32
- mRunningAsRoot = TRUE;
- #else
mRunningAsRoot = (::geteuid() == 0);
- #endif
}
// --------------------------------------------------------------------------
@@ -89,12 +85,6 @@ BackupQueries::~BackupQueries()
{
}
-typedef struct cmd_info
-{
- const char* name;
- const char* opts;
-} cmd_info_t;
-
// --------------------------------------------------------------------------
//
// Function
@@ -172,24 +162,8 @@ void BackupQueries::DoCommand(const char *Command)
}
// Data about commands
- static cmd_info_t commands[] =
- {
- { "quit", "" },
- { "exit", "" },
- { "list", "rodIFtTsh", },
- { "pwd", "" },
- { "cd", "od" },
- { "lcd", "" },
- { "sh", "" },
- { "getobject", "" },
- { "get", "i" },
- { "compare", "alcqAE" },
- { "restore", "dri" },
- { "help", "" },
- { "usage", "" },
- { "undelete", "" },
- { NULL, NULL }
- };
+ static const char *commandNames[] = {"quit", "exit", "list", "pwd", "cd", "lcd", "sh", "getobject", "get", "compare", "restore", "help", "usage", "undelete", 0};
+ static const char *validOptions[] = {"", "", "rodIFtsh", "", "od", "", "", "", "i", "alcqE", "dri", "", "", "", 0};
#define COMMAND_Quit 0
#define COMMAND_Exit 1
#define COMMAND_List 2
@@ -209,11 +183,11 @@ void BackupQueries::DoCommand(const char *Command)
// Work out which command it is...
int cmd = 0;
- while(commands[cmd].name != 0 && ::strcmp(cmdElements[0].c_str(), commands[cmd].name) != 0)
+ while(commandNames[cmd] != 0 && ::strcmp(cmdElements[0].c_str(), commandNames[cmd]) != 0)
{
cmd++;
}
- if(commands[cmd].name == 0)
+ if(commandNames[cmd] == 0)
{
// Check for aliases
int a;
@@ -248,10 +222,9 @@ void BackupQueries::DoCommand(const char *Command)
while(*c != 0)
{
// Valid option?
- if(::strchr(commands[cmd].opts, *c) == NULL)
+ if(::strchr(validOptions[cmd], *c) == NULL)
{
- printf("Invalid option '%c' for command %s\n",
- *c, commands[cmd].name);
+ printf("Invalid option '%c' for command %s\n", *c, commandNames[cmd]);
return;
}
opts[(int)*c] = true;
@@ -346,9 +319,8 @@ void BackupQueries::CommandList(const std::vector<std::string> &args, const bool
#define LIST_OPTION_ALLOWOLD 'o'
#define LIST_OPTION_ALLOWDELETED 'd'
#define LIST_OPTION_NOOBJECTID 'I'
- #define LIST_OPTION_NOFLAGS 'F'
- #define LIST_OPTION_TIMES_LOCAL 't'
- #define LIST_OPTION_TIMES_UTC 'T'
+ #define LIST_OPTION_NOFLAGS 'F'
+ #define LIST_OPTION_TIMES 't'
#define LIST_OPTION_SIZEINBLOCKS 's'
#define LIST_OPTION_DISPLAY_HASH 'h'
@@ -390,7 +362,7 @@ void BackupQueries::CommandList(const std::vector<std::string> &args, const bool
// --------------------------------------------------------------------------
//
// Function
-// Name: BackupQueries::List(int64_t, const std::string &, const bool *, bool)
+// Name: BackupQueries::List(int64_t, const std::string &, const bool *)
// Purpose: Do the actual listing of directories and files
// Created: 2003/10/10
//
@@ -465,9 +437,9 @@ void BackupQueries::List(int64_t DirID, const std::string &rListRoot, const bool
}
}
- if(opts[LIST_OPTION_TIMES_LOCAL])
+ if(opts[LIST_OPTION_TIMES])
{
- // Show local times...
+ // Show times...
std::string time = BoxTimeToISO8601String(
en->GetModificationTime());
printf("%s ", time.c_str());
@@ -872,44 +844,13 @@ void BackupQueries::CommandGet(const std::vector<std::string> &args, const bool
}
// Find object ID somehow
- int64_t fileId;
- int64_t dirId = GetCurrentDirectoryID();
+ int64_t id;
std::string localName;
-
// BLOCK
{
-#ifdef WIN32
- std::string fileName;
- if(!ConvertConsoleToUtf8(args[0].c_str(), fileName))
- return;
-#else
- std::string fileName(args[0]);
-#endif
-
- if(!opts['i'])
- {
- // does this remote filename include a path?
- std::string::size_type index = fileName.rfind('/');
- if(index != std::string::npos)
- {
- std::string dirName(fileName.substr(0, index));
- fileName = fileName.substr(index + 1);
-
- dirId = FindDirectoryObjectID(dirName);
- if(dirId == 0)
- {
- printf("Directory '%s' not found\n",
- dirName.c_str());
- return;
- }
- }
- }
-
- BackupStoreFilenameClear fn(fileName);
-
// Need to look it up in the current directory
mrConnection.QueryListDirectory(
- dirId,
+ GetCurrentDirectoryID(),
BackupProtocolClientListDirectory::Flags_File, // just files
(opts['i'])?(BackupProtocolClientListDirectory::Flags_EXCLUDE_NOTHING):(BackupProtocolClientListDirectory::Flags_OldVersion | BackupProtocolClientListDirectory::Flags_Deleted), // only current versions
false /* don't want attributes */);
@@ -922,23 +863,17 @@ void BackupQueries::CommandGet(const std::vector<std::string> &args, const bool
if(opts['i'])
{
// Specified as ID.
- fileId = ::strtoll(args[0].c_str(), 0, 16);
- if(fileId == std::numeric_limits<long long>::min() ||
- fileId == std::numeric_limits<long long>::max() ||
- fileId == 0)
+ 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");
return;
}
// Check that the item is actually in the directory
- if(dir.FindEntryByID(fileId) == 0)
+ if(dir.FindEntryByID(id) == 0)
{
- printf("ID '%08llx' not found in current "
- "directory on store.\n"
- "(You can only download objects by ID "
- "from the current directory.)\n",
- fileId);
+ printf("ID '%08llx' not found in current directory on store.\n(You can only download objects by ID from the current directory.)\n", id);
return;
}
@@ -949,22 +884,26 @@ void BackupQueries::CommandGet(const std::vector<std::string> &args, const bool
{
// Specified by name, find the object in the directory to get the ID
BackupStoreDirectory::Iterator i(dir);
+#ifdef WIN32
+ std::string fileName;
+ if(!ConvertConsoleToUtf8(args[0].c_str(), fileName))
+ return;
+ BackupStoreFilenameClear fn(fileName);
+#else
+ BackupStoreFilenameClear fn(args[0]);
+#endif
BackupStoreDirectory::Entry *en = i.FindMatchingClearName(fn);
if(en == 0)
{
- printf("Filename '%s' not found in current "
- "directory on store.\n"
- "(Subdirectories in path not "
- "searched.)\n", args[0].c_str());
+ printf("Filename '%s' not found in current directory on store.\n(Subdirectories in path not searched.)\n", args[0].c_str());
return;
}
- fileId = en->GetObjectID();
+ id = en->GetObjectID();
- // Local name is the last argument, which is either
- // the looked up filename, or a filename specified
- // by the user.
+ // Local name is the last argument, which is either the looked up filename, or
+ // a filename specified by the user.
localName = args[args.size() - 1];
}
}
@@ -981,7 +920,7 @@ void BackupQueries::CommandGet(const std::vector<std::string> &args, const bool
try
{
// Request object
- mrConnection.QueryGetFile(dirId, fileId);
+ mrConnection.QueryGetFile(GetCurrentDirectoryID(), id);
// Stream containing encoded file
std::auto_ptr<IOStream> objectStream(mrConnection.ReceiveStream());
@@ -990,7 +929,7 @@ void BackupQueries::CommandGet(const std::vector<std::string> &args, const bool
BackupStoreFile::DecodeFile(*objectStream, localName.c_str(), mrConnection.GetTimeout());
// Done.
- printf("Object ID %08llx fetched sucessfully.\n", fileId);
+ printf("Object ID %08llx fetched sucessfully.\n", id);
}
catch(...)
{
@@ -1011,10 +950,8 @@ void BackupQueries::CommandGet(const std::vector<std::string> &args, const bool
BackupQueries::CompareParams::CompareParams()
: mQuickCompare(false),
mIgnoreExcludes(false),
- mIgnoreAttributes(false),
mDifferences(0),
mDifferencesExplainedByModTime(0),
- mUncheckedFiles(0),
mExcludedDirs(0),
mExcludedFiles(0),
mpExcludeFiles(0),
@@ -1075,7 +1012,6 @@ void BackupQueries::CommandCompare(const std::vector<std::string> &args, const b
BackupQueries::CompareParams params;
params.mQuickCompare = opts['q'];
params.mIgnoreExcludes = opts['E'];
- params.mIgnoreAttributes = opts['A'];
// Try and work out the time before which all files should be on the server
{
@@ -1138,29 +1074,13 @@ void BackupQueries::CommandCompare(const std::vector<std::string> &args, const b
return;
}
- printf("\n[ %d (of %d) differences probably due to file "
- "modifications after the last upload ]\n"
- "Differences: %d (%d dirs excluded, %d files excluded, "
- "%d files not checked)\n",
- params.mDifferencesExplainedByModTime, params.mDifferences,
- params.mDifferences, params.mExcludedDirs,
- params.mExcludedFiles, params.mUncheckedFiles);
+ printf("\n[ %d (of %d) differences probably due to file modifications after the last upload ]\nDifferences: %d (%d dirs excluded, %d files excluded)\n",
+ params.mDifferencesExplainedByModTime, params.mDifferences, params.mDifferences, params.mExcludedDirs, params.mExcludedFiles);
// Set return code?
if(opts['c'])
{
- if (params.mUncheckedFiles != 0)
- {
- SetReturnCode(COMPARE_RETURN_ERROR);
- }
- else if (params.mDifferences != 0)
- {
- SetReturnCode(COMPARE_RETURN_DIFFERENT);
- }
- else
- {
- SetReturnCode(COMPARE_RETURN_SAME);
- }
+ SetReturnCode((params.mDifferences == 0)?COMPARE_RETURN_SAME:COMPARE_RETURN_DIFFERENT);
}
}
@@ -1294,13 +1214,11 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
"(compared to server directory '%s')\n",
localDirDisplay.c_str(),
storeDirDisplay.c_str());
- rParams.mDifferences ++;
}
else
{
printf("ERROR: stat on local dir '%s'\n",
localDirDisplay.c_str());
- rParams.mUncheckedFiles ++;
}
return;
}
@@ -1350,7 +1268,6 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
{
printf("ERROR: opendir on local dir '%s'\n",
localDirDisplay.c_str());
- rParams.mUncheckedFiles ++;
return;
}
try
@@ -1538,12 +1455,11 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
}
// Compare attributes
- box_time_t fileModTime = 0;
BackupClientFileAttributes localAttr;
+ box_time_t fileModTime = 0;
localAttr.ReadAttributes(localPath.c_str(), false /* don't zero mod times */, &fileModTime);
modifiedAfterLastSync = (fileModTime > rParams.mLatestFileUploadTime);
- if(!rParams.mIgnoreAttributes &&
- !localAttr.Compare(fileOnServerStream->GetAttributes(),
+ if(!localAttr.Compare(fileOnServerStream->GetAttributes(),
true /* ignore attr mod time */,
fileOnServerStream->IsSymLink() /* ignore modification time if it's a symlink */))
{
@@ -1638,12 +1554,10 @@ void BackupQueries::Compare(int64_t DirID, const std::string &rStoreDir, const s
e.GetType(),
e.GetSubType(),
storePathDisplay.c_str());
- rParams.mUncheckedFiles ++;
}
catch(...)
- {
+ {
printf("ERROR: (unknown) during file fetch and comparison for '%s'\n", storePathDisplay.c_str());
- rParams.mUncheckedFiles ++;
}
// Remove from set so that we know it's been compared
@@ -1879,14 +1793,6 @@ void BackupQueries::CommandRestore(const std::vector<std::string> &args, const b
printf("The target directory exists. You cannot restore over an existing directory.\n");
break;
- #ifdef WIN32
- case Restore_TargetPathNotFound:
- printf("The target directory path does not exist.\n"
- "To restore to a directory whose parent "
- "does not exist, create the parent first.\n");
- break;
- #endif
-
default:
printf("ERROR: Unknown restore result.\n");
break;