diff options
Diffstat (limited to 'src/VBox/Main/src-server/VirtualBoxImpl.cpp')
| -rw-r--r-- | src/VBox/Main/src-server/VirtualBoxImpl.cpp | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/src/VBox/Main/src-server/VirtualBoxImpl.cpp b/src/VBox/Main/src-server/VirtualBoxImpl.cpp index d90b0b0b2..9789a2bd0 100644 --- a/src/VBox/Main/src-server/VirtualBoxImpl.cpp +++ b/src/VBox/Main/src-server/VirtualBoxImpl.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2012 Oracle Corporation + * Copyright (C) 2006-2013 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -1514,13 +1514,13 @@ void sanitiseMachineFilename(Utf8Str &strName) * *nix, or be otherwise difficult for shells to handle (I would have * preferred to remove the space and brackets too). We also remove all * characters which need UTF-16 surrogate pairs for Windows's benefit. */ -#ifdef RT_STRICT RTUNICP aCpSet[] = { ' ', ' ', '(', ')', '-', '.', '0', '9', 'A', 'Z', 'a', 'z', '_', '_', 0xa0, 0xd7af, '\0' }; -#endif char *pszName = strName.mutableRaw(); - Assert(RTStrPurgeComplementSet(pszName, aCpSet, '_') >= 0); + int cReplacements = RTStrPurgeComplementSet(pszName, aCpSet, '_'); + Assert(cReplacements >= 0); + NOREF(cReplacements); /* No leading dot or dash. */ if (pszName[0] == '.' || pszName[0] == '-') pszName[0] = '_'; @@ -3877,6 +3877,48 @@ HRESULT VirtualBox::checkMediaForConflicts(const Guid &aId, } /** + * Checks whether the given UUID is already in use by one medium for the + * given device type. + * + * @returns true if the UUID is already in use + * fale otherwise + * @param aId The UUID to check. + * @param deviceType The device type the UUID is going to be checked for + * conflicts. + */ +bool VirtualBox::isMediaUuidInUse(const Guid &aId, DeviceType_T deviceType) +{ + AssertReturn(!aId.isEmpty(), E_FAIL); + + AutoReadLock alock(getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS); + + HRESULT rc = S_OK; + bool fInUse = false; + + ComObjPtr<Medium> pMediumFound; + + switch (deviceType) + { + case DeviceType_HardDisk: + rc = findHardDiskById(aId, false /* aSetError */, &pMediumFound); + break; + case DeviceType_DVD: + rc = findDVDOrFloppyImage(DeviceType_DVD, &aId, Utf8Str::Empty, false /* aSetError */, &pMediumFound); + break; + case DeviceType_Floppy: + rc = findDVDOrFloppyImage(DeviceType_Floppy, &aId, Utf8Str::Empty, false /* aSetError */, &pMediumFound); + break; + default: + AssertMsgFailed(("Invalid device type %d\n", deviceType)); + } + + if (SUCCEEDED(rc) && pMediumFound) + fInUse = true; + + return fInUse; +} + +/** * Called from Machine::prepareSaveSettings() when it has detected * that a machine has been renamed. Such renames will require * updating the global media registry during the |
