VirtualBox

Changeset 38561 in vbox


Ignore:
Timestamp:
Aug 29, 2011 7:15:48 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
73727
Message:

VBoxManage/GuestCtrl: Enable directory copying, bugfixes, some simplifications + IPRT usage.

File:
1 edited

Legend:

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

    r38551 r38561  
    883883 *
    884884 * @return  IPRT status code.
    885  * @param   pszSourceRoot           Source root path.
     885 * @param   pszSourceRoot           Source root path. No trailing directory slash!
    886886 * @param   pszSource               Actual source to transform. Must begin with
    887887 *                                  the source root path!
     
    897897    AssertPtrReturn(pszDest, VERR_INVALID_POINTER);
    898898    AssertPtrReturn(ppszTranslated, VERR_INVALID_POINTER);
    899 
    900     /* Source path must contain the source root! */
    901     if (!RTPathStartsWith(pszSource, pszSourceRoot))
    902         return VERR_INVALID_PARAMETER;
     899    AssertReturn(RTPathStartsWith(pszSource, pszSourceRoot), VERR_INVALID_PARAMETER);
    903900
    904901    /* Construct the relative dest destination path by "subtracting" the
     
    909906     * translated = "d:\baz\bar\"
    910907     */
    911 
    912     size_t lenRoot = strlen(pszSourceRoot);
    913     AssertReturn(lenRoot, VERR_INVALID_PARAMETER);
    914     char *pszTranslated = RTStrDup(pszDest);
    915     AssertReturn(pszTranslated, VERR_NO_MEMORY);
    916     int vrc = RTStrAAppend(&pszTranslated, &pszSource[lenRoot]);
    917     if (RT_FAILURE(vrc))
    918         return vrc;
    919 
    920     *ppszTranslated = pszTranslated;
    921 
    922     return vrc;
     908    char szTranslated[RTPATH_MAX];
     909    size_t srcOff = strlen(pszSourceRoot);
     910    AssertReturn(srcOff, VERR_INVALID_PARAMETER);
     911    int rc = RTPathJoin(szTranslated, sizeof(szTranslated),
     912                        pszDest, &pszSource[srcOff]);
     913    if (RT_SUCCESS(rc))
     914        *ppszTranslated = RTStrDup(szTranslated);
     915    return rc;
    923916}
    924917
     
    1002995    else /* ... or on the host. */
    1003996    {
    1004         rc = RTDirCreate(pszDir, 700);
     997        rc = RTDirCreateFullPath(pszDir, 700);
    1005998        if (rc == VERR_ALREADY_EXISTS)
    1006999            rc = VINF_SUCCESS;
     
    12141207                              const char *pszSource, const char *pszFilter,
    12151208                              const char *pszDest, uint32_t fFlags,
    1216                               const char *pszSubDir /* For recursion */)
     1209                              const char *pszSubDir /* For recursion. */)
    12171210{
    12181211    AssertPtrReturn(pContext, VERR_INVALID_POINTER);
     
    12731266                        char *pszNewSub = NULL;
    12741267                        if (pszSubDir)
    1275                             RTStrAPrintf(&pszNewSub, "%s/%s", pszSubDir, DirEntry.szName);
     1268                            pszNewSub = RTPathJoinA(pszSubDir, DirEntry.szName);
    12761269                        else
    1277                             RTStrAPrintf(&pszNewSub, "%s", DirEntry.szName);
     1270                        {
     1271                            pszNewSub = RTStrDup(DirEntry.szName);
     1272                            RTPathStripTrailingSlash(pszNewSub);
     1273                        }
    12781274
    12791275                        if (pszNewSub)
     
    13201316                        if (RT_SUCCESS(rc))
    13211317                        {
    1322                             char *pszFileSource;
    1323                             if (RTStrAPrintf(&pszFileSource, "%s/%s",
    1324                                              szCurDir, DirEntry.szName))
     1318                            char *pszFileSource = RTPathJoinA(szCurDir, DirEntry.szName);
     1319                            if (pszFileSource)
    13251320                            {
    13261321                                char *pszFileDest;
     
    13671362                             const char *pszSource, const char *pszFilter,
    13681363                             const char *pszDest, uint32_t fFlags,
    1369                              const char *pszSubDir /* For recursion */)
     1364                             const char *pszSubDir /* For recursion. */)
    13701365{
    13711366    AssertPtrReturn(pContext, VERR_INVALID_POINTER);
     
    14221417                        char *pszNewSub = NULL;
    14231418                        if (pszSubDir)
    1424                             RTStrAPrintf(&pszNewSub, "%s/%s", pszSubDir, strDir.c_str());
     1419                            pszNewSub = RTPathJoinA(pszSubDir, strDir.c_str());
    14251420                        else
    1426                             RTStrAPrintf(&pszNewSub, "%s", strDir.c_str());
    1427 
     1421                        {
     1422                            pszNewSub = RTStrDup(strDir.c_str());
     1423                            RTPathStripTrailingSlash(pszNewSub);
     1424                        }
    14281425                        if (pszNewSub)
    14291426                        {
     
    14701467                        if (RT_SUCCESS(rc))
    14711468                        {
    1472                             char *pszFileSource;
    1473                             if (RTStrAPrintf(&pszFileSource, "%s/%s",
    1474                                              szCurDir, strFile.c_str()))
     1469                            char *pszFileSource = RTPathJoinA(szCurDir, strFile.c_str());
     1470                            if (pszFileSource)
    14751471                            {
    14761472                                char *pszFileDest;
     
    17541750        for (unsigned long s = 0; s < vecSources.size(); s++)
    17551751        {
    1756             const char *pszSource = vecSources[s].mSource.c_str();
     1752            char *pszSource = RTStrDup(vecSources[s].mSource.c_str());
     1753            AssertPtrBreakStmt(pszSource, vrc = VERR_NO_MEMORY);
    17571754            const char *pszFilter = vecSources[s].mFilter.c_str();
    17581755            if (!strlen(pszFilter))
     
    17731770            bool fIsFile = false;
    17741771            bool fExists;
    1775             Utf8Str Utf8CurSource(pszSource);
    1776             if (   Utf8CurSource.endsWith("/")
    1777                 || Utf8CurSource.endsWith("\\"))
    1778             {
    1779 #ifndef DEBUG_andy
    1780                 if (pContext->fHostToGuest)
    1781                 {
    1782 #endif
    1783                     if (pszFilter) /* Directory with filter. */
    1784                         vrc = ctrlCopyDirExistsOnSource(pContext, pszSourceRoot, &fExists);
    1785                     else /* Regular directory without filter. */
    1786                         vrc = ctrlCopyDirExistsOnSource(pContext, pszSource, &fExists);
    1787 #ifndef DEBUG_andy
    1788                 }
    1789                 else
    1790                 {
    1791                     RTMsgError("Copying of guest directories to the host is not supported yet!\n");
    1792                     vrc = VERR_NOT_IMPLEMENTED;
    1793                 }
    1794 #endif
     1772
     1773            size_t cchSource = strlen(pszSource);
     1774            if (   cchSource > 1
     1775                && RTPATH_IS_SLASH(pszSource[cchSource - 1]))
     1776            {
     1777                if (pszFilter) /* Directory with filter (so use source root w/o the actual filter). */
     1778                    vrc = ctrlCopyDirExistsOnSource(pContext, pszSourceRoot, &fExists);
     1779                else /* Regular directory without filter. */
     1780                    vrc = ctrlCopyDirExistsOnSource(pContext, pszSource, &fExists);
     1781
     1782                /* Strip trailing slash from our source element so that other functions
     1783                 * can use this stuff properly (like RTPathStartsWith). */
     1784                RTPathStripTrailingSlash(pszSource);
    17951785            }
    17961786            else
     
    17991789                if (   RT_SUCCESS(vrc)
    18001790                    && fExists)
     1791                {
    18011792                    fIsFile = true;
    1802             }
    1803 
    1804             if (RT_SUCCESS(vrc))
     1793                }
     1794            }
     1795
     1796            if (   RT_SUCCESS(vrc)
     1797                && fExists)
    18051798            {
    18061799                if (fIsFile)
     
    18371830                RTMsgError("Warning: Source \"%s\" does not exist, skipping!\n",
    18381831                           pszSource);
     1832                RTStrFree(pszSource);
    18391833                continue;
    18401834            }
    1841 
    1842             if (RT_FAILURE(vrc))
     1835            else if (RT_FAILURE(vrc))
    18431836            {
    18441837                RTMsgError("Error processing \"%s\", rc=%Rrc\n",
    18451838                           pszSource, vrc);
    1846                 break;
    1847             }
     1839                RTStrFree(pszSource);
     1840                break;
     1841            }
     1842
     1843            RTStrFree(pszSource);
    18481844        }
    18491845    }
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