VirtualBox

Changeset 39582 in vbox


Ignore:
Timestamp:
Dec 12, 2011 1:40:09 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
75344
Message:

VBoxManage/GuestCtrl: Update.

File:
1 edited

Legend:

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

    r39433 r39582  
    8282 * An entry for a source element, including an optional DOS-like wildcard (*,?).
    8383 */
    84 typedef struct SOURCEFILEENTRY
    85 {
    86     SOURCEFILEENTRY(const char *pszSource, const char *pszFilter)
    87                     : mSource(pszSource),
    88                       mFilter(pszFilter) {}
    89     SOURCEFILEENTRY(const char *pszSource)
    90                     : mSource(pszSource)
    91     {
    92         if (   !RTFileExists(pszSource)
    93             && !RTDirExists(pszSource))
    94         {
    95             /* No file and no directory -- maybe a filter? */
    96             char *pszFilename = RTPathFilename(pszSource);
    97             if (   pszFilename
    98                 && strpbrk(pszFilename, "*?"))
    99             {
    100                 /* Yep, get the actual filter part. */
    101                 mFilter = RTPathFilename(pszSource);
    102                 /* Remove the filter from actual sourcec directory name. */
    103                 RTPathStripFilename(mSource.mutableRaw());
    104                 mSource.jolt();
    105             }
    106         }
    107     }
    108     Utf8Str mSource;
    109     Utf8Str mFilter;
    110 } SOURCEFILEENTRY, *PSOURCEFILEENTRY;
     84class SOURCEFILEENTRY
     85{
     86    public:
     87
     88        SOURCEFILEENTRY(const char *pszSource, const char *pszFilter)
     89                        : mSource(pszSource),
     90                          mFilter(pszFilter) {}
     91
     92        SOURCEFILEENTRY(const char *pszSource)
     93                        : mSource(pszSource)
     94        {
     95            Parse(pszSource);
     96        }
     97
     98        const char* GetSource() const
     99        {
     100            return mSource.c_str();
     101        }
     102
     103        const char* GetFilter() const
     104        {
     105            return mFilter.c_str();
     106        }
     107
     108    private:
     109
     110        int Parse(const char *pszPath)
     111        {
     112            AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
     113
     114            if (   !RTFileExists(pszPath)
     115                && !RTDirExists(pszPath))
     116            {
     117                /* No file and no directory -- maybe a filter? */
     118                char *pszFilename = RTPathFilename(pszPath);
     119                if (   pszFilename
     120                    && strpbrk(pszFilename, "*?"))
     121                {
     122                    /* Yep, get the actual filter part. */
     123                    mFilter = RTPathFilename(pszPath);
     124                    /* Remove the filter from actual sourcec directory name. */
     125                    RTPathStripFilename(mSource.mutableRaw());
     126                    mSource.jolt();
     127                }
     128            }
     129
     130            return VINF_SUCCESS; /* @todo */
     131        }
     132
     133    private:
     134
     135        Utf8Str mSource;
     136        Utf8Str mFilter;
     137};
    111138typedef std::vector<SOURCEFILEENTRY> SOURCEVEC, *PSOURCEVEC;
    112139
     
    197224    OUTPUTTYPE_UNIX2DOS  = 20
    198225};
     226
     227static int ctrlCopyDirExists(PCOPYCONTEXT pContext, bool bGuest, const char *pszDir, bool *fExists);
    199228
    200229#endif /* VBOX_ONLY_DOCS */
     
    962991    size_t srcOff = strlen(pszSourceRoot);
    963992    AssertReturn(srcOff, VERR_INVALID_PARAMETER);
    964     int rc = RTPathJoin(szTranslated, sizeof(szTranslated),
    965                         pszDest, &pszSource[srcOff]);
     993
     994    char *pszDestPath = RTStrDup(pszDest);
     995    AssertPtrReturn(pszDestPath, VERR_NO_MEMORY);
     996
     997    int rc;
     998    if (!RTPathFilename(pszDestPath))
     999    {
     1000        rc = RTPathJoin(szTranslated, sizeof(szTranslated),
     1001                        pszDestPath, &pszSource[srcOff]);
     1002    }
     1003    else
     1004    {
     1005        char *pszDestFileName = RTStrDup(RTPathFilename(pszDestPath));
     1006        if (pszDestFileName)
     1007        {
     1008            RTPathStripFilename(pszDestPath);
     1009            rc = RTPathJoin(szTranslated, sizeof(szTranslated),
     1010                            pszDestPath, pszDestFileName);
     1011            RTStrFree(pszDestFileName);
     1012        }
     1013        else
     1014            rc = VERR_NO_MEMORY;
     1015    }
     1016    RTStrFree(pszDestPath);
     1017
    9661018    if (RT_SUCCESS(rc))
     1019    {
    9671020        *ppszTranslated = RTStrDup(szTranslated);
     1021#ifdef DEBUG
     1022        RTPrintf("Root: %s, Source: %s, Dest: %s, Translated: %s\n",
     1023                 pszSourceRoot, pszSource, pszDest, *ppszTranslated);
     1024#endif
     1025    }
    9681026    return rc;
    9691027}
     
    9721030static int tstTranslatePath()
    9731031{
     1032    RTAssertSetMayPanic(false /* Do not freak out, please. */);
     1033
    9741034    static struct
    9751035    {
     
    9831043        /* Invalid stuff. */
    9841044        { NULL, NULL, NULL, NULL, VERR_INVALID_POINTER },
     1045#ifdef RT_OS_WINDOWS
    9851046        /* Windows paths. */
    9861047        { "c:\\foo", "c:\\foo\\bar.txt", "c:\\test", "c:\\test\\bar.txt", VINF_SUCCESS },
    987         { "c:\\foo", "c:\\foo\\baz\\bar.txt", "c:\\test", "c:\\test\\baz\\bar.txt", VINF_SUCCESS }
    988         /* UNIX-like paths. */
     1048        { "c:\\foo", "c:\\foo\\baz\\bar.txt", "c:\\test", "c:\\test\\baz\\bar.txt", VINF_SUCCESS },
     1049#else /* RT_OS_WINDOWS */
     1050        { "/home/test/foo", "/home/test/foo/bar.txt", "/opt/test", "/opt/test/bar.txt", VINF_SUCCESS },
     1051        { "/home/test/foo", "/home/test/foo/baz/bar.txt", "/opt/test", "/opt/test/baz/bar.txt", VINF_SUCCESS },
     1052#endif /* !RT_OS_WINDOWS */
    9891053        /* Mixed paths*/
    9901054        /** @todo */
     1055        { NULL }
    9911056    };
    9921057
    993     int iTest = 0;
     1058    size_t iTest = 0;
    9941059    for (iTest; iTest < RT_ELEMENTS(aTests); iTest++)
    9951060    {
     
    10371102    AssertPtrReturn(pszDir, VERR_INVALID_POINTER);
    10381103
     1104    bool fDirExists;
     1105    if (ctrlCopyDirExists(pContext, pContext->fHostToGuest, pszDir, &fDirExists))
     1106    {
     1107        if (pContext->fVerbose)
     1108            RTPrintf("Directory \"%s\" already exists\n", pszDir);
     1109        return VINF_SUCCESS;
     1110    }
     1111
    10391112    if (pContext->fVerbose)
    10401113        RTPrintf("Creating directory \"%s\" ...\n", pszDir);
     
    10481121        HRESULT hrc = pContext->pGuest->DirectoryCreate(Bstr(pszDir).raw(),
    10491122                                                        Bstr(pContext->pszUsername).raw(), Bstr(pContext->pszPassword).raw(),
    1050                                                         700, DirectoryCreateFlag_Parents);
     1123                                                        0700, DirectoryCreateFlag_Parents);
    10511124        if (FAILED(hrc))
    10521125            rc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
     
    12861359
    12871360    if (pContext->fVerbose)
    1288         RTPrintf("Processing directory: %s\n", szCurDir);
     1361        RTPrintf("Processing host directory: %s\n", szCurDir);
    12891362
    12901363    /* Flag indicating whether the current directory was created on the
     
    14551528
    14561529    if (pContext->fVerbose)
    1457         RTPrintf("Processing directory: %s\n", szCurDir);
     1530        RTPrintf("Processing guest directory: %s\n", szCurDir);
    14581531
    14591532    /* Flag indicating whether the current directory was created on the
     
    17611834            {
    17621835                /* Last argument and no destination specified with
    1763                  * --target-directory yet? Then use the current argument
    1764                  * as destination. */
     1836                 * --target-directory yet? Then use the current
     1837                 * (= last) argument as destination. */
    17651838                if (   pArg->argc == GetState.iNext
    17661839                    && Utf8Dest.isEmpty())
     
    18201893    /* If the destination is a path, (try to) create it. */
    18211894    const char *pszDest = Utf8Dest.c_str();
    1822     AssertPtr(pszDest);
    1823     size_t lenDest = strlen(pszDest);
    1824     if (   lenDest
    1825          ||pszDest[lenDest - 1] == '/'
    1826         || pszDest[lenDest - 1] == '\\')
     1895    if (!RTPathFilename(pszDest))
    18271896    {
    18281897        vrc = ctrlCopyDirCreate(pContext, pszDest);
     1898    }
     1899    else
     1900    {
     1901        /* We assume we got a file name as destination -- so strip
     1902         * the actual file name and make sure the appropriate
     1903         * directories get created. */
     1904        char *pszDestDir = RTStrDup(pszDest);
     1905        AssertPtr(pszDestDir);
     1906        RTPathStripFilename(pszDestDir);
     1907        vrc = ctrlCopyDirCreate(pContext, pszDestDir);
     1908        RTStrFree(pszDestDir);
    18291909    }
    18301910
     
    18371917        for (unsigned long s = 0; s < vecSources.size(); s++)
    18381918        {
    1839             char *pszSource = RTStrDup(vecSources[s].mSource.c_str());
     1919            char *pszSource = RTStrDup(vecSources[s].GetSource());
    18401920            AssertPtrBreakStmt(pszSource, vrc = VERR_NO_MEMORY);
    1841             const char *pszFilter = vecSources[s].mFilter.c_str();
     1921            const char *pszFilter = vecSources[s].GetFilter();
    18421922            if (!strlen(pszFilter))
    18431923                pszFilter = NULL; /* If empty filter then there's no filter :-) */
     
    18551935
    18561936            /** @todo Files with filter?? */
    1857             bool fIsFile = false;
    1858             bool fExists;
     1937            bool fSourceIsFile = false;
     1938            bool fSourceExists;
    18591939
    18601940            size_t cchSource = strlen(pszSource);
     
    18631943            {
    18641944                if (pszFilter) /* Directory with filter (so use source root w/o the actual filter). */
    1865                     vrc = ctrlCopyDirExistsOnSource(pContext, pszSourceRoot, &fExists);
     1945                    vrc = ctrlCopyDirExistsOnSource(pContext, pszSourceRoot, &fSourceExists);
    18661946                else /* Regular directory without filter. */
    1867                     vrc = ctrlCopyDirExistsOnSource(pContext, pszSource, &fExists);
    1868 
    1869                 if (fExists)
     1947                    vrc = ctrlCopyDirExistsOnSource(pContext, pszSource, &fSourceExists);
     1948
     1949                if (fSourceExists)
    18701950                {
    18711951                    /* Strip trailing slash from our source element so that other functions
     
    18761956            else
    18771957            {
    1878                 vrc = ctrlCopyFileExistsOnSource(pContext, pszSource, &fExists);
     1958                vrc = ctrlCopyFileExistsOnSource(pContext, pszSource, &fSourceExists);
    18791959                if (   RT_SUCCESS(vrc)
    1880                     && fExists)
     1960                    && fSourceExists)
    18811961                {
    1882                     fIsFile = true;
     1962                    fSourceIsFile = true;
    18831963                }
    18841964            }
    18851965
    18861966            if (   RT_SUCCESS(vrc)
    1887                 && fExists)
    1888             {
    1889                 if (fIsFile)
     1967                && fSourceExists)
     1968            {
     1969                if (fSourceIsFile)
    18901970                {
    18911971                    /* Single file. */
     
    19141994
    19151995            if (   RT_SUCCESS(vrc)
    1916                 && !fExists)
     1996                && !fSourceExists)
    19171997            {
    19181998                RTMsgError("Warning: Source \"%s\" does not exist, skipping!\n",
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