From a2c4bfae39d3c6da32f804d0dcc11e3981b3c2b4 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 15 Oct 2006 18:51:44 +0000 Subject: Allow getting an object with a path, not just from the current directory (refs #3) --- bin/bbackupquery/BackupQueries.cpp | 65 +++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 12 deletions(-) (limited to 'bin/bbackupquery/BackupQueries.cpp') diff --git a/bin/bbackupquery/BackupQueries.cpp b/bin/bbackupquery/BackupQueries.cpp index 4ab09a3a..6f075254 100644 --- a/bin/bbackupquery/BackupQueries.cpp +++ b/bin/bbackupquery/BackupQueries.cpp @@ -884,13 +884,44 @@ void BackupQueries::CommandGet(const std::vector &args, const bool } // Find object ID somehow - int64_t id; + int64_t fileId; + int64_t dirId = GetCurrentDirectoryID(); 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( - GetCurrentDirectoryID(), + dirId, 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 */); @@ -903,17 +934,23 @@ void BackupQueries::CommandGet(const std::vector &args, const bool if(opts['i']) { // Specified as ID. - id = ::strtoll(args[0].c_str(), 0, 16); - if(id == std::numeric_limits::min() || id == std::numeric_limits::max() || id == 0) + fileId = ::strtoll(args[0].c_str(), 0, 16); + if(fileId == std::numeric_limits::min() || + fileId == std::numeric_limits::max() || + fileId == 0) { printf("Not a valid object ID (specified in hex)\n"); return; } // Check that the item is actually in the directory - if(dir.FindEntryByID(id) == 0) + if(dir.FindEntryByID(fileId) == 0) { - printf("ID '%08llx' not found in current directory on store.\n(You can only download objects by ID from the current directory.)\n", id); + printf("ID '%08llx' not found in current " + "directory on store.\n" + "(You can only download objects by ID " + "from the current directory.)\n", + fileId); return; } @@ -936,14 +973,18 @@ void BackupQueries::CommandGet(const std::vector &args, const bool 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; } - id = en->GetObjectID(); + fileId = 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]; } } @@ -960,7 +1001,7 @@ void BackupQueries::CommandGet(const std::vector &args, const bool try { // Request object - mrConnection.QueryGetFile(GetCurrentDirectoryID(), id); + mrConnection.QueryGetFile(dirId, fileId); // Stream containing encoded file std::auto_ptr objectStream(mrConnection.ReceiveStream()); @@ -969,7 +1010,7 @@ void BackupQueries::CommandGet(const std::vector &args, const bool BackupStoreFile::DecodeFile(*objectStream, localName.c_str(), mrConnection.GetTimeout()); // Done. - printf("Object ID %08llx fetched sucessfully.\n", id); + printf("Object ID %08llx fetched sucessfully.\n", fileId); } catch(...) { -- cgit v1.2.3