[Box Backup-dev] COMMIT r754 - box/chris/merge/bin/bbackupquery

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Wed Aug 9 19:50:20 BST 2006


Author: chris
Date: 2006-08-09 18:50:19 +0000 (Wed, 09 Aug 2006)
New Revision: 754

Modified:
   box/chris/merge/bin/bbackupquery/BackupQueries.cpp
Log:
* bin/bbackupquery/BackupQueries.cpp
- Revert to trunk


Modified: box/chris/merge/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/chris/merge/bin/bbackupquery/BackupQueries.cpp	2006-08-09 18:46:23 UTC (rev 753)
+++ box/chris/merge/bin/bbackupquery/BackupQueries.cpp	2006-08-09 18:50:19 UTC (rev 754)
@@ -70,11 +70,7 @@
 	  mWarnedAboutOwnerAttributes(false),
 	  mReturnCode(0)		// default return code
 {
-	#ifdef WIN32
-	mRunningAsRoot = TRUE;
-	#else
 	mRunningAsRoot = (::geteuid() == 0);
-	#endif
 }
 
 // --------------------------------------------------------------------------
@@ -89,12 +85,6 @@
 {
 }
 
-typedef struct cmd_info
-{
-	const char* name;
-	const char* opts;
-} cmd_info_t;
-
 // --------------------------------------------------------------------------
 //
 // Function
@@ -172,24 +162,8 @@
 	}
 	
 	// 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 @@
 	
 	// 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 @@
 		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 @@
 	#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 @@
 // --------------------------------------------------------------------------
 //
 // 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 @@
 			}
 		}
 		
-		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 @@
 	}
 
 	// 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 @@
 		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 @@
 		{				
 			// 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 @@
 	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 @@
 		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 @@
 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 @@
 	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 @@
 		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 @@
 				"(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 @@
 	{
 		printf("ERROR: opendir on local dir '%s'\n", 
 			localDirDisplay.c_str());
-		rParams.mUncheckedFiles ++;
 		return;
 	}
 	try
@@ -1538,12 +1455,11 @@
 						}
 						
 						// 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 @@
 						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 @@
 		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;




More information about the Boxbackup-dev mailing list