VirtualBox

Changeset 33793 in vbox


Ignore:
Timestamp:
Nov 5, 2010 2:21:25 PM (14 years ago)
Author:
vboxsync
Message:

VBoxManage/Guest Copy: Destination path construction + normalization.

File:
1 edited

Legend:

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

    r33792 r33793  
    612612 *                              directory; needed for recursion.
    613613 * @param   pszFilter           Search filter (e.g. *.pdf).
     614 * @param   pszDest             Destination directory.
    614615 * @param   uFlags              Copy flags.
    615616 * @param   pcObjects           Where to store the overall objects to
     
    617618 * @param   pList               Pointer to the object list to use.
    618619 */
    619 int ctrlCopyDirectoryRead(const char *pszRootDir, const char *pszSubDir, const char *pszFilter,
     620int ctrlCopyDirectoryRead(const char *pszRootDir, const char *pszSubDir,
     621                          const char *pszFilter, const char *pszDest,
    620622                          uint32_t uFlags, uint32_t *pcObjects, PRTLISTNODE pList)
    621623{
     
    623625    /* Sub directory is optional. */
    624626    /* Filter directory is optional. */
     627    AssertPtrReturn(pszDest, VERR_INVALID_POINTER);
    625628    AssertPtrReturn(pcObjects, VERR_INVALID_POINTER);
    626629    AssertPtrReturn(pList, VERR_INVALID_POINTER);
     
    673676                        if (pszNewSub)
    674677                        {
    675                             rc = ctrlCopyDirectoryRead(pszRootDir, pszNewSub, pszFilter,
     678                            rc = ctrlCopyDirectoryRead(pszRootDir, pszNewSub,
     679                                                       pszFilter, pszDest,
    676680                                                       uFlags, pcObjects, pList);
    677681                            RTStrFree(pszNewSub);
     
    707711                                         DirEntry.szName) >= 0)
    708712                        {
    709                             if (RTStrAPrintf(&pszFileDest, "%s%s",
    710                                              pszSubDir ? pszSubDir : "",
     713                            if (RTStrAPrintf(&pszFileDest, "%s%s%s",
     714                                             pszDest, pszSubDir ? pszSubDir : "",
    711715                                             DirEntry.szName) <= 0)
    712716                            {
     
    771775            && RTFileExists(pszSourceAbs)) /* We have a single file ... */
    772776        {
    773             RTListInit(pList);
    774             rc = ctrlCopyDirectoryEntryAppend(pszSourceAbs, pszDest, pList);
    775             *pcObjects = 1;
     777            char *pszDestAbs = RTStrDup(pszDest);
     778            if (pszDestAbs)
     779            {
     780                RTPathStripFilename(pszDestAbs);
     781                rc = RTStrAAppend(&pszDestAbs, RTPATH_SLASH_STR);
     782                if (RT_SUCCESS(rc))
     783                    rc = RTStrAAppend(&pszDestAbs, RTPathFilename(pszSourceAbs));
     784
     785                RTListInit(pList);
     786                rc = ctrlCopyDirectoryEntryAppend(pszSourceAbs, pszDestAbs, pList);
     787                *pcObjects = 1;
     788
     789                RTStrFree(pszDestAbs);
     790            }
     791            else
     792                rc = VERR_NO_MEMORY;
    776793        }
    777794        else /* ... or a directory. */
     
    784801            char *pszFilter = RTPathFilename(pszSourceAbs);
    785802            char *pszSourceAbsRoot = RTStrDup(pszSourceAbs);
    786             if (pszSourceAbsRoot)
     803            char *pszDestAbs = RTStrDup(pszDest);
     804            if (   pszSourceAbsRoot
     805                && pszDestAbs)
    787806            {
    788807                if (pszFilter)
     
    809828                if (RT_SUCCESS(rc))
    810829                {
     830                    /*
     831                     * Make sure we have a valid destination path. All we can do
     832                     * here is to check whether we have a trailing slash -- the rest
     833                     * (i.e. path creation, rights etc.) needs to be done inside the guest.
     834                     */
     835                    size_t cch = strlen(pszDestAbs);
     836                    if (    cch > 1
     837                        &&  !RTPATH_IS_SLASH(pszDestAbs[cch - 1])
     838                        &&  !RTPATH_IS_SLASH(pszDestAbs[cch - 2]))
     839                    {
     840                        rc = RTStrAAppend(&pszDestAbs, RTPATH_SLASH_STR);
     841                    }
     842                }
     843
     844                if (RT_SUCCESS(rc))
     845                {
    811846                    RTListInit(pList);
    812847                    rc = ctrlCopyDirectoryRead(pszSourceAbsRoot, NULL /* Sub directory */,
    813                                                pszFilter,
     848                                               pszFilter, pszDestAbs,
    814849                                               uFlags, pcObjects, pList);
    815850                    if (RT_SUCCESS(rc) && *pcObjects == 0)
     
    817852                }
    818853
    819                 RTStrFree(pszSourceAbsRoot);
     854                if (pszDestAbs)
     855                    RTStrFree(pszDestAbs);
     856                if (pszSourceAbsRoot)
     857                    RTStrFree(pszSourceAbsRoot);
    820858            }
    821859            else
     
    11741212                    {
    11751213                        if (fVerbose)
     1214#ifndef DEBUG
    11761215                            RTPrintf("Copying \"%s\" (%u/%u) ...\n",
    11771216                                     pNode->pszSourcePath, uCurObject, cObjects);
    1178 
     1217#else
     1218                            RTPrintf("Copying \"%s\" to \"%s\" (%u/%u) ...\n",
     1219                                     pNode->pszSourcePath, pNode->pszDestPath, uCurObject, cObjects);
     1220#endif
    11791221                        /* Finally copy the desired file (if no dry run selected). */
    11801222                        if (!fDryRun)
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