Changeset 1790 for box/chris/general/bin/bbackupquery/BackupQueries.cpp
- Timestamp:
- 03/08/2007 00:29:31 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
box/chris/general/bin/bbackupquery/BackupQueries.cpp
r1784 r1790 182 182 GetConsoleCP())) 183 183 { 184 printf("Failed to convert encoding");184 BOX_ERROR("Failed to convert encoding"); 185 185 return; 186 186 } … … 256 256 if(alias[a] == 0) 257 257 { 258 printf("Unrecognised command: %s\n",Command);258 BOX_ERROR("Unrecognised command: " << Command); 259 259 return; 260 260 } … … 276 276 if(::strchr(commands[cmd].opts, *c) == NULL) 277 277 { 278 printf("Invalid option '%c' for command %s\n",279 *c,commands[cmd].name);278 BOX_ERROR("Invalid option '" << *c << "' for " 279 "command " << commands[cmd].name); 280 280 return; 281 281 } … … 306 306 { 307 307 // Simple implementation, so do it here 308 printf("%s (%08llx)\n", 309 GetCurrentDirectoryName().c_str(), 310 (long long)GetCurrentDirectoryID()); 308 BOX_INFO(GetCurrentDirectoryName() << " (" << 309 BOX_FORMAT_OBJECTID(GetCurrentDirectoryID())); 311 310 } 312 311 break; … … 321 320 322 321 case COMMAND_sh: 323 printf("The command to run must be specified as an argument.\n");322 BOX_ERROR("The command to run must be specified as an argument."); 324 323 break; 325 324 … … 402 401 if(rootDir == 0) 403 402 { 404 printf("Directory '%s' not found on store\n",405 args[0].c_str());403 BOX_ERROR("Directory '" << args[0] << "' not found " 404 "on store."); 406 405 return; 407 406 } … … 748 747 if(args.size() != 1 || args[0].size() == 0) 749 748 { 750 printf("Incorrect usage.\ncd [-o] [-d] <directory>\n");749 BOX_ERROR("Incorrect usage. cd [-o] [-d] <directory>"); 751 750 return; 752 751 } … … 765 764 if(id == 0) 766 765 { 767 printf("Directory '%s' not found\n", args[0].c_str());766 BOX_ERROR("Directory '" << args[0] << "' not found."); 768 767 return; 769 768 } … … 786 785 if(args.size() != 1 || args[0].size() == 0) 787 786 { 788 printf("Incorrect usage.\nlcd <local-directory>\n");787 BOX_ERROR("Incorrect usage. lcd <local-directory>"); 789 788 SetReturnCode(COMMAND_RETURN_ERROR); 790 789 return; … … 796 795 if(!ConvertConsoleToUtf8(args[0].c_str(), dirName)) 797 796 { 798 printf("Failed to convert path from console encoding.\n");797 BOX_ERROR("Failed to convert path from console encoding."); 799 798 SetReturnCode(COMMAND_RETURN_ERROR); 800 799 return; … … 806 805 if(result != 0) 807 806 { 808 printf((errno == ENOENT || errno == ENOTDIR)?"Directory '%s' does not exist\n":"Error changing dir to '%s'\n", 809 args[0].c_str()); 807 if(errno == ENOENT || errno == ENOTDIR) 808 { 809 BOX_ERROR("Directory '" << args[0] << "' does not exist."); 810 } 811 else 812 { 813 BOX_ERROR("Error changing to directory '" << 814 args[0] << ": " << strerror(errno)); 815 } 816 810 817 SetReturnCode(COMMAND_RETURN_ERROR); 811 818 return; … … 816 823 if(::getcwd(wd, PATH_MAX) == 0) 817 824 { 818 printf("Error getting current directory\n"); 825 BOX_ERROR("Error getting current directory: " << 826 strerror(errno)); 819 827 SetReturnCode(COMMAND_RETURN_ERROR); 820 828 return; … … 824 832 if(!ConvertUtf8ToConsole(wd, dirName)) 825 833 { 826 printf("Failed to convert new path from console encoding.\n");834 BOX_ERROR("Failed to convert new path from console encoding."); 827 835 SetReturnCode(COMMAND_RETURN_ERROR); 828 836 return; 829 837 } 830 printf("Local current directory is now '%s'\n", dirName.c_str());838 BOX_INFO("Local current directory is now '" << dirName << "'."); 831 839 #else 832 printf("Local current directory is now '%s'\n", wd);840 BOX_INFO("Local current directory is now '" << wd << "'."); 833 841 #endif 834 842 } … … 848 856 if(args.size() != 2) 849 857 { 850 printf("Incorrect usage.\ngetobject <object-id> <local-filename>\n"); 858 BOX_ERROR("Incorrect usage. getobject <object-id> " 859 "<local-filename>"); 851 860 return; 852 861 } … … 855 864 if(id == std::numeric_limits<long long>::min() || id == std::numeric_limits<long long>::max() || id == 0) 856 865 { 857 printf("Not a valid object ID (specified in hex)\n");866 BOX_ERROR("Not a valid object ID (specified in hex)."); 858 867 return; 859 868 } … … 863 872 if(::stat(args[1].c_str(), &st) == 0 || errno != ENOENT) 864 873 { 865 printf("The local file %s already exists\n", args[1].c_str());874 BOX_ERROR("The local file '" << args[1] << " already exists."); 866 875 return; 867 876 } … … 881 890 objectStream->CopyStreamTo(out); 882 891 883 printf("Object ID %08llx fetched successfully.\n", id); 892 BOX_INFO("Object ID " << BOX_FORMAT_OBJECTID(id) << 893 " fetched successfully."); 884 894 } 885 895 else 886 896 { 887 printf("Object does not exist on store.\n"); 897 BOX_ERROR("Object ID " << BOX_FORMAT_OBJECTID(id) << 898 " does not exist on store."); 888 899 ::unlink(args[1].c_str()); 889 900 } … … 892 903 { 893 904 ::unlink(args[1].c_str()); 894 printf("Error occured fetching object.\n");905 BOX_ERROR("Error occured fetching object."); 895 906 } 896 907 } … … 912 923 if(args.size() < 1 || (opts['i'] && args.size() != 2) || args.size() > 2) 913 924 { 914 printf("Incorrect usage.\n"925 BOX_ERROR("Incorrect usage.\n" 915 926 "get <remote-filename> [<local-filename>] or\n" 916 "get -i <object-id> <local-filename> \n");927 "get -i <object-id> <local-filename>"); 917 928 return; 918 929 } … … 932 943 if(!ConvertConsoleToUtf8(i->c_str(), out)) 933 944 { 934 fprintf(stderr, "failed to convert encoding\n");945 BOX_ERROR("Failed to convert encoding."); 935 946 return; 936 947 } … … 953 964 if(dirId == 0) 954 965 { 955 printf("Directory '%s' not found\n",956 dirName.c_str());966 BOX_ERROR("Directory '" << dirName << 967 "' not found."); 957 968 return; 958 969 } … … 982 993 fileId == 0) 983 994 { 984 printf("Not a valid object ID (specified in hex)\n");995 BOX_ERROR("Not a valid object ID (specified in hex)."); 985 996 return; 986 997 } … … 989 1000 if(dir.FindEntryByID(fileId) == 0) 990 1001 { 991 printf("ID '%08llx' not found in current " 1002 BOX_ERROR("File ID " << 1003 BOX_FORMAT_OBJECTID(fileId) << 1004 " not found in current " 992 1005 "directory on store.\n" 993 "(You can only download objects by ID " 994 "from the current directory.)\n", 995 fileId); 1006 "(You can only download files by ID " 1007 "from the current directory.)"); 996 1008 return; 997 1009 } … … 1008 1020 if(en == 0) 1009 1021 { 1010 printf("Filename '%s' not found in current " 1022 BOX_ERROR("Filename '" << args[0] << "' " 1023 "not found in current " 1011 1024 "directory on store.\n" 1012 1025 "(Subdirectories in path not " 1013 "searched.) \n", args[0].c_str());1026 "searched.)"); 1014 1027 return; 1015 1028 } … … 1028 1041 if(::stat(localName.c_str(), &st) == 0 || errno != ENOENT) 1029 1042 { 1030 printf("The local file %s already exists, will not"1031 " overwrite it.\n", localName.c_str());1043 BOX_ERROR("The local file " << localName << " already exists, " 1044 "will not overwrite it."); 1032 1045 SetReturnCode(COMMAND_RETURN_ERROR); 1033 1046 return; … … 1047 1060 1048 1061 // Done. 1049 printf("Object ID %08llx fetched sucessfully.\n", fileId); 1062 BOX_INFO("Object ID " << BOX_FORMAT_OBJECTID(fileId) << 1063 " fetched successfully."); 1050 1064 } 1051 1065 catch (BoxException &e) … … 1161 1175 else 1162 1176 { 1163 printf("Warning: couldn't determine the time of the last synchronisation -- checks not performed.\n"); 1177 BOX_WARNING("Failed to determine the time of the last " 1178 "synchronisation -- checks not performed."); 1164 1179 } 1165 1180 } … … 1168 1183 if(params.mQuickCompare) 1169 1184 { 1170 printf("WARNING: Quick compare used -- file attributes are not checked.\n"); 1185 BOX_WARNING("Quick compare used -- file attributes are not " 1186 "checked."); 1171 1187 } 1172 1188 … … 1193 1209 if(!params.mIgnoreExcludes) 1194 1210 { 1195 printf("Cannot use excludes on directory to directory comparison -- use -E flag to specify ignored excludes\n");1211 BOX_ERROR("Cannot use excludes on directory to directory comparison -- use -E flag to specify ignored excludes."); 1196 1212 return; 1197 1213 } … … 1204 1220 else 1205 1221 { 1206 printf("Incorrect usage.\ncompare -a\n or compare -l <location-name>\n or compare <store-dir-name> <local-dir-name>\n");1222 BOX_ERROR("Incorrect usage.\ncompare -a\n or compare -l <location-name>\n or compare <store-dir-name> <local-dir-name>"); 1207 1223 return; 1208 1224 } … … 1210 1226 if (!params.mQuietCompare) 1211 1227 { 1212 printf("\n[ %d (of %d) differences probably due to file "1213 "modifications after the last upload ]\n",1214 params.mDifferences ExplainedByModTime,1215 params.mDifferences);1216 } 1217 1218 printf("Differences: %d (%d dirs excluded, %d files excluded, "1219 "%d files not checked)\n",1220 params.m Differences, params.mExcludedDirs,1221 params.m ExcludedFiles, params.mUncheckedFiles);1228 BOX_INFO("[ " << 1229 params.mDifferencesExplainedByModTime << " (of " << 1230 params.mDifferences << ") differences probably " 1231 "due to file modifications after the last upload ]"); 1232 } 1233 1234 BOX_INFO("Differences: " << params.mDifferences << " (" << 1235 params.mExcludedDirs << " dirs excluded, " << 1236 params.mExcludedFiles << " files excluded, " << 1237 params.mUncheckedFiles << " files not checked)"); 1222 1238 1223 1239 // Set return code? … … 1254 1270 if(!locations.SubConfigurationExists(rLocation.c_str())) 1255 1271 { 1256 printf("Location %s does not exist.\n", rLocation.c_str());1272 BOX_ERROR("Location " << rLocation << " does not exist."); 1257 1273 return; 1258 1274 } … … 1265 1281 DIRECTORY_SEPARATOR_ASCHAR) 1266 1282 { 1267 fprintf(stderr, "Warning: location '%s' path ends "1268 "with ' %s', compare may fail!",1269 rLocation.c_str(), DIRECTORY_SEPARATOR);1283 BOX_WARNING("Location '" << rLocation << "' path ends " 1284 "with '" DIRECTORY_SEPARATOR "', " 1285 "compare may fail!"); 1270 1286 } 1271 1287 } … … 1320 1336 if(dirID == 0) 1321 1337 { 1322 printf("Local directory '%s' exists, but"1323 " server directory '%s' does not exist\n",1324 rLocalDir.c_str(), rStoreDir.c_str());1338 BOX_WARNING("Local directory '" << rLocalDir << "' exists, " 1339 "but server directory '" << rStoreDir << "' does not " 1340 "exist."); 1325 1341 rParams.mDifferences ++; 1326 1342 return; … … 1370 1386 if(errno == ENOTDIR) 1371 1387 { 1372 printf("Local object '%s' is a file, " 1373 "server object '%s' is a directory\n", 1374 localDirDisplay.c_str(), 1375 storeDirDisplay.c_str()); 1388 BOX_WARNING("Local object '" << localDirDisplay << "' " 1389 "is a file, server object '" << 1390 storeDirDisplay << "' is a directory."); 1376 1391 rParams.mDifferences ++; 1377 1392 } 1378 1393 else if(errno == ENOENT) 1379 1394 { 1380 printf("Local directory '%s' does not exist " 1381 "(compared to server directory '%s')\n", 1382 localDirDisplay.c_str(), 1383 storeDirDisplay.c_str()); 1395 BOX_WARNING("Local directory '" << localDirDisplay << 1396 "' does not exist (compared to server " 1397 "directory '" << storeDirDisplay << "')."); 1384 1398 rParams.mDifferences ++; 1385 1399 } 1386 1400 else 1387 1401 { 1388 printf("ERROR: stat on local dir '%s'\n", 1389 localDirDisplay.c_str()); 1402 BOX_WARNING("Failed to access local directory '" << 1403 localDirDisplay << ": " << strerror(errno) << 1404 "'."); 1390 1405 rParams.mUncheckedFiles ++; 1391 1406 } … … 1408 1423 if(!dir.HasAttributes()) 1409 1424 { 1410 printf("Store directory '%s' doesn't have attributes.\n",1411 storeDirDisplay.c_str());1425 BOX_WARNING("Store directory '" << storeDirDisplay << "' " 1426 "doesn't have attributes."); 1412 1427 } 1413 1428 else … … 1424 1439 if(!(attr.Compare(localAttr, true, true /* ignore modification times */))) 1425 1440 { 1426 printf("Local directory '%s' has different attributes " 1427 "to store directory '%s'.\n", 1428 localDirDisplay.c_str(), 1429 storeDirDisplay.c_str()); 1441 BOX_WARNING("Local directory '" << localDirDisplay << 1442 "' has different attributes to store " 1443 "directory '" << storeDirDisplay << "'."); 1430 1444 rParams.mDifferences ++; 1431 1445 } … … 1436 1450 if(dirhandle == 0) 1437 1451 { 1438 printf("ERROR: opendir on local dir '%s'\n",1439 localDirDisplay .c_str());1452 BOX_WARNING("Failed to open local directory '" << 1453 localDirDisplay << "': " << strerror(errno)); 1440 1454 rParams.mUncheckedFiles ++; 1441 1455 return; … … 1458 1472 if (localDirEn->d_type != DT_DIR) 1459 1473 { 1460 fprintf(stderr, "ERROR: d_type does"1461 " not really work on your"1462 " platform. Reconfigure Box!\n");1474 BOX_ERROR("d_type does not really " 1475 "work on your platform. " 1476 "Reconfigure Box!"); 1463 1477 return; 1464 1478 } … … 1505 1519 if(::closedir(dirhandle) != 0) 1506 1520 { 1507 printf("ERROR: closedir on local dir '%s'\n",1508 localDirDisplay .c_str());1521 BOX_ERROR("Failed to close local directory '" << 1522 localDirDisplay << "': " << strerror(errno)); 1509 1523 } 1510 1524 dirhandle = 0; … … 1566 1580 { 1567 1581 // Not found -- report 1568 printf("Local file '%s' does not exist, "1569 "but store file '%s' does.\n",1570 localPathDisplay.c_str(),1571 storePathDisplay .c_str());1582 BOX_WARNING("Local file '" << 1583 localDirDisplay << "' does not exist, " 1584 "but store file '" << 1585 storePathDisplay << "' does."); 1572 1586 rParams.mDifferences ++; 1573 1587 } … … 1644 1658 fileOnServerStream->IsSymLink() /* ignore modification time if it's a symlink */)) 1645 1659 { 1646 printf("Local file '%s' " 1647 "has different attributes " 1648 "to store file '%s'.\n", 1649 localPathDisplay.c_str(), 1650 storePathDisplay.c_str()); 1660 BOX_WARNING("Local file '" << 1661 localPathDisplay << 1662 "' has different attributes " 1663 "to store file '" << 1664 storePathDisplay << 1665 "'."); 1651 1666 rParams.mDifferences ++; 1652 1667 if(modifiedAfterLastSync) 1653 1668 { 1654 1669 rParams.mDifferencesExplainedByModTime ++; 1655 printf("(the file above was modified after the last sync time -- might be reason for difference)\n");1670 BOX_INFO("(the file above was modified after the last sync time -- might be reason for difference)"); 1656 1671 } 1657 1672 else if(i->second->HasAttributes()) 1658 1673 { 1659 printf("(the file above has had new attributes applied)\n");1674 BOX_INFO("(the file above has had new attributes applied)\n"); 1660 1675 } 1661 1676 } … … 1723 1738 if(!equal) 1724 1739 { 1725 printf("Local file '%s' " 1740 BOX_WARNING("Local file '" << 1741 localPathDisplay << "' " 1726 1742 "has different contents " 1727 "to store file ' %s'.\n",1728 localPathDisplay.c_str(),1729 storePathDisplay.c_str());1743 "to store file '" << 1744 storePathDisplay << 1745 "'."); 1730 1746 rParams.mDifferences ++; 1731 1747 if(modifiedAfterLastSync) 1732 1748 { 1733 1749 rParams.mDifferencesExplainedByModTime ++; 1734 printf("(the file above was modified after the last sync time -- might be reason for difference)\n");1750 BOX_INFO("(the file above was modified after the last sync time -- might be reason for difference)"); 1735 1751 } 1736 1752 else if(i->second->HasAttributes()) 1737 1753 { 1738 printf("(the file above has had new attributes applied)\n");1754 BOX_INFO("(the file above has had new attributes applied)\n"); 1739 1755 } 1740 1756 } … … 1795 1811 !(rParams.mpExcludeFiles->IsExcluded(localPath))) 1796 1812 { 1797 printf("Local file '%s' exists, "1798 "but store file '%s' "1799 " does not exist.\n",1800 localPathDisplay.c_str(),1801 storePathDisplay.c_str());1813 BOX_WARNING("Local file '" << 1814 localPathDisplay << 1815 "' exists, but store file '" << 1816 storePathDisplay << 1817 "' does not."); 1802 1818 rParams.mDifferences ++; 1803 1819 … … 1810 1826 { 1811 1827 rParams.mDifferencesExplainedByModTime ++; 1812 printf("(the file above was modified after the last sync time -- might be reason for difference)\n");1828 BOX_INFO("(the file above was modified after the last sync time -- might be reason for difference)"); 1813 1829 } 1814 1830 } … … 1853 1869 { 1854 1870 // Not found -- report 1855 printf("Local directory '%s' is excluded, but "1856 "store directory '%s' still exists.\n",1857 localPathDisplay.c_str(),1858 storePathDisplay .c_str());1871 BOX_WARNING("Local directory '" << 1872 localPathDisplay << "' is excluded, " 1873 "but store directory '" << 1874 storePathDisplay << "' still exists."); 1859 1875 rParams.mDifferences ++; 1860 1876 } … … 1862 1878 { 1863 1879 // Not found -- report 1864 printf("Local directory '%s' does not exist, "1865 "but store directory '%s' does.\n",1866 localPathDisplay.c_str(),1867 storePathDisplay .c_str());1880 BOX_WARNING("Local directory '" << 1881 localPathDisplay << "' does not exist, " 1882 "but store directory '" << 1883 storePathDisplay << "' does."); 1868 1884 rParams.mDifferences ++; 1869 1885 } … … 1909 1925 if(rParams.mpExcludeDirs == 0 || !(rParams.mpExcludeDirs->IsExcluded(localPath))) 1910 1926 { 1911 printf("Local directory '%s' exists, but "1912 "store directory '%s' does not exist.\n",1913 localPathDisplay.c_str(),1914 storePathDisplay .c_str());1927 BOX_WARNING("Local directory '" << 1928 localPathDisplay << "' exists, but " 1929 "store directory '" << 1930 storePathDisplay << "' does not."); 1915 1931 rParams.mDifferences ++; 1916 1932 } … … 1945 1961 if(args.size() != 2) 1946 1962 { 1947 printf("Incorrect usage.\nrestore [-d] [-r] [-i] <directory-name> <local-directory-name>\n");1963 BOX_ERROR("Incorrect usage. restore [-d] [-r] [-i] <remote-name> <local-name>"); 1948 1964 return; 1949 1965 } … … 1960 1976 if(dirID == std::numeric_limits<long long>::min() || dirID == std::numeric_limits<long long>::max() || dirID == 0) 1961 1977 { 1962 printf("Not a valid object ID (specified in hex)\n");1978 BOX_ERROR("Not a valid object ID (specified in hex)"); 1963 1979 return; 1964 1980 } … … 1983 1999 if(dirID == 0) 1984 2000 { 1985 printf("Directory '%s' not found on server\n", args[0].c_str());2001 BOX_ERROR("Directory '" << args[0] << "' not found on server"); 1986 2002 return; 1987 2003 } 1988 2004 if(dirID == BackupProtocolClientListDirectory::RootDirectory) 1989 2005 { 1990 printf("Cannot restore the root directory -- restore locations individually.\n");2006 BOX_ERROR("Cannot restore the root directory -- restore locations individually."); 1991 2007 return; 1992 2008 } … … 2024 2040 { 2025 2041 case Restore_Complete: 2026 printf("Restore complete\n");2042 BOX_INFO("Restore complete."); 2027 2043 break; 2028 2044 2029 2045 case Restore_ResumePossible: 2030 printf("Resume possible -- repeat command with -r flag to resume\n");2046 BOX_ERROR("Resume possible -- repeat command with -r flag to resume"); 2031 2047 break; 2032 2048 2033 2049 case Restore_TargetExists: 2034 printf("The target directory exists. You cannot restore over an existing directory.\n");2050 BOX_ERROR("The target directory exists. You cannot restore over an existing directory."); 2035 2051 break; 2036 2052 2037 2053 #ifdef WIN32 2038 2054 case Restore_TargetPathNotFound: 2039 printf("The target directory path does not exist.\n"2055 BOX_ERROR("The target directory path does not exist.\n" 2040 2056 "To restore to a directory whose parent " 2041 "does not exist, create the parent first. \n");2057 "does not exist, create the parent first."); 2042 2058 break; 2043 2059 #endif 2044 2060 2045 2061 case Restore_UnknownError: 2046 printf("Unknown error during restore.\n");2062 BOX_ERROR("Unknown error during restore."); 2047 2063 break; 2048 2064 2049 2065 default: 2050 printf("ERROR: Unknown restore result %d.\n", result);2066 BOX_ERROR("Unknown restore result " << result << "."); 2051 2067 break; 2052 2068 } … … 2168 2184 if(args.size() != 1) 2169 2185 { 2170 printf("Incorrect usage.\nundelete <directory-name>\n");2186 BOX_ERROR("Incorrect usage. undelete <directory-name>"); 2171 2187 return; 2172 2188 } … … 2186 2202 if(dirID == 0) 2187 2203 { 2188 printf("Directory '%s' not found on server\n", args[0].c_str());2204 BOX_ERROR("Directory '" << args[0] << "' not found on server."); 2189 2205 return; 2190 2206 } 2191 2207 if(dirID == BackupProtocolClientListDirectory::RootDirectory) 2192 2208 { 2193 printf("Cannot undelete the root directory.\n");2209 BOX_ERROR("Cannot undelete the root directory."); 2194 2210 return; 2195 2211 }
Note: See TracChangeset
for help on using the changeset viewer.
