VirtualBox

Changeset 71053 in vbox


Ignore:
Timestamp:
Feb 19, 2018 1:35:01 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
120916
Message:

bugref: 8345. Added a function isMediumTypeSupportedForMoving(). Checking a trailing slash in the destination path. Cleaned up the code.

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/MachineImplMoveVM.h

    r70971 r71053  
    121121    HRESULT moveAllDisks(const std::map<Utf8Str, MEDIUMTASK>& listOfDisks, const Utf8Str* strTargetFolder = NULL);
    122122    HRESULT restoreAllDisks(const std::map<Utf8Str, MEDIUMTASK>& listOfDisks);
     123    bool isMediumTypeSupportedForMoving(const ComPtr<IMedium> &pMedium);
    123124};
    124125
  • trunk/src/VBox/Main/src-server/MachineImplMoveVM.cpp

    r70973 r71053  
    2323
    2424#include "MachineImplMoveVM.h"
     25#include "MediumFormatImpl.h"
    2526#include "VirtualBoxImpl.h"
    2627#include "Logging.h"
     
    113114{
    114115    HRESULT rc = S_OK;
    115     Utf8Str strTargetFolder = m_targetPath;
     116
     117    Utf8Str strTargetFolder;
     118    /* adding a trailing slash if it's needed */
     119    {
     120        size_t len = m_targetPath.length() + 2;
     121        if (len >=RTPATH_MAX)
     122        {
     123            throw m_pMachine->setError(VBOX_E_IPRT_ERROR,
     124                           m_pMachine->tr(" The destination path isn't correct. "
     125                                          "The length of path exceeded the maximum value."));
     126        }
     127
     128        char* path = new char [len];
     129        RTStrCopy(path, len, m_targetPath.c_str());
     130        RTPathEnsureTrailingSeparator(path, len);
     131        strTargetFolder = m_targetPath = path;
     132        delete path;
     133    }
    116134
    117135    /*
     
    135153
    136154        vrc = RTFsQuerySizes(strTargetFolder.c_str(), &cbTotal, &cbFree, &cbBlock, &cbSector);
    137         if (FAILED(vrc)) throw vrc;
     155        if (FAILED(vrc))
     156        {
     157            RTPrintf("strTargetFolder is %s\n", strTargetFolder.c_str());
     158            rc = m_pMachine->setError(E_FAIL,
     159                                      m_pMachine->tr("Unable to move machine. Can't get the destination storage size (%s)"),
     160                                      strTargetFolder.c_str());
     161            throw rc;
     162        }
     163
    138164        long long totalFreeSpace = cbFree;
    139165        long long totalSpace = cbTotal;
     
    517543     * folder will be moved.
    518544     */
     545
    519546     /* Collect the shareable disks.
    520547     * Get the machines whom the shareable disks attach to.
     
    913940
    914941                strTargetImageName.append(RTPATH_DELIMITER).append(strLocation);
    915                 rc = m_pProgress->SetNextOperation(BstrFmt(machine->tr("Moving disk '%ls' ..."),
     942                rc = m_pProgress->SetNextOperation(BstrFmt(machine->tr("Moving medium '%ls' ..."),
    916943                                                       bstrSrcName.raw()).raw(),
    917944                                                       mt.uWeight);
     
    921948            {
    922949                strTargetImageName = mt.strBaseName;//Should contain full path to the image
    923                 rc = m_pProgress->SetNextOperation(BstrFmt(machine->tr("Moving disk '%ls' back..."),
     950                rc = m_pProgress->SetNextOperation(BstrFmt(machine->tr("Moving medium '%ls' back..."),
    924951                                                       bstrSrcName.raw()).raw(),
    925952                                                       mt.uWeight);
     
    942969            if (FAILED(rc)) throw rc;
    943970
    944             if (deviceType == DeviceType_Floppy)//on 12.02.2017, skip floppy
    945             {
    946                 //1. no host drive image
    947                 BOOL fHostDrive = false;
    948                 rc = pMedium->COMGETTER(HostDrive)(&fHostDrive);
    949                 if (FAILED(rc)) throw rc;
    950             }
    951             else
    952             {
    953                 ComPtr<IProgress> moveDiskProgress;
    954                 rc = pMedium->SetLocation(bstrLocation.raw(), moveDiskProgress.asOutParam());
    955                 /* Wait until the async process has finished. */
    956                 machineLock.release();
    957 
    958                 rc = m_pProgress->WaitForAsyncProgressCompletion(moveDiskProgress);
    959 
    960                 machineLock.acquire();
    961                 if (FAILED(rc)) throw rc;
    962 
    963                 LogRelFunc(("Moving %s has been finished\n", strTargetImageName.c_str()));
    964 
    965                 /* Check the result of the async process. */
    966                 LONG iRc;
    967                 rc = moveDiskProgress->COMGETTER(ResultCode)(&iRc);
    968                 if (FAILED(rc)) throw rc;
    969                 /* If the thread of the progress object has an error, then
    970                  * retrieve the error info from there, or it'll be lost. */
    971                 if (FAILED(iRc))
    972                     throw machine->setError(ProgressErrorInfo(moveDiskProgress));
    973             }
     971            ComPtr<IProgress> moveDiskProgress;
     972            rc = pMedium->SetLocation(bstrLocation.raw(), moveDiskProgress.asOutParam());
     973            /* Wait until the async process has finished. */
     974            machineLock.release();
     975
     976            rc = m_pProgress->WaitForAsyncProgressCompletion(moveDiskProgress);
     977
     978            machineLock.acquire();
     979            if (FAILED(rc)) throw rc;
     980
     981            LogRelFunc(("Moving %s has been finished\n", strTargetImageName.c_str()));
     982
     983            /* Check the result of the async process. */
     984            LONG iRc;
     985            rc = moveDiskProgress->COMGETTER(ResultCode)(&iRc);
     986            if (FAILED(rc)) throw rc;
     987            /* If the thread of the progress object has an error, then
     988             * retrieve the error info from there, or it'll be lost. */
     989            if (FAILED(iRc))
     990                throw machine->setError(ProgressErrorInfo(moveDiskProgress));
    974991
    975992            ++itMedium;
     
    12111228            ComObjPtr<Medium> pObjMedium = (Medium *)(IMedium *)pMedium;
    12121229
    1213             /*Check for "read-only" medium ?????????????????? */
    1214 //          bool fReadOnly = pObjMedium->i_isReadOnly();
    1215 //          if (fReadOnly)
    1216 //          {
    1217 //              RTPrintf("Skipping file %s because of \"read-only\" property.\n",
    1218 //                       Utf8Str(bstrLocation.raw()).c_str());
    1219 //              continue;
    1220 //          }
    1221 
    1222             /* Check whether medium is represented by file on the disk or not. Case for ISCI, in instance */
    1223             bool fRealFile = pObjMedium->i_isMediumFormatFile();
    1224             if (!fRealFile)
    1225             {
    1226                 LogRelFunc(("Skipping file %s because it's not a real file on the disk.\n",
    1227                                  Utf8Str(bstrLocation.raw()).c_str()));
     1230            /*Check for "read-only" medium in terms that VBox can't create this one */
     1231            bool fPass = isMediumTypeSupportedForMoving(pMedium);
     1232            if(!fPass)
     1233            {
     1234                LogRelFunc(("Skipping file %s because of this medium type hasn't been supported for moving.\n",
     1235                         Utf8Str(bstrLocation.raw()).c_str()));
    12281236                continue;
    1229             }
    1230 
    1231             /* some special checks for DVD */
    1232             if (deviceType == DeviceType_DVD)
    1233             {
    1234                 //no host drive CD/DVD image
    1235                 BOOL fHostDrive = false;
    1236                 rc = pMedium->COMGETTER(HostDrive)(&fHostDrive);
    1237                 if (FAILED(rc)) throw rc;
    1238 
    1239                 if(fHostDrive)
    1240                     continue;
    1241 
    1242                 //only ISO image is moved
    1243                 Utf8Str ext = bstrLocation;
    1244                 ext.assignEx(RTPathSuffix(ext.c_str()));//returns extension with dot (".iso")
    1245 
    1246                 int equality = ext.compare(".iso", Utf8Str::CaseInsensitive);
    1247                 if (equality != false)
    1248                     continue;
    12491237            }
    12501238
     
    12851273                mtc.chain.append(mt);
    12861274
    1287 //              LogRelFunc(("Added media file %s into the llMedias.\n", mt.strBaseName.c_str()));
    1288 
    12891275                /* Query next parent. */
    12901276                rc = pMedium->COMGETTER(Parent)(pMedium.asOutParam());
     
    13341320        sst.uWeight = (ULONG)(2 * (cbSize + _1M - 1) / _1M);
    13351321        llSaveStateFiles.append(sst);
    1336         LogRelFunc(("Added state file %s into the llSaveStateFiles.\n", sst.strSaveStateFile.c_str()));
    13371322    }
    13381323    return S_OK;
     
    13631348    }
    13641349}
     1350
     1351bool MachineMoveVM::isMediumTypeSupportedForMoving(const ComPtr<IMedium> &pMedium)
     1352{
     1353    HRESULT rc = S_OK;
     1354    bool fSupported = true;
     1355    Bstr bstrLocation;
     1356    rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());
     1357    if (FAILED(rc))
     1358    {
     1359        fSupported = false;
     1360        throw rc;
     1361    }
     1362
     1363    DeviceType_T deviceType;
     1364    rc = pMedium->COMGETTER(DeviceType)(&deviceType);
     1365    if (FAILED(rc))
     1366    {
     1367        fSupported = false;
     1368        throw rc;
     1369    }
     1370
     1371    ComPtr<IMediumFormat> mediumFormat;
     1372    rc = pMedium->COMGETTER(MediumFormat)(mediumFormat.asOutParam());
     1373    if (FAILED(rc))
     1374    {
     1375        fSupported = false;
     1376        throw rc;
     1377    }
     1378
     1379    /*Check whether VBox is able to create this medium format or not, i.e. medium can be "read-only" */
     1380    Bstr bstrFormatName;
     1381    rc = mediumFormat->COMGETTER(Name)(bstrFormatName.asOutParam());
     1382    if (FAILED(rc))
     1383    {
     1384        fSupported = false;
     1385        throw rc;
     1386    }
     1387
     1388    Utf8Str formatName = Utf8Str(bstrFormatName);
     1389    if (formatName.compare("VHDX", Utf8Str::CaseInsensitive) == 0)
     1390    {
     1391        LogRelFunc(("Skipping medium %s. VHDX format is supported in \"read-only\" mode only. \n",
     1392                    Utf8Str(bstrLocation.raw()).c_str()));
     1393        fSupported = false;
     1394    }
     1395
     1396    /* Check whether medium is represented by file on the disk  or not */
     1397    if (fSupported)
     1398    {
     1399        ComObjPtr<Medium> pObjMedium = (Medium *)(IMedium *)pMedium;
     1400        fSupported = pObjMedium->i_isMediumFormatFile();
     1401        if (!fSupported)
     1402        {
     1403            LogRelFunc(("Skipping medium %s because it's not a real file on the disk.\n",
     1404                        Utf8Str(bstrLocation.raw()).c_str()));
     1405        }
     1406    }
     1407
     1408    /* some special checks for DVD */
     1409    if (fSupported && deviceType == DeviceType_DVD)
     1410    {
     1411        Utf8Str ext = bstrLocation;
     1412        ext.assignEx(RTPathSuffix(ext.c_str()));//returns extension with dot (".iso")
     1413
     1414        //only ISO image is moved. Otherwise adding some information into log file
     1415        int equality = ext.compare(".iso", Utf8Str::CaseInsensitive);
     1416        if (equality != false)
     1417        {
     1418            LogRelFunc(("Skipping file %s. Only ISO images are supported for now.\n",
     1419                         Utf8Str(bstrLocation.raw()).c_str()));
     1420            fSupported = false;
     1421        }
     1422    }
     1423
     1424    return fSupported;
     1425}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette