VirtualBox

Changeset 83607 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Apr 7, 2020 12:16:58 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
137012
Message:

Guest Control/Main: Check if destination/source entries in Copy[To|From] tasks are not empty. bugref:9320

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp

    r83606 r83607  
    14071407
    14081408    if (mDest.isEmpty())
    1409         return setProgressErrorMsg(VBOX_E_IPRT_ERROR, Utf8StrFmt(GuestSession::tr("Destination must not be empty")));
    1410 
    1411     GuestSessionFsSourceSet::iterator itSrc = mSources.begin();
    1412     while (itSrc != mSources.end())
    1413     {
    1414         Utf8Str strSrc = itSrc->strSource;
    1415         Utf8Str strDst = mDest;
    1416 
    1417         bool    fFollowSymlinks;
    1418 
    1419         if (strSrc.isEmpty())
    1420         {
    1421             strErrorInfo = Utf8StrFmt(GuestSession::tr("Source entry must not be empty"));
    1422             break;
    1423         }
    1424 
    1425         if (itSrc->enmType == FsObjType_Directory)
    1426         {
    1427             /* If the source does not end with a slash, copy over the entire directory
    1428              * (and not just its contents). */
    1429             /** @todo r=bird: Try get the path style stuff right and stop assuming all guest are windows guests.  */
    1430             if (   !strSrc.endsWith("/")
    1431                 && !strSrc.endsWith("\\"))
    1432             {
    1433                 if (!RTPATH_IS_SLASH(strDst[strDst.length() - 1]))
    1434                     strDst += "/";
    1435 
    1436                 strDst += Utf8Str(RTPathFilenameEx(strSrc.c_str(), mfPathStyle));
    1437             }
    1438 
    1439             fFollowSymlinks = itSrc->Type.Dir.fFollowSymlinks;
    1440         }
    1441         else
    1442         {
    1443             fFollowSymlinks = RT_BOOL(itSrc->Type.File.fCopyFlags & FileCopyFlag_FollowLinks);
    1444         }
    1445 
    1446         LogFlowFunc(("strSrc=%s, strDst=%s, fFollowSymlinks=%RTbool\n", strSrc.c_str(), strDst.c_str(), fFollowSymlinks));
    1447 
    1448         GuestFsObjData srcObjData;
    1449         int rcGuest = VERR_IPE_UNINITIALIZED_STATUS;
    1450         vrc = mSession->i_fsQueryInfo(strSrc, fFollowSymlinks, srcObjData, &rcGuest);
    1451         if (RT_FAILURE(vrc))
    1452         {
    1453             strErrorInfo = Utf8StrFmt(GuestSession::tr("No such source file/directory: %s"), strSrc.c_str());
    1454             break;
    1455         }
    1456 
    1457         if (srcObjData.mType == FsObjType_Directory)
    1458         {
    1459             if (itSrc->enmType != FsObjType_Directory)
    1460             {
    1461                 strErrorInfo = Utf8StrFmt(GuestSession::tr("Source is not a file: %s"), strSrc.c_str());
    1462                 vrc = VERR_NOT_A_FILE;
     1409    {
     1410        strErrorInfo = Utf8StrFmt(GuestSession::tr("Destination must not be empty"));
     1411        vrc = VERR_INVALID_PARAMETER;
     1412    }
     1413    else
     1414    {
     1415        GuestSessionFsSourceSet::iterator itSrc = mSources.begin();
     1416        while (itSrc != mSources.end())
     1417        {
     1418            Utf8Str strSrc = itSrc->strSource;
     1419            Utf8Str strDst = mDest;
     1420
     1421            bool    fFollowSymlinks;
     1422
     1423            if (strSrc.isEmpty())
     1424            {
     1425                strErrorInfo = Utf8StrFmt(GuestSession::tr("Source entry must not be empty"));
     1426                vrc = VERR_INVALID_PARAMETER;
    14631427                break;
    14641428            }
    1465         }
    1466         else
    1467         {
    1468             if (itSrc->enmType != FsObjType_File)
    1469             {
    1470                 strErrorInfo = Utf8StrFmt(GuestSession::tr("Source is not a directory: %s"), strSrc.c_str());
    1471                 vrc = VERR_NOT_A_DIRECTORY;
     1429
     1430            if (itSrc->enmType == FsObjType_Directory)
     1431            {
     1432                /* If the source does not end with a slash, copy over the entire directory
     1433                 * (and not just its contents). */
     1434                /** @todo r=bird: Try get the path style stuff right and stop assuming all guest are windows guests.  */
     1435                if (   !strSrc.endsWith("/")
     1436                    && !strSrc.endsWith("\\"))
     1437                {
     1438                    if (!RTPATH_IS_SLASH(strDst[strDst.length() - 1]))
     1439                        strDst += "/";
     1440
     1441                    strDst += Utf8Str(RTPathFilenameEx(strSrc.c_str(), mfPathStyle));
     1442                }
     1443
     1444                fFollowSymlinks = itSrc->Type.Dir.fFollowSymlinks;
     1445            }
     1446            else
     1447            {
     1448                fFollowSymlinks = RT_BOOL(itSrc->Type.File.fCopyFlags & FileCopyFlag_FollowLinks);
     1449            }
     1450
     1451            LogFlowFunc(("strSrc=%s, strDst=%s, fFollowSymlinks=%RTbool\n", strSrc.c_str(), strDst.c_str(), fFollowSymlinks));
     1452
     1453            GuestFsObjData srcObjData;
     1454            int rcGuest = VERR_IPE_UNINITIALIZED_STATUS;
     1455            vrc = mSession->i_fsQueryInfo(strSrc, fFollowSymlinks, srcObjData, &rcGuest);
     1456            if (RT_FAILURE(vrc))
     1457            {
     1458                strErrorInfo = Utf8StrFmt(GuestSession::tr("No such source file/directory: %s"), strSrc.c_str());
    14721459                break;
    14731460            }
    1474         }
    1475 
    1476         FsList *pFsList = NULL;
    1477         try
    1478         {
    1479             pFsList = new FsList(*this);
    1480             vrc = pFsList->Init(strSrc, strDst, *itSrc);
    1481             if (RT_SUCCESS(vrc))
    1482             {
    1483                 if (itSrc->enmType == FsObjType_Directory)
    1484                     vrc = pFsList->AddDirFromGuest(strSrc);
    1485                 else
    1486                     vrc = pFsList->AddEntryFromGuest(RTPathFilename(strSrc.c_str()), srcObjData);
    1487             }
    1488 
    1489             if (RT_FAILURE(vrc))
    1490             {
    1491                 delete pFsList;
    1492                 strErrorInfo = Utf8StrFmt(GuestSession::tr("Error adding source '%s' to list: %Rrc"), strSrc.c_str(), vrc);
     1461
     1462            if (srcObjData.mType == FsObjType_Directory)
     1463            {
     1464                if (itSrc->enmType != FsObjType_Directory)
     1465                {
     1466                    strErrorInfo = Utf8StrFmt(GuestSession::tr("Source is not a file: %s"), strSrc.c_str());
     1467                    vrc = VERR_NOT_A_FILE;
     1468                    break;
     1469                }
     1470            }
     1471            else
     1472            {
     1473                if (itSrc->enmType != FsObjType_File)
     1474                {
     1475                    strErrorInfo = Utf8StrFmt(GuestSession::tr("Source is not a directory: %s"), strSrc.c_str());
     1476                    vrc = VERR_NOT_A_DIRECTORY;
     1477                    break;
     1478                }
     1479            }
     1480
     1481            FsList *pFsList = NULL;
     1482            try
     1483            {
     1484                pFsList = new FsList(*this);
     1485                vrc = pFsList->Init(strSrc, strDst, *itSrc);
     1486                if (RT_SUCCESS(vrc))
     1487                {
     1488                    if (itSrc->enmType == FsObjType_Directory)
     1489                        vrc = pFsList->AddDirFromGuest(strSrc);
     1490                    else
     1491                        vrc = pFsList->AddEntryFromGuest(RTPathFilename(strSrc.c_str()), srcObjData);
     1492                }
     1493
     1494                if (RT_FAILURE(vrc))
     1495                {
     1496                    delete pFsList;
     1497                    strErrorInfo = Utf8StrFmt(GuestSession::tr("Error adding source '%s' to list: %Rrc"), strSrc.c_str(), vrc);
     1498                    break;
     1499                }
     1500
     1501                mVecLists.push_back(pFsList);
     1502            }
     1503            catch (std::bad_alloc &)
     1504            {
     1505                vrc = VERR_NO_MEMORY;
    14931506                break;
    14941507            }
    14951508
    1496             mVecLists.push_back(pFsList);
    1497         }
    1498         catch (std::bad_alloc &)
    1499         {
    1500             vrc = VERR_NO_MEMORY;
    1501             break;
    1502         }
    1503 
    1504         AssertPtr(pFsList);
    1505         cOperations += (ULONG)pFsList->mVecEntries.size();
    1506 
    1507         itSrc++;
     1509            AssertPtr(pFsList);
     1510            cOperations += (ULONG)pFsList->mVecEntries.size();
     1511
     1512            itSrc++;
     1513        }
    15081514    }
    15091515
     
    15231529    if (RT_FAILURE(vrc))
    15241530    {
    1525         Assert(strErrorInfo.isNotEmpty());
     1531        if (strErrorInfo.isEmpty())
     1532            strErrorInfo = Utf8StrFmt(GuestSession::tr("Failed with %Rrc"), vrc);
    15261533        setProgressErrorMsg(VBOX_E_IPRT_ERROR, vrc, "%s", strErrorInfo.c_str());
    15271534    }
     
    16641671
    16651672    if (mDest.isEmpty())
    1666         return setProgressErrorMsg(VBOX_E_IPRT_ERROR, Utf8StrFmt(GuestSession::tr("Destination must not be empty")));
    1667 
    1668     GuestSessionFsSourceSet::iterator itSrc = mSources.begin();
    1669     while (itSrc != mSources.end())
    1670     {
    1671         Utf8Str strSrc = itSrc->strSource;
    1672         Utf8Str strDst = mDest;
    1673 
    1674         LogFlowFunc(("Source: strSrc=%s, strDst=%s\n", strSrc.c_str(), strDst.c_str()));
    1675 
    1676         if (strSrc.isEmpty())
    1677         {
    1678             strErrorInfo = Utf8StrFmt(GuestSession::tr("Source entry must not be empty"));
    1679             break;
    1680         }
    1681 
    1682         RTFSOBJINFO srcFsObjInfo;
    1683         rc = RTPathQueryInfo(strSrc.c_str(), &srcFsObjInfo, RTFSOBJATTRADD_NOTHING);
    1684         if (RT_FAILURE(rc))
    1685         {
    1686             strErrorInfo = Utf8StrFmt(GuestSession::tr("No such source file/directory: %s"), strSrc.c_str());
    1687             break;
    1688         }
    1689 
    1690         if (RTFS_IS_DIRECTORY(srcFsObjInfo.Attr.fMode))
    1691         {
    1692             if (itSrc->enmType != FsObjType_Directory)
    1693             {
    1694                 strErrorInfo = Utf8StrFmt(GuestSession::tr("Source is not a file: %s"), strSrc.c_str());
    1695                 rc = VERR_NOT_A_FILE;
     1673    {
     1674        strErrorInfo = Utf8StrFmt(GuestSession::tr("Destination must not be empty"));
     1675        rc = VERR_INVALID_PARAMETER;
     1676    }
     1677    else
     1678    {
     1679        GuestSessionFsSourceSet::iterator itSrc = mSources.begin();
     1680        while (itSrc != mSources.end())
     1681        {
     1682            Utf8Str strSrc = itSrc->strSource;
     1683            Utf8Str strDst = mDest;
     1684
     1685            LogFlowFunc(("Source: strSrc=%s, strDst=%s\n", strSrc.c_str(), strDst.c_str()));
     1686
     1687            if (strSrc.isEmpty())
     1688            {
     1689                strErrorInfo = Utf8StrFmt(GuestSession::tr("Source entry must not be empty"));
     1690                rc = VERR_INVALID_PARAMETER;
    16961691                break;
    16971692            }
    1698         }
    1699         else
    1700         {
    1701             if (itSrc->enmType == FsObjType_Directory)
    1702             {
    1703                 strErrorInfo = Utf8StrFmt(GuestSession::tr("Source is not a directory: %s"), strSrc.c_str());
    1704                 rc = VERR_NOT_A_DIRECTORY;
     1693
     1694            RTFSOBJINFO srcFsObjInfo;
     1695            rc = RTPathQueryInfo(strSrc.c_str(), &srcFsObjInfo, RTFSOBJATTRADD_NOTHING);
     1696            if (RT_FAILURE(rc))
     1697            {
     1698                strErrorInfo = Utf8StrFmt(GuestSession::tr("No such source file/directory: %s"), strSrc.c_str());
    17051699                break;
    17061700            }
    1707         }
    1708 
    1709         FsList *pFsList = NULL;
    1710         try
    1711         {
    1712             pFsList = new FsList(*this);
    1713             rc = pFsList->Init(strSrc, strDst, *itSrc);
    1714             if (RT_SUCCESS(rc))
     1701
     1702            if (RTFS_IS_DIRECTORY(srcFsObjInfo.Attr.fMode))
     1703            {
     1704                if (itSrc->enmType != FsObjType_Directory)
     1705                {
     1706                    strErrorInfo = Utf8StrFmt(GuestSession::tr("Source is not a file: %s"), strSrc.c_str());
     1707                    rc = VERR_NOT_A_FILE;
     1708                    break;
     1709                }
     1710            }
     1711            else
    17151712            {
    17161713                if (itSrc->enmType == FsObjType_Directory)
    17171714                {
    1718                     rc = pFsList->AddDirFromHost(strSrc);
    1719                 }
    1720                 else
    1721                     rc = pFsList->AddEntryFromHost(RTPathFilename(strSrc.c_str()), &srcFsObjInfo);
    1722             }
    1723 
    1724             if (RT_FAILURE(rc))
    1725             {
    1726                 delete pFsList;
    1727                 strErrorInfo = Utf8StrFmt(GuestSession::tr("Error adding source '%s' to list: %Rrc"), strSrc.c_str(), rc);
     1715                    strErrorInfo = Utf8StrFmt(GuestSession::tr("Source is not a directory: %s"), strSrc.c_str());
     1716                    rc = VERR_NOT_A_DIRECTORY;
     1717                    break;
     1718                }
     1719            }
     1720
     1721            FsList *pFsList = NULL;
     1722            try
     1723            {
     1724                pFsList = new FsList(*this);
     1725                rc = pFsList->Init(strSrc, strDst, *itSrc);
     1726                if (RT_SUCCESS(rc))
     1727                {
     1728                    if (itSrc->enmType == FsObjType_Directory)
     1729                    {
     1730                        rc = pFsList->AddDirFromHost(strSrc);
     1731                    }
     1732                    else
     1733                        rc = pFsList->AddEntryFromHost(RTPathFilename(strSrc.c_str()), &srcFsObjInfo);
     1734                }
     1735
     1736                if (RT_FAILURE(rc))
     1737                {
     1738                    delete pFsList;
     1739                    strErrorInfo = Utf8StrFmt(GuestSession::tr("Error adding source '%s' to list: %Rrc"), strSrc.c_str(), rc);
     1740                    break;
     1741                }
     1742
     1743                mVecLists.push_back(pFsList);
     1744            }
     1745            catch (std::bad_alloc &)
     1746            {
     1747                rc = VERR_NO_MEMORY;
    17281748                break;
    17291749            }
    17301750
    1731             mVecLists.push_back(pFsList);
    1732         }
    1733         catch (std::bad_alloc &)
    1734         {
    1735             rc = VERR_NO_MEMORY;
    1736             break;
    1737         }
    1738 
    1739         AssertPtr(pFsList);
    1740         cOperations += (ULONG)pFsList->mVecEntries.size();
    1741 
    1742         itSrc++;
     1751            AssertPtr(pFsList);
     1752            cOperations += (ULONG)pFsList->mVecEntries.size();
     1753
     1754            itSrc++;
     1755        }
    17431756    }
    17441757
     
    17581771    if (RT_FAILURE(rc))
    17591772    {
    1760         Assert(strErrorInfo.isNotEmpty());
     1773        if (strErrorInfo.isEmpty())
     1774            strErrorInfo = Utf8StrFmt(GuestSession::tr("Failed with %Rrc"), rc);
    17611775        setProgressErrorMsg(VBOX_E_IPRT_ERROR, strErrorInfo);
    17621776    }
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