VirtualBox

Changeset 33791 in vbox


Ignore:
Timestamp:
Nov 5, 2010 12:55:55 PM (14 years ago)
Author:
vboxsync
Message:

VBoxManage/Guest Copy: Support recursive directory handling with file filters.

File:
1 edited

Legend:

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

    r33790 r33791  
    630630    int rc = VINF_SUCCESS;
    631631    char szCurDir[RTPATH_MAX];
     632    /* Construct current path. */
    632633    if (RTStrPrintf(szCurDir, sizeof(szCurDir), pszRootDir))
    633634    {
    634635        if (pszSubDir != NULL)
    635636            rc = RTPathAppend(szCurDir, sizeof(szCurDir), pszSubDir);
    636         if (RT_SUCCESS(rc) && pszFilter != NULL)
    637             rc = RTPathAppend(szCurDir, sizeof(szCurDir), pszFilter);
    638637    }
    639638    else
    640639        rc = VERR_NO_MEMORY;
    641640
    642     if (pszFilter)
    643         rc = RTDirOpenFiltered(&pDir, szCurDir,
    644 #ifdef RT_OS_WINDOWS
    645                                RTDIRFILTER_WINNT);
    646 #else
    647                                RTDIRFILTER_UNIX);
    648 #endif
    649     else
     641    if (RT_SUCCESS(rc))
     642    {
     643        /* Open directory without a filter - RTDirOpenFiltered unfortunately
     644         * cannot handle sub directories so we have to do the filtering ourselves. */
    650645        rc = RTDirOpen(&pDir, szCurDir);
    651 
    652     if (RT_SUCCESS(rc))
    653     {
    654         for (;;)
     646        for (;RT_SUCCESS(rc);)
    655647        {
    656648            RTDIRENTRY DirEntry;
     
    692684                case RTDIRENTRYTYPE_FILE:
    693685                {
    694                     char *pszFileSource = NULL;
    695                     char *pszFileDest = NULL;
    696                     if (RTStrAPrintf(&pszFileSource, "%s%s%s",
    697                                      pszRootDir, pszSubDir ? pszSubDir : "",
    698                                      DirEntry.szName) >= 0)
     686                    bool fProcess = false;
     687                    if (pszFilter && RTStrSimplePatternMatch(pszFilter, DirEntry.szName))
     688                        fProcess = true;
     689                    else if (!pszFilter)
     690                        fProcess = true;
     691
     692                    if (fProcess)
    699693                    {
    700                         if (RTStrAPrintf(&pszFileDest, "%s%s",
    701                                          pszSubDir ? pszSubDir : "",
    702                                          DirEntry.szName) <= 0)
     694                        char *pszFileSource = NULL;
     695                        char *pszFileDest = NULL;
     696                        if (RTStrAPrintf(&pszFileSource, "%s%s%s",
     697                                         pszRootDir, pszSubDir ? pszSubDir : "",
     698                                         DirEntry.szName) >= 0)
    703699                        {
     700                            if (RTStrAPrintf(&pszFileDest, "%s%s",
     701                                             pszSubDir ? pszSubDir : "",
     702                                             DirEntry.szName) <= 0)
     703                            {
     704                                rc = VERR_NO_MEMORY;
     705                            }
     706                        }
     707                        else
    704708                            rc = VERR_NO_MEMORY;
     709
     710                        if (RT_SUCCESS(rc))
     711                        {
     712                            rc = ctrlCopyDirectoryEntryAppend(pszFileSource, pszFileDest, pList);
     713                            if (RT_SUCCESS(rc))
     714                                *pcObjects = *pcObjects + 1;
    705715                        }
     716
     717                        if (pszFileSource)
     718                            RTStrFree(pszFileSource);
     719                        if (pszFileDest)
     720                            RTStrFree(pszFileDest);
    706721                    }
    707                     else
    708                         rc = VERR_NO_MEMORY;
    709 
    710                     if (RT_SUCCESS(rc))
    711                     {
    712                         rc = ctrlCopyDirectoryEntryAppend(pszFileSource, pszFileDest, pList);
    713                         if (RT_SUCCESS(rc))
    714                             *pcObjects = *pcObjects + 1;
    715                     }
    716 
    717                     if (pszFileSource)
    718                         RTStrFree(pszFileSource);
    719                     if (pszFileDest)
    720                         RTStrFree(pszFileDest);
    721                     break;
    722                 }
     722                }
     723                break;
    723724
    724725                case RTDIRENTRYTYPE_SYMLINK:
Note: See TracChangeset for help on using the changeset viewer.

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