- Timestamp:
- Nov 1, 2022 1:33:46 AM (2 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
doc/manual/en_US/man_VBoxManage-unregistervm.xml (modified) (2 diffs)
-
src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp (modified) (4 diffs)
-
src/VBox/Main/idl/VirtualBox.xidl (modified) (1 diff)
-
src/VBox/Main/src-server/MediumImpl.cpp (modified) (1 diff)
-
src/VBox/Main/src-server/UnattendedImpl.cpp (modified) (8 diffs)
-
src/VBox/Storage/VISO.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/manual/en_US/man_VBoxManage-unregistervm.xml
r96407 r97360 55 55 </group> 56 56 <arg>--delete</arg> 57 <arg>--delete-all</arg> 57 58 </cmdsynopsis> 58 59 </refsynopsisdiv> … … 95 96 </itemizedlist></listitem> 96 97 </varlistentry> 98 <varlistentry> 99 <term><option>--delete-all</option></term> 100 <listitem><para> 101 Deletes the files described in the <option>--delete</option> option, 102 as well as all DVDs and Floppy disks located in the VM folder and 103 attached only to this VM. 104 </para></listitem> 105 </varlistentry> 97 106 </variablelist> 98 107 </refsect1> -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp
r96620 r97360 171 171 { "--delete", 'd', RTGETOPT_REQ_NOTHING }, 172 172 { "-delete", 'd', RTGETOPT_REQ_NOTHING }, // deprecated 173 { "--delete-all", 'a', RTGETOPT_REQ_NOTHING }, 174 { "-delete-all", 'a', RTGETOPT_REQ_NOTHING }, // deprecated 173 175 }; 174 176 … … 178 180 const char *VMName = NULL; 179 181 bool fDelete = false; 182 bool fDeleteAll = false; 180 183 181 184 int c; … … 191 194 case 'd': // --delete 192 195 fDelete = true; 196 break; 197 198 case 'a': // --delete-all 199 fDeleteAll = true; 193 200 break; 194 201 … … 224 231 RTEXITCODE_FAILURE); 225 232 SafeIfaceArray<IMedium> aMedia; 226 CHECK_ERROR_RET(machine, Unregister(CleanupMode_DetachAllReturnHardDisksOnly, 233 CHECK_ERROR_RET(machine, Unregister(fDeleteAll ? CleanupMode_DetachAllReturnHardDisksAndVMRemovable 234 :CleanupMode_DetachAllReturnHardDisksOnly, 227 235 ComSafeArrayAsOutParam(aMedia)), 228 236 RTEXITCODE_FAILURE); 229 if (fDelete )237 if (fDelete || fDeleteAll) 230 238 { 231 239 ComPtr<IProgress> pProgress; -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r96888 r97360 6517 6517 <enum 6518 6518 name="CleanupMode" 6519 uuid=" 67897c50-7cca-47a9-83f6-ce8fd8eb5441"6519 uuid="1ec1df9e-9b0e-43cd-ad4d-a34e10edb0c5" 6520 6520 > 6521 6521 <desc>Cleanup mode, used with <link to="IMachine::unregister" />. 6522 6522 </desc> 6523 <const name="UnregisterOnly" value="1">6523 <const name="UnregisterOnly" value="1"> 6524 6524 <desc>Unregister only the machine, but neither delete snapshots nor detach media.</desc> 6525 6525 </const> 6526 <const name="DetachAllReturnNone" value="2">6526 <const name="DetachAllReturnNone" value="2"> 6527 6527 <desc>Delete all snapshots and detach all media but return none; this will keep all media registered.</desc> 6528 6528 </const> 6529 <const name="DetachAllReturnHardDisksOnly" value="3">6529 <const name="DetachAllReturnHardDisksOnly" value="3"> 6530 6530 <desc>Delete all snapshots, detach all media and return hard disks for closing, but not removable media.</desc> 6531 6531 </const> 6532 <const name="Full" value="4">6532 <const name="Full" value="4"> 6533 6533 <desc>Delete all snapshots, detach all media and return all media for closing.</desc> 6534 </const> 6535 <const name="DetachAllReturnHardDisksAndVMRemovable" value="5"> 6536 <desc>Delete all snapshots, detach all media and return hard disks and removable locating in the folder of the machine to be deleted and referenced only to this machine, for closing.</desc> 6534 6537 </const> 6535 6538 </enum> -
trunk/src/VBox/Main/src-server/MediumImpl.cpp
r96407 r97360 5528 5528 5529 5529 if ( !(m->formatObj->i_getCapabilities() & ( MediumFormatCapabilities_CreateDynamic 5530 | MediumFormatCapabilities_CreateFixed))) 5530 | MediumFormatCapabilities_CreateFixed 5531 | MediumFormatCapabilities_File))) 5531 5532 throw setError(VBOX_E_NOT_SUPPORTED, 5532 5533 tr("Medium format '%s' does not support storage deletion"), -
trunk/src/VBox/Main/src-server/UnattendedImpl.cpp
r96862 r97360 141 141 bool fMountOnly; 142 142 Utf8Str strImagePath; 143 bool fAuxiliary; 143 144 144 145 UnattendedInstallationDisk(StorageBus_T a_enmBusType, Utf8Str const &a_rBusName, DeviceType_T a_enmDeviceType, 145 146 AccessMode_T a_enmAccessType, LONG a_iPort, LONG a_iDevice, bool a_fMountOnly, 146 Utf8Str const &a_rImagePath )147 Utf8Str const &a_rImagePath, bool a_fAuxiliary) 147 148 : enmBusType(a_enmBusType), strControllerName(a_rBusName), enmDeviceType(a_enmDeviceType), enmAccessType(a_enmAccessType) 148 , iPort(a_iPort), iDevice(a_iDevice), fMountOnly(a_fMountOnly), strImagePath(a_rImagePath) 149 , iPort(a_iPort), iDevice(a_iDevice), fMountOnly(a_fMountOnly), strImagePath(a_rImagePath), fAuxiliary(a_fAuxiliary) 149 150 { 150 151 Assert(strControllerName.length() > 0); 151 152 } 152 153 153 UnattendedInstallationDisk(std::list<ControllerSlot>::const_iterator const &itDvdSlot, Utf8Str const &a_rImagePath) 154 UnattendedInstallationDisk(std::list<ControllerSlot>::const_iterator const &itDvdSlot, Utf8Str const &a_rImagePath, 155 bool a_fAuxiliary) 154 156 : enmBusType(itDvdSlot->enmBus), strControllerName(itDvdSlot->strControllerName), enmDeviceType(DeviceType_DVD) 155 157 , enmAccessType(AccessMode_ReadOnly), iPort(itDvdSlot->iPort), iDevice(itDvdSlot->iDevice) 156 , fMountOnly(!itDvdSlot->fFree), strImagePath(a_rImagePath) 158 , fMountOnly(!itDvdSlot->fFree), strImagePath(a_rImagePath), fAuxiliary(a_fAuxiliary) 157 159 { 158 160 Assert(strControllerName.length() > 0); … … 3052 3054 0, 0, 3053 3055 fFoundPort0Dev0 /*fMountOnly*/, 3054 mpInstaller->getAuxiliaryFloppyFilePath() ));3056 mpInstaller->getAuxiliaryFloppyFilePath(), false)); 3055 3057 return S_OK; 3056 3058 } … … 3211 3213 if (mpInstaller->isAuxiliaryIsoNeeded() && mpInstaller->bootFromAuxiliaryIso()) 3212 3214 { 3213 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, mpInstaller->getAuxiliaryIsoFilePath() ));3215 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, mpInstaller->getAuxiliaryIsoFilePath(), true)); 3214 3216 ++itDvdSlot; 3215 3217 } … … 3217 3219 if (mpInstaller->isOriginalIsoNeeded()) 3218 3220 { 3219 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getIsoPath() ));3221 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getIsoPath(), false)); 3220 3222 ++itDvdSlot; 3221 3223 } … … 3223 3225 if (mpInstaller->isAuxiliaryIsoNeeded() && !mpInstaller->bootFromAuxiliaryIso()) 3224 3226 { 3225 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, mpInstaller->getAuxiliaryIsoFilePath() ));3227 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, mpInstaller->getAuxiliaryIsoFilePath(), true)); 3226 3228 ++itDvdSlot; 3227 3229 } … … 3230 3232 if (mpInstaller->isAdditionsIsoNeeded()) 3231 3233 { 3232 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getAdditionsIsoPath() ));3234 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getAdditionsIsoPath(), false)); 3233 3235 ++itDvdSlot; 3234 3236 } … … 3236 3238 if (mpInstaller->isValidationKitIsoNeeded()) 3237 3239 { 3238 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getValidationKitIsoPath() ));3240 rVecInstallatationDisks.push_back(UnattendedInstallationDisk(itDvdSlot, i_getValidationKitIsoPath(), false)); 3239 3241 ++itDvdSlot; 3240 3242 } … … 4215 4217 if (SUCCEEDED(rc)) 4216 4218 { 4219 if (pImage->fAuxiliary && pImage->strImagePath.endsWith(".viso")) 4220 { 4221 rc = ptrMedium->SetProperty(L"UnattendedInstall", L"1"); 4222 LogRelFlowFunc(("Medium::SetProperty -> %Rhrc\n", rc)); 4223 } 4224 4217 4225 if (pImage->fMountOnly) 4218 4226 { -
trunk/src/VBox/Storage/VISO.cpp
r96407 r97360 105 105 { "viso", VDTYPE_OPTICAL_DISC }, 106 106 { NULL, VDTYPE_INVALID } 107 }; 108 109 /** NULL-terminated array of configuration option. */ 110 static const VDCONFIGINFO s_aVisoConfigInfo[] = 111 { 112 /* Options for VMDK raw disks */ 113 { "UnattendedInstall", NULL, VDCFGVALUETYPE_STRING, VD_CFGKEY_EXPERT }, 114 /* End of options list */ 115 { NULL, NULL, VDCFGVALUETYPE_INTEGER, 0 } 107 116 }; 108 117 … … 515 524 } 516 525 517 518 /** 519 * @interface_method_impl{VDIMAGEBACKEND,pfnClose} 526 /** 527 * Scans the VISO file and removes all references to files 528 * which are in the same folder as the VISO and 529 * whose names begin with "Unattended-". 530 * 531 * @return VBox status code. 532 * 533 * @param pThis Pointer to VISO backend data. 534 */ 535 static int deleteReferences(PVISOIMAGE pThis) 536 { 537 /* 538 * Open the file and read it into memory. 539 */ 540 PVDIOSTORAGE pStorage = NULL; 541 int vrc = vdIfIoIntFileOpen(pThis->pIfIo, pThis->pszFilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE, &pStorage); 542 if (RT_FAILURE(vrc)) 543 { 544 LogRel(("VISO: Unable to open file '%s': %Rrc\n", pThis->pszFilename, vrc)); 545 return vrc; 546 } 547 548 LogRel(("VISO: Handling file '%s' references\n", pThis->pszFilename)); 549 550 /* 551 * Read the file into memory. 552 */ 553 uint64_t cbFile = 0; 554 vrc = vdIfIoIntFileGetSize(pThis->pIfIo, pStorage, &cbFile); 555 if (RT_SUCCESS(vrc)) 556 { 557 if (cbFile <= VISO_MAX_FILE_SIZE) 558 { 559 char *pszContent = (char *)RTMemTmpAlloc(cbFile + 1); 560 if (pszContent) 561 { 562 vrc = vdIfIoIntFileReadSync(pThis->pIfIo, pStorage, 0 /*off*/, pszContent, (size_t)cbFile); 563 if (RT_SUCCESS(vrc)) 564 { 565 /* 566 * Check the file marker. 567 * Ignore leading blanks. 568 */ 569 pszContent[(size_t)cbFile] = '\0'; 570 571 char *pszReadDst = pszContent; 572 while (RT_C_IS_SPACE(*pszReadDst)) 573 pszReadDst++; 574 if (strncmp(pszReadDst, RT_STR_TUPLE("--iprt-iso-maker-file-marker")) == 0) 575 { 576 vrc = visoParseUuid(pszReadDst, &pThis->Uuid); 577 if (RT_SUCCESS(vrc)) 578 { 579 /* 580 * Make sure it's valid UTF-8 before letting 581 */ 582 vrc = RTStrValidateEncodingEx(pszContent, cbFile + 1, 583 RTSTR_VALIDATE_ENCODING_EXACT_LENGTH 584 | RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED); 585 if (RT_SUCCESS(vrc)) 586 { 587 /* 588 * Convert it into an argument vector. 589 * Free the content afterwards to reduce memory pressure. 590 */ 591 uint32_t fGetOpt = strncmp(pszReadDst, RT_STR_TUPLE("--iprt-iso-maker-file-marker-ms")) != 0 592 ? RTGETOPTARGV_CNV_QUOTE_BOURNE_SH : RTGETOPTARGV_CNV_QUOTE_MS_CRT; 593 fGetOpt |= RTGETOPTARGV_CNV_MODIFY_INPUT; 594 char **papszArgs; 595 int cArgs; 596 vrc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszContent, fGetOpt, NULL); 597 598 if (RT_SUCCESS(vrc)) 599 { 600 for (int i = 0; i < cArgs; ++i) 601 { 602 char *pszArg = papszArgs[i]; 603 char *pszOffset = strrchr(pszArg, '='); 604 if (pszOffset != NULL) 605 pszArg = pszOffset + 1; 606 607 /* if it isn't option */ 608 if (pszArg[0] != '-') 609 { 610 char *pszPath = RTPathAbsExDup(pThis->pszCwd, pszArg, 0); 611 if (RTStrStartsWith((const char *)pszPath, pThis->pszCwd)) 612 { 613 char *pszFileName = RTPathFilename(pszPath); 614 if ( pszFileName != NULL 615 && RTStrStartsWith((const char *)pszFileName, "Unattended-")) 616 { 617 vrc = RTFileDelete(pszPath); 618 if (RT_SUCCESS(vrc)) 619 LogRel(("VISO: file '%s' deleted\n", pszPath)); 620 else 621 LogRel(("VISO: Failed to delete the file '%s' (%Rrc)\n", pszPath, vrc)); 622 vrc = VINF_SUCCESS; 623 } 624 } 625 RTStrFree(pszPath); 626 } 627 } 628 RTGetOptArgvFreeEx(papszArgs, fGetOpt); 629 papszArgs = NULL; 630 } 631 else 632 vdIfError(pThis->pIfError, vrc, RT_SRC_POS, "VISO: RTGetOptArgvFromString failed: %Rrc", vrc); 633 } 634 else 635 vdIfError(pThis->pIfError, vrc, RT_SRC_POS, "VISO: Invalid file encoding"); 636 } 637 else 638 vdIfError(pThis->pIfError, vrc, RT_SRC_POS, "VISO: Parsing UUID failed: %Rrc", vrc); 639 } 640 else 641 vrc = VERR_VD_GEN_INVALID_HEADER; 642 } 643 else 644 vdIfError(pThis->pIfError, vrc, RT_SRC_POS, "VISO: Reading file failed: %Rrc", vrc); 645 646 RTMemTmpFree(pszContent); 647 } 648 else 649 vrc = VERR_NO_TMP_MEMORY; 650 } 651 else 652 { 653 LogRel(("visoOpen: VERR_VD_INVALID_SIZE - cbFile=%#RX64 cbMaxFile=%#RX64\n", 654 cbFile, (uint64_t)VISO_MAX_FILE_SIZE)); 655 vrc = VERR_VD_INVALID_SIZE; 656 } 657 } 658 659 if (RT_FAILURE(vrc)) 660 LogRel(("VISO: Handling of file '%s' failed with %Rrc\n", pThis->pszFilename, vrc)); 661 662 vdIfIoIntFileClose(pThis->pIfIo, pStorage); 663 return vrc; 664 } 665 666 /** 667 * @interface_method_impl{VDIMAGEBACKEND,pfnClose} 520 668 */ 521 669 static DECLCALLBACK(int) visoClose(void *pBackendData, bool fDelete) … … 527 675 { 528 676 if (fDelete) 677 { 678 PVDINTERFACECONFIG pImgCfg = VDIfConfigGet(&pThis->pIfIo->Core); 679 680 bool fUnattendedInstall = false; 681 int vrc = VDCFGQueryBool(pImgCfg, "UnattendedInstall", &fUnattendedInstall); 682 683 /* 684 * The VISO created by unattended installer, so delete all generated files 685 * included in the VISO. the file is considered generated if it is located 686 * in the same folder as VISO and its name begins with "Unattended-" 687 */ 688 if (RT_SUCCESS(vrc) && fUnattendedInstall) 689 deleteReferences(pThis); 529 690 vdIfIoIntFileDelete(pThis->pIfIo, pThis->pszFilename); 691 } 530 692 531 693 if (pThis->hIsoFile != NIL_RTVFSFILE) … … 869 1031 g_aVBoXIsoMakerFileExtensions, 870 1032 /* paConfigInfo */ 871 NULL,1033 s_aVisoConfigInfo, 872 1034 /* pfnProbe */ 873 1035 visoProbe,
Note:
See TracChangeset
for help on using the changeset viewer.

