Changeset 42534 in vbox
- Timestamp:
- Aug 2, 2012 1:01:10 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.cpp
r42521 r42534 951 951 952 952 /** 953 * Report the result of a vbox_rm operation - either errors to stderr (not 954 * machine-readable) or everything to stdout as <name>\0<rc>\0 (machine- 955 * readable format). The message may optionally contain a '%s' for the file 956 * name and an %Rrc for the result code in that order. In future a "verbose" 957 * flag may be added, without which nothing will be output in non-machine- 958 * readable mode. Sets prc if rc is a non-success code. 959 */ 960 static void toolboxRmReport(const char *pcszMessage, const char *pcszFile, 961 int rc, uint32_t fOutputFlags, int *prc) 962 { 963 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)) 964 { 965 if (RT_FAILURE(rc)) 966 RTMsgError(pcszMessage, pcszFile, rc); 967 } 968 else 969 RTPrintf("fname=%s%crc=%d%c", pcszFile, 0, rc, 0); 970 if (prc && RT_FAILURE(rc)) 971 *prc = rc; 972 } 973 974 975 /** 953 976 * Main function for tool "vbox_rm". 954 977 * … … 975 998 }; 976 999 977 int ch ;1000 int ch, rc, rc2; 978 1001 RTGETOPTUNION ValueUnion; 979 1002 RTGETOPTSTATE GetState; 980 int rc = RTGetOptInit(&GetState, argc, argv,981 s_aOptions, RT_ELEMENTS(s_aOptions),982 1 /*iFirst*/,RTGETOPTINIT_FLAGS_OPTS_FIRST);1003 rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, 1004 RT_ELEMENTS(s_aOptions), 1 /*iFirst*/, 1005 RTGETOPTINIT_FLAGS_OPTS_FIRST); 983 1006 AssertRCReturn(rc, RTEXITCODE_INIT); 984 1007 … … 986 1009 uint32_t fFlags = 0; 987 1010 uint32_t fOutputFlags = 0; 1011 int cNonOptions = 0; 988 1012 989 1013 while ( (ch = RTGetOpt(&GetState, &ValueUnion)) … … 1014 1038 /* RTGetOpt will sort these to the end of the argv vector so 1015 1039 * that we will deal with them afterwards. */ 1040 ++cNonOptions; 1016 1041 break; 1017 1042 … … 1020 1045 } 1021 1046 } 1022 if (GetState.cNonOptions > argc - 1)1023 GetState.cNonOptions = argc - 1;1024 1047 /* We need at least one file. */ 1025 if (RT_SUCCESS(rc) && GetState.cNonOptions == 0)1048 if (RT_SUCCESS(rc) && cNonOptions == 0) 1026 1049 { 1027 1050 RTMsgError("No files or directories specified."); … … 1043 1066 if (RT_SUCCESS(rc)) 1044 1067 { 1045 for (int i = argc - GetState.cNonOptions; i < argc; ++i)1068 for (int i = argc - cNonOptions; i < argc; ++i) 1046 1069 { 1047 1070 /* I'm sure this isn't the most effective way, but I hope it will … … 1050 1073 { 1051 1074 if (!(fFlags & VBOXSERVICETOOLBOXRMFLAG_RECURSIVE)) 1052 { 1053 if (!( fOutputFlags 1054 & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)) 1055 RTMsgError("Cannot remove directory '%s' as the '-R' option was not specified.\n", 1056 argv[i]); 1057 } 1075 toolboxRmReport("Cannot remove directory '%s' as the '-R' option was not specified.\n", 1076 argv[i], VERR_INVALID_PARAMETER, 1077 fOutputFlags, &rc); 1058 1078 else 1059 1079 { 1060 rc = RTDirRemoveRecursive(argv[i], 1061 RTDIRRMREC_F_CONTENT_AND_DIR); 1062 if ( RT_FAILURE(rc) 1063 && !( fOutputFlags 1064 & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)) 1065 RTMsgError("The following error occurred while removing directory '%s': %Rrc.\n", 1066 argv[i], rc); 1080 rc2 = RTDirRemoveRecursive(argv[i], 1081 RTDIRRMREC_F_CONTENT_AND_DIR); 1082 toolboxRmReport("The following error occurred while removing directory '%s': %Rrc.\n", 1083 argv[i], rc2, fOutputFlags, &rc); 1067 1084 } 1068 1085 } 1069 1086 else if (RTPathExists(argv[i]) || RTSymlinkExists(argv[i])) 1070 1087 { 1071 rc = RTFileDelete(argv[i]); 1072 if ( RT_FAILURE(rc) 1073 && !( fOutputFlags 1074 & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)) 1075 RTMsgError("The following error occurred while removing file '%s': %Rrc.\n", 1076 argv[i], rc); 1088 rc2 = RTFileDelete(argv[i]); 1089 toolboxRmReport("The following error occurred while removing file '%s': %Rrc.\n", 1090 argv[i], rc2, fOutputFlags, &rc); 1077 1091 } 1078 1092 else 1079 { 1080 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)) 1081 RTMsgError("File '%s' does not exist.\n", argv[i]); 1082 } 1093 toolboxRmReport("File '%s' does not exist.\n", argv[i], 1094 VERR_FILE_NOT_FOUND, fOutputFlags, &rc); 1083 1095 } 1084 1096 … … 1086 1098 VBoxServiceToolboxPrintStrmTermination(); 1087 1099 } 1088 return RT EXITCODE_SUCCESS;1100 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 1089 1101 } 1090 1102
Note:
See TracChangeset
for help on using the changeset viewer.