VirtualBox

Changeset 75848 in vbox


Ignore:
Timestamp:
Nov 30, 2018 12:23:17 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
127051
Message:

VBoxManage/guestcontrol: copyto/from hacking

File:
1 edited

Legend:

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

    r75847 r75848  
    186186} GCTLCMDCTX, *PGCTLCMDCTX;
    187187
    188 /**
    189  * An entry for a source element, including an optional DOS-like wildcard (*,?).
    190  */
    191 class SourceFileEntry
    192 {
    193 public:
    194     SourceFileEntry(const char *pszSource, const char *pszFilter)
    195         : mSource(pszSource)
    196         , mFilter(pszFilter)
    197     {}
    198 
    199     SourceFileEntry(const char *pszSource)
    200     {
    201 /** @todo Using host parsing rules for guest filenames might be undesirable... */
    202 
    203         /* Look for filter and split off the filter part if present. */
    204         const char *pszFilename = RTPathFilename(pszSource);
    205         if (   !pszFilename
    206             || !strpbrk(pszFilename, "*?"))
    207             mSource.assign(pszSource);
    208         else
    209         {
    210             mFilter = pszFilename;
    211             size_t cch = pszFilename - pszSource;
    212             if (cch > 0 && pszFilename[-1] != ':')
    213                 cch--;
    214             mSource.assign(pszSource, cch);
    215         }
    216     }
    217 
    218     const Utf8Str &GetSource() const
    219     {
    220         return mSource;
    221     }
    222 
    223     const Utf8Str &GetFilter() const
    224     {
    225         return mFilter;
    226     }
    227 
    228 protected:
    229     Utf8Str mSource;
    230     Utf8Str mFilter;
    231 };
    232 typedef std::vector<SourceFileEntry> SourceVec;
    233188
    234189/**
     
    17361691    RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, RTGETOPTINIT_FLAGS_OPTS_FIRST);
    17371692
     1693    bool fDstMustBeDir = false;
    17381694    const char *pszDst = NULL;
    17391695    bool fFollow = false;
     
    17411697    uint32_t uUsage = fHostToGuest ? USAGE_GSTCTRL_COPYTO : USAGE_GSTCTRL_COPYFROM;
    17421698
    1743     SourceVec vecSources;
    1744 
    17451699    int vrc = VINF_SUCCESS;
    1746     while ((ch = RTGetOpt(&GetState, &ValueUnion)) != 0)
     1700    while (  (ch = RTGetOpt(&GetState, &ValueUnion)) != 0
     1701           && ch != VINF_GETOPT_NOT_OPTION)
    17471702    {
    17481703        /* For options that require an argument, ValueUnion has received the value. */
     
    17611716            case GETOPTDEF_COPY_TARGETDIR:
    17621717                pszDst = ValueUnion.psz;
    1763                 break;
    1764 
    1765             case VINF_GETOPT_NOT_OPTION:
    1766                 /* Last argument and no destination specified with --target-directory yet?
    1767                    Then use the current (= last) argument as destination. */
    1768                 if (   GetState.argc == GetState.iNext
    1769                     && pszDst == NULL)
    1770                     pszDst = ValueUnion.psz;
    1771                 else
    1772                 {
    1773                     try
    1774                     {
    1775                         vecSources.push_back(SourceFileEntry(ValueUnion.psz));
    1776                     }
    1777                     catch (std::bad_alloc &)
    1778                     {
    1779                         return RTMsgErrorExit(RTEXITCODE_FAILURE, "Out of memory");
    1780                     }
    1781                 }
     1718                fDstMustBeDir = true;
    17821719                break;
    17831720
     
    17871724    }
    17881725
    1789     if (!vecSources.size())
     1726    char **papszSources = RTGetOptNonOptionArrayPtr(&GetState);
     1727    size_t cSources = &argv[argc] - papszSources;
     1728
     1729    if (!cSources)
    17901730        return errorSyntaxEx(USAGE_GUESTCONTROL, uUsage, "No sources specified!");
     1731
     1732    /* Unless a --target-directory is given, the last argument is the destination, so
     1733       bump it from the source list. */
     1734    if (pszDst == NULL && cSources >= 2)
     1735        pszDst = papszSources[--cSources];
    17911736
    17921737    if (pszDst == NULL)
     
    18201765    HRESULT           rc = S_OK;
    18211766    ComPtr<IProgress> pProgress;
    1822 
    18231767/** @todo r=bird: This codes does nothing to handle the case where there are
    18241768 * multiple sources.  You need to do serveral thing before thats handled
     
    18351779 * The handling of the wildcard filtering expressions in sources was also just
    18361780 * skipped.   I've corrected this, but you still need to make up your mind wrt
    1837  * wildcards or not.
     1781 * wildcards or not.
     1782 *
     1783 * Update: I've kicked out the whole SourceFileEntry/vecSources stuff as we can
     1784 *         use argv directly without any unnecessary copying.  You just have to
     1785 *         look for the wildcards inside this loop instead.
    18381786 */
    1839     if (vecSources.size() != 1)
     1787    NOREF(fDstMustBeDir);
     1788    if (cSources != 1)
    18401789        return RTMsgErrorExitFailure("Only one source file or directory at the moment.");
    1841     for (size_t s = 0; s < vecSources.size(); s++)
    1842     {
    1843         Utf8Str const &strSrc    = vecSources[s].GetSource();
    1844         Utf8Str const &strFilter = vecSources[s].GetFilter();
    1845 
    1846         RT_NOREF(strFilter);
    1847         if (strFilter.isNotEmpty())
    1848             rcExit = RTMsgErrorExitFailure("Skipping '%s/%s' because wildcard expansion isn't implemented yet\n",
    1849                                            strSrc.c_str(),  strFilter.c_str());
     1790    for (size_t iSrc = 0; iSrc < cSources; iSrc++)
     1791    {
     1792        const char *pszSource = papszSources[iSrc];
     1793
     1794        /* Check if the source contains any wilecards in the last component, if so we
     1795           don't know how to deal with it yet and refuse. */
     1796        const char *pszSrcFinalComp = RTPathFilename(pszSource);
     1797        if (pszSrcFinalComp && strpbrk(pszSrcFinalComp, "*?"))
     1798            rcExit = RTMsgErrorExitFailure("Skipping '%s' because wildcard expansion isn't implemented yet\n", pszSource);
    18501799        else if (fHostToGuest)
    18511800        {
     
    18541803             */
    18551804            char szAbsSrc[RTPATH_MAX];
    1856             vrc = RTPathAbs(strSrc.c_str(), szAbsSrc, sizeof(szAbsSrc));
     1805            vrc = RTPathAbs(pszSource, szAbsSrc, sizeof(szAbsSrc));
    18571806            if (RT_SUCCESS(vrc))
    18581807            {
     
    18871836            }
    18881837            else
    1889                 rcExit = RTMsgErrorExitFailure("RTPathAbs failed on '%s': %Rrc", strSrc.c_str());
     1838                rcExit = RTMsgErrorExitFailure("RTPathAbs failed on '%s': %Rrc", pszSource);
    18901839        }
    18911840        else
     
    18961845            /* We need to query the source type on the guest first in order to know which copy flavor we need. */
    18971846            ComPtr<IGuestFsObjInfo> pFsObjInfo;
    1898             rc = pCtx->pGuestSession->FsObjQueryInfo(Bstr(strSrc).raw(), TRUE  /* fFollowSymlinks */, pFsObjInfo.asOutParam());
     1847            rc = pCtx->pGuestSession->FsObjQueryInfo(Bstr(pszSource).raw(), TRUE  /* fFollowSymlinks */, pFsObjInfo.asOutParam());
    18991848            if (SUCCEEDED(rc))
    19001849            {
     
    19071856                    {
    19081857                        if (pCtx->cVerbose)
    1909                             RTPrintf("Directory '%s' -> '%s'\n", strSrc.c_str(), pszDst);
     1858                            RTPrintf("Directory '%s' -> '%s'\n", pszSource, pszDst);
    19101859
    19111860                        SafeArray<DirectoryCopyFlag_T> aCopyFlags;
    19121861                        aCopyFlags.push_back(DirectoryCopyFlag_CopyIntoExisting);
    1913                         rc = pCtx->pGuestSession->DirectoryCopyFromGuest(Bstr(strSrc).raw(), Bstr(pszDst).raw(),
     1862                        rc = pCtx->pGuestSession->DirectoryCopyFromGuest(Bstr(pszSource).raw(), Bstr(pszDst).raw(),
    19141863                                                                         ComSafeArrayAsInParam(aCopyFlags), pProgress.asOutParam());
    19151864                    }
     
    19171866                    {
    19181867                        if (pCtx->cVerbose)
    1919                             RTPrintf("File '%s' -> '%s'\n", strSrc.c_str(), pszDst);
     1868                            RTPrintf("File '%s' -> '%s'\n", pszSource, pszDst);
    19201869
    19211870                        SafeArray<FileCopyFlag_T> aCopyFlags;
    1922                         rc = pCtx->pGuestSession->FileCopyFromGuest(Bstr(strSrc).raw(), Bstr(pszDst).raw(),
     1871                        rc = pCtx->pGuestSession->FileCopyFromGuest(Bstr(pszSource).raw(), Bstr(pszDst).raw(),
    19231872                                                                    ComSafeArrayAsInParam(aCopyFlags), pProgress.asOutParam());
    19241873                    }
    19251874                    else
    1926                         rcExit = RTMsgErrorExitFailure("Not a file or directory: %s\n", strSrc.c_str());
     1875                        rcExit = RTMsgErrorExitFailure("Not a file or directory: %s\n", pszSource);
    19271876                }
    19281877                else
     
    19301879            }
    19311880            else
    1932                 rcExit = RTMsgErrorExitFailure("FsObjQueryInfo failed on '%s': %Rrc", strSrc.c_str());
     1881                rcExit = RTMsgErrorExitFailure("FsObjQueryInfo failed on '%s': %Rhrc", pszSource, rc);
    19331882        }
    19341883    }
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