Changeset 30380 in vbox for trunk/src/VBox
- Timestamp:
- Jun 22, 2010 4:28:14 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 62987
- Location:
- trunk/src/VBox/Main
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/MachineImpl.cpp
r30379 r30380 5095 5095 5096 5096 /** 5097 * Tries to calculate the relative path of the given absolute path using the 5098 * directory of the machine settings file as the base directory. 5099 * 5100 * @param aPath Absolute path to calculate the relative path for. 5101 * @param aResult Where to put the result (used only when it's possible to 5102 * make a relative path from the given absolute path; otherwise 5103 * left untouched). 5097 * Copies strSource to strTarget, making it relative to the machine folder 5098 * if it is a subdirectory thereof, or simply copying it otherwise. 5099 * 5100 * @param strSource Path to evalue and copy. 5101 * @param strTarget Buffer to receive target path. 5104 5102 * 5105 5103 * @note Locks this object for reading. 5106 5104 */ 5107 void Machine::calculateRelativePath(const Utf8Str &strPath, Utf8Str &aResult) 5105 void Machine::copyPathRelativeToMachine(const Utf8Str &strSource, 5106 Utf8Str &strTarget) 5108 5107 { 5109 5108 AutoCaller autoCaller(this); … … 5113 5112 5114 5113 AssertReturnVoid(!mData->m_strConfigFileFull.isEmpty()); 5115 5116 Utf8Str settingsDir = mData->m_strConfigFileFull; 5117 5118 settingsDir.stripFilename(); 5119 if (RTPathStartsWith(strPath.c_str(), settingsDir.c_str())) 5120 { 5121 /* when assigning, we create a separate Utf8Str instance because both 5122 * aPath and aResult can point to the same memory location when this 5123 * func is called (if we just do aResult = aPath, aResult will be freed 5124 * first, and since its the same as aPath, an attempt to copy garbage 5125 * will be made. */ 5126 aResult = Utf8Str(strPath.c_str() + settingsDir.length() + 1); 5127 } 5114 // use strTarget as a temporary buffer to hold the machine settings dir 5115 strTarget = mData->m_strConfigFileFull; 5116 strTarget.stripFilename(); 5117 if (RTPathStartsWith(strSource.c_str(), strTarget.c_str())) 5118 // is relative: then append what's left 5119 strTarget.append(strSource.c_str() + strTarget.length()); // include '/' 5120 else 5121 // is not relative: then overwrite 5122 strTarget = strSource; 5128 5123 } 5129 5124 … … 7440 7435 /* update m_strConfigFileFull amd mConfigFile */ 7441 7436 mData->m_strConfigFileFull = newConfigFile; 7442 7443 7437 // compute the relative path too 7444 Utf8Str path = newConfigFile; 7445 mParent->calculateRelativePath(path, path); 7446 mData->m_strConfigFile = path; 7438 mParent->copyPathRelativeToConfig(newConfigFile, mData->m_strConfigFile); 7447 7439 7448 7440 // store the old and new so that VirtualBox::saveSettings() can update … … 7458 7450 7459 7451 /* update the snapshot folder */ 7460 path = mUserData->mSnapshotFolderFull;7452 Utf8Str path = mUserData->mSnapshotFolderFull; 7461 7453 if (RTPathStartsWith(path.c_str(), configDir.c_str())) 7462 7454 { … … 7464 7456 path.raw() + configDir.length()); 7465 7457 mUserData->mSnapshotFolderFull = path; 7466 calculateRelativePath(path, path); 7467 mUserData->mSnapshotFolder = path; 7458 Utf8Str strTemp; 7459 copyPathRelativeToMachine(path, strTemp); 7460 mUserData->mSnapshotFolder = strTemp; 7468 7461 } 7469 7462 … … 7720 7713 Assert(!mSSData->mStateFilePath.isEmpty()); 7721 7714 /* try to make the file name relative to the settings file dir */ 7722 calculateRelativePath(mSSData->mStateFilePath, config.strStateFile); 7723 if (!config.strStateFile.length()) 7724 // path is not relative (e.g. because snapshot folder was changed to a non-default location): 7725 config.strStateFile = mSSData->mStateFilePath; 7715 copyPathRelativeToMachine(mSSData->mStateFilePath, config.strStateFile); 7726 7716 } 7727 7717 else … … 8152 8142 if (!mSSData->mStateFilePath.isEmpty()) 8153 8143 /* try to make the file name relative to the settings file dir */ 8154 c alculateRelativePath(mSSData->mStateFilePath, mData->pMachineConfigFile->strStateFile);8144 copyPathRelativeToMachine(mSSData->mStateFilePath, mData->pMachineConfigFile->strStateFile); 8155 8145 else 8156 8146 mData->pMachineConfigFile->strStateFile.setNull(); -
trunk/src/VBox/Main/MediumImpl.cpp
r30377 r30380 2866 2866 aNewPath, 2867 2867 pcszMediumPath + strlen(aOldPath)); 2868 Utf8Str path = newPath;2869 m->pVirtualBox->calculateRelativePath(path, path);2870 2868 unconst(m->strLocationFull) = newPath; 2869 2870 Utf8Str path; 2871 m->pVirtualBox->copyPathRelativeToConfig(newPath, path); 2871 2872 unconst(m->strLocation) = path; 2872 2873 -
trunk/src/VBox/Main/SnapshotImpl.cpp
r30377 r30380 762 762 /* stateFile (optional) */ 763 763 if (!stateFilePath().isEmpty()) 764 /* try to make the file name relative to the settings file dir */ 765 m->pMachine->calculateRelativePath(stateFilePath(), data.strStateFile); 764 m->pMachine->copyPathRelativeToMachine(stateFilePath(), data.strStateFile); 766 765 else 767 766 data.strStateFile.setNull(); -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r30377 r30380 3395 3395 3396 3396 /** 3397 * Tries to calculate the relative path of the given absolute path using the 3398 * directory of the VirtualBox settings file as the base directory. 3399 * 3400 * @param aPath Absolute path to calculate the relative path for. 3401 * @param aResult Where to put the result (used only when it's possible to 3402 * make a relative path from the given absolute path; otherwise 3403 * left untouched). 3404 * 3405 * @note Doesn't lock any object. 3406 */ 3407 void VirtualBox::calculateRelativePath(const Utf8Str &strPath, Utf8Str &aResult) 3397 * Copies strSource to strTarget, making it relative to the VirtualBox config folder 3398 * if it is a subdirectory thereof, or simply copying it otherwise. 3399 * 3400 * @param strSource Path to evalue and copy. 3401 * @param strTarget Buffer to receive target path. 3402 */ 3403 void VirtualBox::copyPathRelativeToConfig(const Utf8Str &strSource, 3404 Utf8Str &strTarget) 3408 3405 { 3409 3406 AutoCaller autoCaller(this); 3410 3407 AssertComRCReturnVoid(autoCaller.rc()); 3411 3408 3412 /* no need to lock since mHomeDir is const */ 3413 3414 Utf8Str settingsDir = m->strHomeDir; 3415 3416 if (RTPathStartsWith(strPath.c_str(), settingsDir.c_str())) 3417 { 3418 /* when assigning, we create a separate Utf8Str instance because both 3419 * aPath and aResult can point to the same memory location when this 3420 * func is called (if we just do aResult = aPath, aResult will be freed 3421 * first, and since its the same as aPath, an attempt to copy garbage 3422 * will be made. */ 3423 aResult = Utf8Str(strPath.c_str() + settingsDir.length() + 1); 3424 } 3409 // no need to lock since mHomeDir is const 3410 3411 // use strTarget as a temporary buffer to hold the machine settings dir 3412 strTarget = m->strHomeDir; 3413 if (RTPathStartsWith(strSource.c_str(), strTarget.c_str())) 3414 // is relative: then append what's left 3415 strTarget.append(strSource.c_str() + strTarget.length()); // include '/' 3416 else 3417 // is not relative: then overwrite 3418 strTarget = strSource; 3425 3419 } 3426 3420 -
trunk/src/VBox/Main/include/MachineImpl.h
r29864 r30380 615 615 616 616 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult); 617 void c alculateRelativePath(const Utf8Str &strPath, Utf8Str &aResult);617 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget); 618 618 619 619 void getLogFolder(Utf8Str &aLogFolder); -
trunk/src/VBox/Main/include/VirtualBoxImpl.h
r30345 r30380 282 282 283 283 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult); 284 void c alculateRelativePath(const Utf8Str &strPath, Utf8Str &aResult);284 void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget); 285 285 286 286 HRESULT registerHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
Note:
See TracChangeset
for help on using the changeset viewer.