VirtualBox

Changeset 38656 in vbox


Ignore:
Timestamp:
Sep 6, 2011 12:34:26 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
73866
Message:

VBoxManage/GuestCtrl: Obey --dryrun, verbose adjustments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp

    r38586 r38656  
    7373    IGuest *pGuest;
    7474    bool fVerbose;
     75    bool fDryRun;
    7576    bool fHostToGuest;
    7677    char *pszUsername;
     
    821822 * @param   pGuest                  Pointer to IGuest interface to use.
    822823 * @param   fVerbose                Flag indicating if we want to run in verbose mode.
     824 * @param   fDryRun                 Flag indicating if we want to run a dry run only.
    823825 * @param   fHostToGuest            Flag indicating if we want to copy from host to guest
    824826 *                                  or vice versa.
     
    827829 * @param   ppContext               Pointer which receives the allocated copy context.
    828830 */
    829 static int ctrlCopyContextCreate(IGuest *pGuest, bool fVerbose, bool fHostToGuest,
     831static int ctrlCopyContextCreate(IGuest *pGuest, bool fVerbose, bool fDryRun,
     832                                 bool fHostToGuest,
    830833                                 const char *pszUsername, const char *pszPassword,
    831834                                 PCOPYCONTEXT *ppContext)
     
    839842    pContext->pGuest = pGuest;
    840843    pContext->fVerbose = fVerbose;
     844    pContext->fDryRun = fDryRun;
    841845    pContext->fHostToGuest = fHostToGuest;
    842846
     
    984988    AssertPtrReturn(pszDir, VERR_INVALID_POINTER);
    985989
     990    if (pContext->fVerbose)
     991        RTPrintf("Creating directory \"%s\" ...\n", pszDir);
     992
     993    if (pContext->fDryRun)
     994        return VINF_SUCCESS;
     995
    986996    int rc = VINF_SUCCESS;
    987997    if (pContext->fHostToGuest) /* We want to create directories on the guest. */
     
    11601170
    11611171    if (pContext->fVerbose)
    1162     {
    11631172        RTPrintf("Copying \"%s\" to \"%s\" ...\n",
    11641173                 pszFileSource, pszFileDest);
    1165     }
     1174
     1175    if (pContext->fDryRun)
     1176        return VINF_SUCCESS;
    11661177
    11671178    int vrc = VINF_SUCCESS;
     
    12251236        rc = RTPathAppend(szCurDir, sizeof(szCurDir), pszSubDir);
    12261237
     1238    if (pContext->fVerbose)
     1239        RTPrintf("Processing directory: %s\n", szCurDir);
     1240
    12271241    /* Flag indicating whether the current directory was created on the
    12281242     * target or not. */
     
    12631277                        || !strcmp(DirEntry.szName, ".."))
    12641278                        break;
     1279
     1280                    if (pContext->fVerbose)
     1281                        RTPrintf("Directory: %s\n", DirEntry.szName);
    12651282
    12661283                    if (fFlags & CopyFileFlag_Recursive)
     
    12991316                case RTDIRENTRYTYPE_FILE:
    13001317                {
    1301                     if (   !pszFilter
    1302                         || RTStrSimplePatternMatch(pszFilter, DirEntry.szName))
     1318                    if (   pszFilter
     1319                        && !RTStrSimplePatternMatch(pszFilter, DirEntry.szName))
    13031320                    {
    1304                         if (!fDirCreated)
     1321                        break; /* Filter does not match. */
     1322                    }
     1323
     1324                    if (pContext->fVerbose)
     1325                        RTPrintf("File: %s\n", DirEntry.szName);
     1326
     1327                    if (!fDirCreated)
     1328                    {
     1329                        char *pszDestDir;
     1330                        rc = ctrlCopyTranslatePath(pszSource, szCurDir,
     1331                                                   pszDest, &pszDestDir);
     1332                        if (RT_SUCCESS(rc))
    13051333                        {
    1306                             char *pszDestDir;
    1307                             rc = ctrlCopyTranslatePath(pszSource, szCurDir,
    1308                                                        pszDest, &pszDestDir);
     1334                            rc = ctrlCopyDirCreate(pContext, pszDestDir);
     1335                            RTStrFree(pszDestDir);
     1336
     1337                            fDirCreated = true;
     1338                        }
     1339                    }
     1340
     1341                    if (RT_SUCCESS(rc))
     1342                    {
     1343                        char *pszFileSource = RTPathJoinA(szCurDir, DirEntry.szName);
     1344                        if (pszFileSource)
     1345                        {
     1346                            char *pszFileDest;
     1347                            rc = ctrlCopyTranslatePath(pszSource, pszFileSource,
     1348                                                       pszDest, &pszFileDest);
    13091349                            if (RT_SUCCESS(rc))
    13101350                            {
    1311                                 rc = ctrlCopyDirCreate(pContext, pszDestDir);
    1312                                 RTStrFree(pszDestDir);
    1313 
    1314                                 fDirCreated = true;
     1351                                rc = ctrlCopyFileToDest(pContext, pszFileSource,
     1352                                                        pszFileDest, 0 /* Flags */);
     1353                                RTStrFree(pszFileDest);
    13151354                            }
    1316                         }
    1317 
    1318                         if (RT_SUCCESS(rc))
    1319                         {
    1320                             char *pszFileSource = RTPathJoinA(szCurDir, DirEntry.szName);
    1321                             if (pszFileSource)
    1322                             {
    1323                                 char *pszFileDest;
    1324                                 rc = ctrlCopyTranslatePath(pszSource, pszFileSource,
    1325                                                            pszDest, &pszFileDest);
    1326                                 if (RT_SUCCESS(rc))
    1327                                 {
    1328                                     rc = ctrlCopyFileToDest(pContext, pszFileSource,
    1329                                                             pszFileDest, 0 /* Flags */);
    1330                                     RTStrFree(pszFileDest);
    1331                                 }
    1332                                 RTStrFree(pszFileSource);
    1333                             }
     1355                            RTStrFree(pszFileSource);
    13341356                        }
    13351357                    }
     
    13831405        return rc;
    13841406
     1407    if (pContext->fVerbose)
     1408        RTPrintf("Processing directory: %s\n", szCurDir);
     1409
    13851410    /* Flag indicating whether the current directory was created on the
    13861411     * target or not. */
     
    14131438                        || !strName.compare(Bstr("..")))
    14141439                        break;
     1440
     1441                    if (pContext->fVerbose)
     1442                    {
     1443                        Utf8Str Utf8Dir(strName);
     1444                        RTPrintf("Directory: %s\n", Utf8Dir.c_str());
     1445                    }
    14151446
    14161447                    if (fFlags & CopyFileFlag_Recursive)
     
    14501481                {
    14511482                    Utf8Str strFile(strName);
    1452                     if (   !pszFilter
    1453                         || RTStrSimplePatternMatch(pszFilter, strFile.c_str()))
     1483                    if (   pszFilter
     1484                        && !RTStrSimplePatternMatch(pszFilter, strFile.c_str()))
    14541485                    {
    1455                         if (!fDirCreated)
     1486                        break; /* Filter does not match. */
     1487                    }
     1488
     1489                    if (pContext->fVerbose)
     1490                        RTPrintf("File: %s\n", strFile.c_str());
     1491
     1492                    if (!fDirCreated)
     1493                    {
     1494                        char *pszDestDir;
     1495                        rc = ctrlCopyTranslatePath(pszSource, szCurDir,
     1496                                                   pszDest, &pszDestDir);
     1497                        if (RT_SUCCESS(rc))
    14561498                        {
    1457                             char *pszDestDir;
    1458                             rc = ctrlCopyTranslatePath(pszSource, szCurDir,
    1459                                                        pszDest, &pszDestDir);
     1499                            rc = ctrlCopyDirCreate(pContext, pszDestDir);
     1500                            RTStrFree(pszDestDir);
     1501
     1502                            fDirCreated = true;
     1503                        }
     1504                    }
     1505
     1506                    if (RT_SUCCESS(rc))
     1507                    {
     1508                        char *pszFileSource = RTPathJoinA(szCurDir, strFile.c_str());
     1509                        if (pszFileSource)
     1510                        {
     1511                            char *pszFileDest;
     1512                            rc = ctrlCopyTranslatePath(pszSource, pszFileSource,
     1513                                                       pszDest, &pszFileDest);
    14601514                            if (RT_SUCCESS(rc))
    14611515                            {
    1462                                 rc = ctrlCopyDirCreate(pContext, pszDestDir);
    1463                                 RTStrFree(pszDestDir);
    1464 
    1465                                 fDirCreated = true;
     1516                                rc = ctrlCopyFileToDest(pContext, pszFileSource,
     1517                                                        pszFileDest, 0 /* Flags */);
     1518                                RTStrFree(pszFileDest);
    14661519                            }
     1520                            RTStrFree(pszFileSource);
    14671521                        }
    1468 
    1469                         if (RT_SUCCESS(rc))
    1470                         {
    1471                             char *pszFileSource = RTPathJoinA(szCurDir, strFile.c_str());
    1472                             if (pszFileSource)
    1473                             {
    1474                                 char *pszFileDest;
    1475                                 rc = ctrlCopyTranslatePath(pszSource, pszFileSource,
    1476                                                            pszDest, &pszFileDest);
    1477                                 if (RT_SUCCESS(rc))
    1478                                 {
    1479                                     rc = ctrlCopyFileToDest(pContext, pszFileSource,
    1480                                                             pszFileDest, 0 /* Flags */);
    1481                                     RTStrFree(pszFileDest);
    1482                                 }
    1483                                 RTStrFree(pszFileSource);
    1484                             }
    1485                             else
    1486                                 rc = VERR_NO_MEMORY;
    1487                         }
     1522                        else
     1523                            rc = VERR_NO_MEMORY;
    14881524                    }
    14891525                    break;
     
    17241760     * the routines need to know when handling the actual copying. */
    17251761    PCOPYCONTEXT pContext;
    1726     vrc = ctrlCopyContextCreate(guest, fVerbose, fHostToGuest,
     1762    vrc = ctrlCopyContextCreate(guest, fVerbose, fDryRun, fHostToGuest,
    17271763                                Utf8UserName.c_str(), Utf8Password.c_str(),
    17281764                                &pContext);
     
    17821818                    vrc = ctrlCopyDirExistsOnSource(pContext, pszSource, &fExists);
    17831819
    1784                 /* Strip trailing slash from our source element so that other functions
    1785                  * can use this stuff properly (like RTPathStartsWith). */
    1786                 RTPathStripTrailingSlash(pszSource);
     1820                if (fExists)
     1821                {
     1822                    /* Strip trailing slash from our source element so that other functions
     1823                     * can use this stuff properly (like RTPathStartsWith). */
     1824                    RTPathStripTrailingSlash(pszSource);
     1825                }
    17871826            }
    17881827            else
     
    18121851                    }
    18131852                    else
    1814                     {
    18151853                        RTMsgError("Unable to translate path for \"%s\", rc=%Rrc\n",
    18161854                                   pszSource, vrc);
    1817                     }
    18181855                }
    18191856                else
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