Changeset 38015 in vbox for trunk/src/VBox/Additions/common/VBoxService
- Timestamp:
- Jul 18, 2011 12:49:31 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.cpp
r37952 r38015 47 47 * Defined Constants And Macros * 48 48 *******************************************************************************/ 49 49 50 /** Options indices for "vbox_cat". */ 50 #define CAT_OPT_NO_CONTENT_INDEXED 1000 51 typedef enum VBOXSERVICETOOLBOXCATOPT 52 { 53 VBOXSERVICETOOLBOXCATOPT_NO_CONTENT_INDEXED = 1000 54 } VBOXSERVICETOOLBOXCATOPT; 55 51 56 /** Options indices for "vbox_ls". */ 52 #define LS_OPT_MACHINE_READABLE 1000 57 typedef enum VBOXSERVICETOOLBOXLSOPT 58 { 59 VBOXSERVICETOOLBOXLSOPT_MACHINE_READABLE = 1000, 60 VBOXSERVICETOOLBOXLSOPT_VERBOSE 61 } VBOXSERVICETOOLBOXLSOPT; 62 53 63 /** Options indices for "vbox_stat". */ 54 #define STAT_OPT_MACHINE_READABLE 1000 64 typedef enum VBOXSERVICETOOLBOXSTATOPT 65 { 66 VBOXSERVICETOOLBOXSTATOPT_MACHINE_READABLE = 1000 67 } VBOXSERVICETOOLBOXSTATOPT; 68 69 55 70 /** Flags for "vbox_ls". */ 56 71 typedef enum VBOXSERVICETOOLBOXLSFLAG … … 268 283 { 269 284 /* Sorted by short ops. */ 270 { "--show-all", 'a', RTGETOPT_REQ_NOTHING },271 { "--number-nonblank", 'b', RTGETOPT_REQ_NOTHING},272 { NULL, 'e', RTGETOPT_REQ_NOTHING},273 { NULL, 'E', RTGETOPT_REQ_NOTHING},274 { "--flags", 'f', RTGETOPT_REQ_STRING},275 { "--no-content-indexed", CAT_OPT_NO_CONTENT_INDEXED,RTGETOPT_REQ_NOTHING},276 { "--number", 'n', RTGETOPT_REQ_NOTHING},277 { "--output", 'o', RTGETOPT_REQ_STRING},278 { "--squeeze-blank", 's', RTGETOPT_REQ_NOTHING},279 { NULL, 't', RTGETOPT_REQ_NOTHING},280 { "--show-tabs", 'T', RTGETOPT_REQ_NOTHING},281 { NULL, 'u', RTGETOPT_REQ_NOTHING},282 { "--show-noneprinting", 'v', RTGETOPT_REQ_NOTHING}285 { "--show-all", 'a', RTGETOPT_REQ_NOTHING }, 286 { "--number-nonblank", 'b', RTGETOPT_REQ_NOTHING}, 287 { NULL, 'e', RTGETOPT_REQ_NOTHING}, 288 { NULL, 'E', RTGETOPT_REQ_NOTHING}, 289 { "--flags", 'f', RTGETOPT_REQ_STRING}, 290 { "--no-content-indexed", VBOXSERVICETOOLBOXCATOPT_NO_CONTENT_INDEXED, RTGETOPT_REQ_NOTHING}, 291 { "--number", 'n', RTGETOPT_REQ_NOTHING}, 292 { "--output", 'o', RTGETOPT_REQ_STRING}, 293 { "--squeeze-blank", 's', RTGETOPT_REQ_NOTHING}, 294 { NULL, 't', RTGETOPT_REQ_NOTHING}, 295 { "--show-tabs", 'T', RTGETOPT_REQ_NOTHING}, 296 { NULL, 'u', RTGETOPT_REQ_NOTHING}, 297 { "--show-noneprinting", 'v', RTGETOPT_REQ_NOTHING} 283 298 }; 284 299 … … 341 356 return RTEXITCODE_SUCCESS; 342 357 343 case CAT_OPT_NO_CONTENT_INDEXED:358 case VBOXSERVICETOOLBOXCATOPT_NO_CONTENT_INDEXED: 344 359 fFlags |= RTFILE_O_NOT_CONTENT_INDEXED; 345 360 break; … … 717 732 static const RTGETOPTDEF s_aOptions[] = 718 733 { 719 { "--machinereadable", LS_OPT_MACHINE_READABLE,RTGETOPT_REQ_NOTHING },720 { "--dereference", 'L', RTGETOPT_REQ_NOTHING },721 { NULL, 'l', RTGETOPT_REQ_NOTHING },722 { NULL, 'R', RTGETOPT_REQ_NOTHING },723 { "--verbose", 'v',RTGETOPT_REQ_NOTHING}734 { "--machinereadable", VBOXSERVICETOOLBOXLSOPT_MACHINE_READABLE, RTGETOPT_REQ_NOTHING }, 735 { "--dereference", 'L', RTGETOPT_REQ_NOTHING }, 736 { NULL, 'l', RTGETOPT_REQ_NOTHING }, 737 { NULL, 'R', RTGETOPT_REQ_NOTHING }, 738 { "--verbose", VBOXSERVICETOOLBOXLSOPT_VERBOSE, RTGETOPT_REQ_NOTHING} 724 739 }; 725 740 … … 758 773 break; 759 774 760 case LS_OPT_MACHINE_READABLE:775 case VBOXSERVICETOOLBOXLSOPT_MACHINE_READABLE: 761 776 fOutputFlags |= VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE; 762 777 break; … … 766 781 break; 767 782 768 case 'v': /** @todo r=bird: "man ls" -> "-v natural sort of (version) numbers within text" */783 case VBOXSERVICETOOLBOXLSOPT_VERBOSE: 769 784 fVerbose = true; 770 785 break; … … 816 831 RTListForEach(&fileList, pNodeIt, VBOXSERVICETOOLBOXPATHENTRY, Node) 817 832 { 818 /** @todo r=bird: Call RTPathQueryInfoEx directly (RTFileExists819 * does it under the hood) and skip the RTFileOpen stuff!820 * /bin/ls can list full details for files you cannot open.821 *822 * Just try the following:823 * @code824 $ echo > testfile825 $ chmod 600 testfile826 $ sudo chown root:root testfile827 $ ls -la testfile828 * @endcode829 */830 831 833 if (RTFileExists(pNodeIt->pszName)) 832 834 { 833 RTFILE file; 834 rc = RTFileOpen(&file, pNodeIt->pszName, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ); 835 if (RT_SUCCESS(rc)) 835 RTFSOBJINFO objInfo; 836 int rc2 = RTPathQueryInfoEx(pNodeIt->pszName, &objInfo, 837 RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK /* @todo Follow link? */); 838 if (RT_FAILURE(rc2)) 836 839 { 837 RTFSOBJINFO objInfo; 838 rc = RTFileQueryInfo(file, &objInfo, RTFSOBJATTRADD_UNIX); 839 if (RT_SUCCESS(rc)) 840 { 841 rc = VBoxServiceToolboxPrintFsInfo(pNodeIt->pszName, strlen(pNodeIt->pszName), 842 fOutputFlags, &objInfo); 843 } 844 else 845 RTMsgError("Unable to query information for '%s', rc=%Rrc\n", 846 pNodeIt->pszName, rc); 847 RTFileClose(file); 840 RTMsgError("Cannot access '%s': No such file or directory\n", 841 pNodeIt->pszName); 842 rc = VERR_FILE_NOT_FOUND; 843 /* Do not break here -- process every element in the list 844 * and keep failing rc. */ 848 845 } 849 846 else 850 RTMsgError("Failed opening '%s', rc=%Rrc\n", 851 pNodeIt->pszName, rc); 847 { 848 rc2 = VBoxServiceToolboxPrintFsInfo(pNodeIt->pszName, 849 strlen(pNodeIt->pszName) /* cbName */, 850 fOutputFlags, 851 &objInfo); 852 if (RT_FAILURE(rc2)) 853 rc = rc2; 854 } 852 855 } 853 856 else 854 rc = VBoxServiceToolboxLsHandleDir(pNodeIt->pszName, 855 fFlags, fOutputFlags); 856 if (RT_FAILURE(rc)) 857 RTMsgError("Failed while enumerating '%s', rc=%Rrc\n", 858 pNodeIt->pszName, rc); 857 { 858 int rc2 = VBoxServiceToolboxLsHandleDir(pNodeIt->pszName, 859 fFlags, fOutputFlags); 860 if (RT_FAILURE(rc2)) 861 rc = rc2; 862 } 859 863 } 860 864 … … 958 962 ValueUnion.psz, rc); 959 963 if (fVerbose) 960 RTMsgInfo("Created directory ' s', mode %#RTfmode\n", ValueUnion.psz, fDirMode);964 RTMsgInfo("Created directory '%s', mode %#RTfmode\n", ValueUnion.psz, fDirMode); 961 965 cDirsCreated++; 962 966 break; … … 986 990 static const RTGETOPTDEF s_aOptions[] = 987 991 { 988 { "--file-system", 'f', RTGETOPT_REQ_NOTHING },989 { "--dereference", 'L', RTGETOPT_REQ_NOTHING },990 { "--machinereadable", STAT_OPT_MACHINE_READABLE,RTGETOPT_REQ_NOTHING },991 { "--terse", 't', RTGETOPT_REQ_NOTHING },992 { "--verbose", 'v', RTGETOPT_REQ_NOTHING }992 { "--file-system", 'f', RTGETOPT_REQ_NOTHING }, 993 { "--dereference", 'L', RTGETOPT_REQ_NOTHING }, 994 { "--machinereadable", VBOXSERVICETOOLBOXLSOPT_MACHINE_READABLE, RTGETOPT_REQ_NOTHING }, 995 { "--terse", 't', RTGETOPT_REQ_NOTHING }, 996 { "--verbose", 'v', RTGETOPT_REQ_NOTHING } 993 997 }; 994 998 … … 1020 1024 break; 1021 1025 1022 case LS_OPT_MACHINE_READABLE:1026 case VBOXSERVICETOOLBOXLSOPT_MACHINE_READABLE: 1023 1027 fOutputFlags |= VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE; 1024 1028 break; … … 1061 1065 RTListForEach(&fileList, pNodeIt, VBOXSERVICETOOLBOXPATHENTRY, Node) 1062 1066 { 1063 /** @todo r=bird: Use RTPathQueryInfoEx! The tool is called1064 * 'stat' because it's just a wrapper for 'stat()',1065 * right? Our equvialent to the 'stat()' call is1066 * RTPathQueryInfoEx(). Same permission issues as above1067 * with 'ls'. */1068 /* Only check for file existence for now. */1069 1067 RTFSOBJINFO objInfo; 1070 int rc2 = VINF_SUCCESS; /* Temporary rc to keep original rc. */ 1071 if (RTFileExists(pNodeIt->pszName)) 1072 { 1073 RTFILE file; 1074 rc2 = RTFileOpen(&file, pNodeIt->pszName, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ); 1075 if (RT_SUCCESS(rc2)) 1076 { 1077 rc2 = RTFileQueryInfo(file, &objInfo, RTFSOBJATTRADD_UNIX); 1078 if (RT_FAILURE(rc2)) 1079 RTMsgError("Unable to query information for '%s', rc=%Rrc\n", 1080 pNodeIt->pszName, rc2); 1081 RTFileClose(file); 1082 } 1083 else 1084 RTMsgError("Failed opening '%s', rc=%Rrc\n", 1085 pNodeIt->pszName, rc2); 1086 1087 if (RT_FAILURE(rc2)) 1088 rc = rc2; 1089 } 1090 else if (RTDirExists(pNodeIt->pszName)) 1091 { 1092 PRTDIR pDir; 1093 rc2 = RTDirOpen(&pDir, pNodeIt->pszName); 1094 if (RT_SUCCESS(rc2)) 1095 { 1096 rc2 = RTDirQueryInfo(pDir, &objInfo, RTFSOBJATTRADD_UNIX); 1097 RTDirClose(pDir); 1098 } 1099 } 1100 else 1068 int rc2 = RTPathQueryInfoEx(pNodeIt->pszName, &objInfo, 1069 RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK /* @todo Follow link? */); 1070 if (RT_FAILURE(rc2)) 1101 1071 { 1102 1072 RTMsgError("Cannot stat for '%s': No such file or directory\n", … … 1106 1076 * and keep failing rc. */ 1107 1077 } 1108 1109 if (RT_SUCCESS(rc2)) 1078 else 1110 1079 { 1111 1080 rc2 = VBoxServiceToolboxPrintFsInfo(pNodeIt->pszName,
Note:
See TracChangeset
for help on using the changeset viewer.