- Timestamp:
- Aug 6, 2012 12:04:38 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.cpp
r42534 r42615 136 136 " [--verbose|-v] [<file>...]\n" 137 137 " rm <general options> [-r|-R] <file>...\n" 138 " mktemp <general options> <template>\n" 138 139 " mkdir <general options> [--mode|-m] [--parents|-p]\n" 139 140 " [--verbose|-v] <directory>...\n" … … 1102 1103 1103 1104 1105 static char g_paszMkTempHelp[] = 1106 " VBoxService [--use-toolbox] vbox_mktemp <general options> <template>\n\n" 1107 "Create a temporary directory based on the template supplied. The last string\n" 1108 "of consecutive 'X' characters in the template will be replaced to form a unique\n" 1109 "name for the directory.\n" 1110 "\n"; 1111 1112 1113 /** 1114 * Report the result of a vbox_mktemp operation - either errors to stderr (not 1115 * machine-readable) or everything to stdout as <name>\0<rc>\0 (machine- 1116 * readable format). The message may optionally contain a '%s' for the file 1117 * name and an %Rrc for the result code in that order. In future a "verbose" 1118 * flag may be added, without which nothing will be output in non-machine- 1119 * readable mode. Sets prc if rc is a non-success code. 1120 */ 1121 static void toolboxMkTempReport(const char *pcszMessage, const char *pcszFile, 1122 int rc, uint32_t fOutputFlags, int *prc) 1123 { 1124 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)) 1125 { 1126 if (RT_FAILURE(rc)) 1127 RTMsgError(pcszMessage, pcszFile, rc); 1128 } 1129 else 1130 RTPrintf("name=%s%crc=%d%c", pcszFile, 0, rc, 0); 1131 if (prc && RT_FAILURE(rc)) 1132 *prc = rc; 1133 } 1134 1135 1136 /** 1137 * Main function for tool "vbox_mktemp". 1138 * 1139 * @return RTEXITCODE. 1140 * @param argc Number of arguments. 1141 * @param argv Pointer to argument array. 1142 */ 1143 static RTEXITCODE VBoxServiceToolboxMkTemp(int argc, char **argv) 1144 { 1145 static const RTGETOPTDEF s_aOptions[] = 1146 { 1147 { "--machinereadable", VBOXSERVICETOOLBOXOPT_MACHINE_READABLE, 1148 RTGETOPT_REQ_NOTHING }, 1149 }; 1150 1151 int ch, rc, rc2; 1152 RTGETOPTUNION ValueUnion; 1153 RTGETOPTSTATE GetState; 1154 rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, 1155 RT_ELEMENTS(s_aOptions), 1 /*iFirst*/, 1156 RTGETOPTINIT_FLAGS_OPTS_FIRST); 1157 AssertRCReturn(rc, RTEXITCODE_INIT); 1158 1159 bool fVerbose = false; 1160 uint32_t fFlags = 0; 1161 uint32_t fOutputFlags = 0; 1162 int cNonOptions = 0; 1163 1164 while ( (ch = RTGetOpt(&GetState, &ValueUnion)) 1165 && RT_SUCCESS(rc)) 1166 { 1167 /* For options that require an argument, ValueUnion has received the value. */ 1168 switch (ch) 1169 { 1170 case 'h': 1171 VBoxServiceToolboxShowUsageHeader(); 1172 RTPrintf("%s", g_paszMkTempHelp); 1173 return RTEXITCODE_SUCCESS; 1174 1175 case 'V': 1176 VBoxServiceToolboxShowVersion(); 1177 return RTEXITCODE_SUCCESS; 1178 1179 case VBOXSERVICETOOLBOXOPT_MACHINE_READABLE: 1180 fOutputFlags |= VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE; 1181 break; 1182 1183 case VINF_GETOPT_NOT_OPTION: 1184 /* RTGetOpt will sort these to the end of the argv vector so 1185 * that we will deal with them afterwards. */ 1186 ++cNonOptions; 1187 break; 1188 1189 default: 1190 return RTGetOptPrintError(ch, &ValueUnion); 1191 } 1192 } 1193 if (RT_SUCCESS(rc)) 1194 { 1195 /* Print magic/version. */ 1196 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) 1197 { 1198 rc = VBoxServiceToolboxStrmInit(); 1199 if (RT_FAILURE(rc)) 1200 RTMsgError("Error while initializing parseable streams, rc=%Rrc\n", rc); 1201 VBoxServiceToolboxPrintStrmHeader("vbt_mktemp", 1 /* Stream version */); 1202 } 1203 } 1204 1205 /* We need exactly one template, containing at least one 'X'. */ 1206 if (RT_SUCCESS(rc) && cNonOptions != 1) 1207 { 1208 toolboxMkTempReport("Please specify exactly one template.\n", 1209 "", VERR_INVALID_PARAMETER, fOutputFlags, &rc); 1210 return RTEXITCODE_FAILURE; 1211 } 1212 if (RT_SUCCESS(rc) && !strchr(argv[argc - 1], 'X')) /* IPRT asserts this. */ 1213 { 1214 toolboxMkTempReport("Template '%s' should contain at least one 'X' character.\n", 1215 argv[argc - 1], VERR_INVALID_PARAMETER, 1216 fOutputFlags, &rc); 1217 return RTEXITCODE_FAILURE; 1218 } 1219 1220 if (RT_SUCCESS(rc)) 1221 { 1222 rc = RTDirCreateTemp(argv[argc - 1]); 1223 toolboxMkTempReport("The following error occurred while creating a temporary directory with template '%s': %Rrc.\n", 1224 argv[argc - 1], rc, fOutputFlags, NULL); 1225 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) /* Output termination. */ 1226 VBoxServiceToolboxPrintStrmTermination(); 1227 } 1228 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 1229 } 1230 1231 1104 1232 /** @todo Document options! */ 1105 1233 static char g_paszMkDirHelp[] = … … 1370 1498 const s_aTools[] = 1371 1499 { 1372 { "cat", VBoxServiceToolboxCat }, 1373 { "ls", VBoxServiceToolboxLs }, 1374 { "rm", VBoxServiceToolboxRm }, 1375 { "mkdir", VBoxServiceToolboxMkDir }, 1376 { "stat", VBoxServiceToolboxStat }, 1500 { "cat", VBoxServiceToolboxCat }, 1501 { "ls", VBoxServiceToolboxLs }, 1502 { "rm", VBoxServiceToolboxRm }, 1503 { "mktemp", VBoxServiceToolboxMkTemp }, 1504 { "mkdir", VBoxServiceToolboxMkDir }, 1505 { "stat", VBoxServiceToolboxStat }, 1377 1506 }; 1378 1507
Note:
See TracChangeset
for help on using the changeset viewer.