Changeset 81425 in vbox for trunk/src/VBox/Main/src-server/SnapshotImpl.cpp
- Timestamp:
- Oct 21, 2019 6:19:39 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 134142
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/SnapshotImpl.cpp
r79154 r81425 656 656 657 657 /* state file may be NULL (for offline snapshots) */ 658 if ( path. length()658 if ( path.isNotEmpty() 659 659 && RTPathStartsWith(path.c_str(), strOldPath.c_str()) 660 660 ) … … 663 663 strNewPath.c_str(), 664 664 path.c_str() + strOldPath.length()); 665 LogFlowThisFunc(("-> updated: {%s}\n", path.c_str()));665 LogFlowThisFunc(("-> updated: {%s}\n", m->pMachine->mSSData->strStateFilePath.c_str())); 666 666 } 667 667 … … 673 673 pChild->i_updateSavedStatePathsImpl(strOldPath, strNewPath); 674 674 } 675 } 676 677 /** 678 * Checks if the specified path change affects the saved state file path of 679 * this snapshot or any of its (grand-)children and updates it accordingly. 680 * 681 * Intended to be called by Machine::openConfigLoader() only. 682 * 683 * @param strOldPath old path (full) 684 * @param strNewPath new path (full) 685 * 686 * @note Locks the machine (for the snapshots tree) + this object + children for writing. 687 */ 688 void Snapshot::i_updateSavedStatePaths(const Utf8Str &strOldPath, 689 const Utf8Str &strNewPath) 690 { 691 LogFlowThisFunc(("aOldPath={%s} aNewPath={%s}\n", strOldPath.c_str(), strNewPath.c_str())); 692 693 AutoCaller autoCaller(this); 694 AssertComRC(autoCaller.rc()); 695 696 // snapshots tree is protected by machine lock 697 AutoWriteLock alock(m->pMachine COMMA_LOCKVAL_SRC_POS); 698 699 // call the implementation under the tree lock 700 i_updateSavedStatePathsImpl(strOldPath, strNewPath); 675 701 } 676 702 … … 714 740 715 741 /** 716 * Checks if the specified path change affects the saved state file path of 742 * Internal implementation for Snapshot::updateNVRAMPaths (below). 743 * @param strOldPath 744 * @param strNewPath 745 */ 746 void Snapshot::i_updateNVRAMPathsImpl(const Utf8Str &strOldPath, 747 const Utf8Str &strNewPath) 748 { 749 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 750 751 const Utf8Str path = m->pMachine->mBIOSSettings->i_getNonVolatileStorageFile(); 752 LogFlowThisFunc(("Snap[%s].nvramPath={%s}\n", m->strName.c_str(), path.c_str())); 753 754 /* NVRAM filename may be empty */ 755 if ( path.isNotEmpty() 756 && RTPathStartsWith(path.c_str(), strOldPath.c_str()) 757 ) 758 { 759 m->pMachine->mBIOSSettings->i_updateNonVolatileStorageFile(Utf8StrFmt("%s%s", 760 strNewPath.c_str(), 761 path.c_str() + strOldPath.length())); 762 LogFlowThisFunc(("-> updated: {%s}\n", m->pMachine->mBIOSSettings->i_getNonVolatileStorageFile().c_str())); 763 } 764 765 for (SnapshotsList::const_iterator it = m->llChildren.begin(); 766 it != m->llChildren.end(); 767 ++it) 768 { 769 Snapshot *pChild = *it; 770 pChild->i_updateNVRAMPathsImpl(strOldPath, strNewPath); 771 } 772 } 773 774 /** 775 * Checks if the specified path change affects the NVRAM file path of 717 776 * this snapshot or any of its (grand-)children and updates it accordingly. 718 777 * … … 724 783 * @note Locks the machine (for the snapshots tree) + this object + children for writing. 725 784 */ 726 void Snapshot::i_update SavedStatePaths(const Utf8Str &strOldPath,727 785 void Snapshot::i_updateNVRAMPaths(const Utf8Str &strOldPath, 786 const Utf8Str &strNewPath) 728 787 { 729 788 LogFlowThisFunc(("aOldPath={%s} aNewPath={%s}\n", strOldPath.c_str(), strNewPath.c_str())); … … 844 903 845 904 // report the saved state file if it's not on the list yet 846 if ( !m->pMachine->mSSData->strStateFilePath.isEmpty())905 if (m->pMachine->mSSData->strStateFilePath.isNotEmpty()) 847 906 { 848 907 bool fFound = false; … … 861 920 llFilenames.push_back(m->pMachine->mSSData->strStateFilePath); 862 921 } 922 923 Utf8Str strNVRAMFile = m->pMachine->mBIOSSettings->i_getNonVolatileStorageFile(); 924 if (strNVRAMFile.isNotEmpty() && RTFileExists(strNVRAMFile.c_str())) 925 llFilenames.push_back(strNVRAMFile); 863 926 864 927 i_beginSnapshotDelete(); … … 1782 1845 if (FAILED(rc)) 1783 1846 throw rc; 1847 } 1848 1849 // Handle NVRAM file snapshotting 1850 Utf8Str strNVRAM = mBIOSSettings->i_getNonVolatileStorageFile(); 1851 Utf8Str strNVRAMSnap = pSnapshotMachine->i_getSnapshotNVRAMFilename(); 1852 Utf8Str strNVRAMSnapAbs; 1853 i_calculateFullPath(strNVRAMSnap, strNVRAMSnapAbs); 1854 if (strNVRAM.isNotEmpty() && strNVRAMSnap.isNotEmpty() && RTFileExists(strNVRAM.c_str())) 1855 { 1856 rc = VirtualBox::i_ensureFilePathExists(strNVRAMSnapAbs, true /* fCreate */); 1857 if (FAILED(rc)) 1858 throw rc; 1859 int vrc = RTFileCopy(strNVRAM.c_str(), strNVRAMSnapAbs.c_str()); 1860 if (RT_FAILURE(vrc)) 1861 throw setErrorBoth(VBOX_E_IPRT_ERROR, vrc, 1862 tr("Could not copy NVRAM file '%s' to '%s' (%Rrc)"), 1863 strNVRAM.c_str(), strNVRAMSnapAbs.c_str(), vrc); 1864 pSnapshotMachine->mBIOSSettings->i_updateNonVolatileStorageFile(strNVRAMSnap); 1784 1865 } 1785 1866 … … 2276 2357 mSSData->strStateFilePath = strSnapshotStateFile; 2277 2358 2359 const Utf8Str srcNVRAM(pSnapshotMachine->mBIOSSettings->i_getNonVolatileStorageFile()); 2360 const Utf8Str dstNVRAM(mBIOSSettings->i_getNonVolatileStorageFile()); 2361 if (dstNVRAM.isNotEmpty() && RTFileExists(dstNVRAM.c_str())) 2362 RTFileDelete(dstNVRAM.c_str()); 2363 if (srcNVRAM.isNotEmpty() && dstNVRAM.isNotEmpty() && RTFileExists(srcNVRAM.c_str())) 2364 RTFileCopy(srcNVRAM.c_str(), dstNVRAM.c_str()); 2365 2278 2366 LogFlowThisFunc(("Setting new current snapshot {%RTuuid}\n", task.m_pSnapshot->i_getId().raw())); 2279 2367 /* make the snapshot we restored from the current snapshot */ … … 2621 2709 ULONG ulTotalWeight = 1; // one for preparations 2622 2710 2623 if (pSnapshot->i_getStateFilePath(). length())2711 if (pSnapshot->i_getStateFilePath().isNotEmpty()) 2624 2712 { 2625 2713 ++ulOpCount; … … 3391 3479 } 3392 3480 3481 /* 3a: delete NVRAM file if present. */ 3482 { 3483 Utf8Str NVRAMPath = pSnapMachine->mBIOSSettings->i_getNonVolatileStorageFile(); 3484 if (NVRAMPath.isNotEmpty() && RTFileExists(NVRAMPath.c_str())) 3485 RTFileDelete(NVRAMPath.c_str()); 3486 } 3487 3488 /* third pass: */ 3393 3489 { 3394 3490 // beginSnapshotDelete() needs the machine lock, and the snapshots
Note:
See TracChangeset
for help on using the changeset viewer.