[Box Backup-commit] COMMIT r1210 - box/trunk/bin/bbackupquery
boxbackup-dev at fluffy.co.uk
boxbackup-dev at fluffy.co.uk
Thu Dec 14 23:20:36 GMT 2006
Author: chris
Date: 2006-12-14 23:20:36 +0000 (Thu, 14 Dec 2006)
New Revision: 1210
Modified:
box/trunk/bin/bbackupquery/BackupQueries.cpp
box/trunk/bin/bbackupquery/BackupQueries.h
box/trunk/bin/bbackupquery/bbackupquery.cpp
Log:
* Convert command-line arguments from the system locale/character set to
the console character set (code page), so they they can be converted from
console to UTF-8 (yuck).
* Don't try to read from stdin or change its code page when it's not open
(invalid file handle)
(merges [1050]+[1051])
Modified: box/trunk/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/trunk/bin/bbackupquery/BackupQueries.cpp 2006-12-14 23:10:33 UTC (rev 1209)
+++ box/trunk/bin/bbackupquery/BackupQueries.cpp 2006-12-14 23:20:36 UTC (rev 1210)
@@ -102,12 +102,12 @@
// --------------------------------------------------------------------------
//
// Function
-// Name: BackupQueries::DoCommand(const char *)
+// Name: BackupQueries::DoCommand(const char *, bool)
// Purpose: Perform a command
// Created: 2003/10/10
//
// --------------------------------------------------------------------------
-void BackupQueries::DoCommand(const char *Command)
+void BackupQueries::DoCommand(const char *Command, bool isFromCommandLine)
{
// is the command a shell command?
if(Command[0] == 's' && Command[1] == 'h' && Command[2] == ' ' && Command[3] != '\0')
@@ -168,6 +168,25 @@
if(!s.empty()) cmdElements.push_back(s);
}
+ #ifdef WIN32
+ if (isFromCommandLine)
+ {
+ for (std::vector<std::string>::iterator
+ i = cmdElements.begin();
+ i != cmdElements.end(); i++)
+ {
+ std::string converted;
+ if (!ConvertEncoding(*i, CP_ACP, converted,
+ GetConsoleCP()))
+ {
+ printf("Failed to convert encoding");
+ return;
+ }
+ *i = converted;
+ }
+ }
+ #endif
+
// Check...
if(cmdElements.size() < 1)
{
@@ -394,7 +413,7 @@
// --------------------------------------------------------------------------
//
// Function
-// Name: BackupQueries::List(int64_t, const std::string &, const bool *)
+// Name: BackupQueries::List(int64_t, const std::string &, const bool *, bool)
// Purpose: Do the actual listing of directories and files
// Created: 2003/10/10
//
@@ -871,7 +890,7 @@
// Created: 2003/10/12
//
// --------------------------------------------------------------------------
-void BackupQueries::CommandGet(const std::vector<std::string> &args, const bool *opts)
+void BackupQueries::CommandGet(std::vector<std::string> args, const bool *opts)
{
// At least one argument?
// Check args
@@ -888,6 +907,43 @@
std::string localName;
// BLOCK
{
+#ifdef WIN32
+ for (std::vector<std::string>::iterator
+ i = args.begin(); i != args.end(); i++)
+ {
+ std::string out;
+ if(!ConvertConsoleToUtf8(i->c_str(), out))
+ {
+ fprintf(stderr, "failed to convert encoding\n");
+ return;
+ }
+ *i = out;
+ }
+#endif
+
+ std::string fileName(args[0]);
+
+ 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(),
@@ -924,14 +980,6 @@
{
// 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)
Modified: box/trunk/bin/bbackupquery/BackupQueries.h
===================================================================
--- box/trunk/bin/bbackupquery/BackupQueries.h 2006-12-14 23:10:33 UTC (rev 1209)
+++ box/trunk/bin/bbackupquery/BackupQueries.h 2006-12-14 23:20:36 UTC (rev 1210)
@@ -36,7 +36,7 @@
BackupQueries(const BackupQueries &);
public:
- void DoCommand(const char *Command);
+ void DoCommand(const char *Command, bool isFromCommandLine);
// Ready to stop?
bool Stop() {return mQuitNow;}
@@ -50,7 +50,7 @@
void CommandChangeDir(const std::vector<std::string> &args, const bool *opts);
void CommandChangeLocalDir(const std::vector<std::string> &args);
void CommandGetObject(const std::vector<std::string> &args, const bool *opts);
- void CommandGet(const std::vector<std::string> &args, const bool *opts);
+ void CommandGet(std::vector<std::string> args, const bool *opts);
void CommandCompare(const std::vector<std::string> &args, const bool *opts);
void CommandRestore(const std::vector<std::string> &args, const bool *opts);
void CommandUndelete(const std::vector<std::string> &args, const bool *opts);
Modified: box/trunk/bin/bbackupquery/bbackupquery.cpp
===================================================================
--- box/trunk/bin/bbackupquery/bbackupquery.cpp 2006-12-14 23:10:33 UTC (rev 1209)
+++ box/trunk/bin/bbackupquery/bbackupquery.cpp 2006-12-14 23:20:36 UTC (rev 1210)
@@ -171,7 +171,8 @@
}
// enable input of Unicode characters
- if (_setmode(_fileno(stdin), _O_TEXT) == -1)
+ if (_fileno(stdin) != -1 &&
+ _setmode(_fileno(stdin), _O_TEXT) == -1)
{
perror("Failed to set the console input to "
"binary mode");
@@ -245,7 +246,7 @@
int c = 0;
while(c < argc && !context.Stop())
{
- context.DoCommand(argv[c++]);
+ context.DoCommand(argv[c++], true);
}
}
@@ -263,7 +264,7 @@
// Ctrl-D pressed -- terminate now
break;
}
- context.DoCommand(command);
+ context.DoCommand(command, false);
if(last_cmd != 0 && ::strcmp(last_cmd, command) == 0)
{
free(command);
@@ -284,13 +285,16 @@
#endif
#else
// Version for platforms which don't have readline by default
- FdGetLine getLine(fileno(stdin));
- while(!context.Stop())
+ if(fileno(stdin) >= 0)
{
- printf("query > ");
- fflush(stdout);
- std::string command(getLine.GetLine());
- context.DoCommand(command.c_str());
+ FdGetLine getLine(fileno(stdin));
+ while(!context.Stop())
+ {
+ printf("query > ");
+ fflush(stdout);
+ std::string command(getLine.GetLine());
+ context.DoCommand(command.c_str(), false);
+ }
}
#endif
More information about the Boxbackup-commit
mailing list