VirtualBox

Changeset 33301 in vbox


Ignore:
Timestamp:
Oct 21, 2010 11:41:49 AM (14 years ago)
Author:
vboxsync
Message:

Guest Copy/VBoxManage+Main: Implemented first working "copyto" command (single file only, no progress), in development.

Location:
trunk/src/VBox
Files:
4 edited

Legend:

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

    r33294 r33301  
    8080                 "                            copyto <vmname>|<uuid>\n"
    8181                 "                            <source on host> <destination on guest>\n"
     82                 "                            --username <name> --password <password>\n"
    8283                 "                            [--recursive] [--verbose] [--flags <flags>]\n"
    8384#endif
     
    368369                    RTPrintf("Waiting for process to exit ...\n");
    369370
    370                 /* setup signal handling if cancelable */
     371                /* Setup signal handling if cancelable. */
    371372                ASSERT(progress);
    372373                bool fCanceledAlready = false;
     
    441442                    }
    442443
    443 #if 0
     444#if 1
    444445                    static int sent = 0;
    445446                    if (sent < 1)
     
    627628    Utf8Str Utf8Source(a->argv[1]);
    628629    Utf8Str Utf8Dest(a->argv[2]);
    629     uint32_t uFlags = 0;
     630    Utf8Str Utf8UserName;
     631    Utf8Str Utf8Password;
     632    uint32_t uFlags = CopyFileFlag_None;
    630633    bool fVerbose = false;
    631634    bool fCopyRecursive = false;
     
    635638    for (int i = 3; usageOK && i < a->argc; i++)
    636639    {
    637         if (!strcmp(a->argv[i], "--flags"))
     640        if (   !strcmp(a->argv[i], "--username")
     641            || !strcmp(a->argv[i], "--user"))
     642        {
     643            if (i + 1 >= a->argc)
     644                usageOK = false;
     645            else
     646            {
     647                Utf8UserName = a->argv[i + 1];
     648                ++i;
     649            }
     650        }
     651        else if (   !strcmp(a->argv[i], "--password")
     652                 || !strcmp(a->argv[i], "--pwd"))
     653        {
     654            if (i + 1 >= a->argc)
     655                usageOK = false;
     656            else
     657            {
     658                Utf8Password = a->argv[i + 1];
     659                ++i;
     660            }
     661        }
     662        else if (!strcmp(a->argv[i], "--flags"))
    638663        {
    639664            if (i + 1 >= a->argc)
     
    678703        return errorSyntax(USAGE_GUESTCONTROL,
    679704                           "No destination specified!");
     705
     706    if (Utf8UserName.isEmpty())
     707        return errorSyntax(USAGE_GUESTCONTROL,
     708                           "No user name specified!");
    680709
    681710    /* lookup VM. */
     
    716745            /* Do the copy. */
    717746            rc = guest->CopyToGuest(Bstr(Utf8Source).raw(), Bstr(Utf8Dest).raw(),
     747                                    Bstr(Utf8UserName).raw(), Bstr(Utf8Password).raw(),
    718748                                    uFlags, progress.asOutParam());
    719749            if (FAILED(rc))
     
    733763            else
    734764            {
    735                 /* setup signal handling if cancelable */
     765                /* Setup signal handling if cancelable. */
    736766                ASSERT(progress);
    737767                bool fCanceledAlready = false;
     
    751781                BOOL fCompleted = FALSE;
    752782                BOOL fCanceled = FALSE;
    753                 while (SUCCEEDED(progress->COMGETTER(Completed(&fCompleted))))
     783                while (   SUCCEEDED(progress->COMGETTER(Completed(&fCompleted)))
     784                       && !fCompleted)
    754785                {
    755786                    /* Process async cancelation */
  • trunk/src/VBox/Main/GuestImpl.cpp

    r33253 r33301  
    3434#include <iprt/cpp/utils.h>
    3535#include <iprt/dir.h>
     36#include <iprt/file.h>
    3637#include <iprt/getopt.h>
    3738#include <iprt/list.h>
     
    15211522                            && fCompleted)
    15221523                        {
    1523                             PCALLBACKDATAEXECINSTATUS pData = (PCALLBACKDATAEXECINSTATUS)it->second.pvData;
     1524                            PCALLBACKDATAEXECINSTATUS pStatusData = (PCALLBACKDATAEXECINSTATUS)it->second.pvData;
    15241525                            Assert(it->second.cbData == sizeof(CALLBACKDATAEXECINSTATUS));
    1525                             AssertPtr(pData);
    1526 
    1527                             *aBytesWritten = pData->cbProcessed;
     1526                            AssertPtr(pStatusData);
     1527
     1528                            *aBytesWritten = pStatusData->cbProcessed;
    15281529                        }
    15291530                    }
     
    19301931#endif
    19311932
    1932 STDMETHODIMP Guest::CopyToGuest(IN_BSTR aSource, IN_BSTR aDest, ULONG aFlags,
    1933                                 IProgress **aProgress)
     1933/** @todo For having a progress object which actually reports something,
     1934  *       the actual copy loop (see below) needs to go to some worker thread
     1935  *       so that this routine can return to the caller (and the caller then
     1936  *       can do display a progress). */
     1937STDMETHODIMP Guest::CopyToGuest(IN_BSTR aSource, IN_BSTR aDest,
     1938                                IN_BSTR aUserName, IN_BSTR aPassword,
     1939                                ULONG aFlags, IProgress **aProgress)
    19341940{
    19351941#ifndef VBOX_WITH_GUEST_CONTROL
     
    19491955
    19501956    /* Validate flags. */
    1951     if (aFlags)
     1957    if (aFlags != CopyFileFlag_None)
    19521958    {
    19531959        if (   !(aFlags & CopyFileFlag_Recursive)
     
    19631969    try
    19641970    {
    1965         ULONG cObjectsToCopy = 0;
    1966         RTLISTNODE listEntries;
     1971        /*ULONG cObjectsToCopy = 0;
     1972        RTLISTNODE listEntries;*/
    19671973
    19681974        Utf8Str Utf8Source(aSource);
    19691975        Utf8Str Utf8Dest(aDest);
    1970 
    1971         char *pszSourceAbs = RTPathAbsDup(Utf8Source.c_str());
    1972         if (!pszSourceAbs)
    1973         {
    1974             rc = setError(VBOX_E_IPRT_ERROR,
    1975                           tr("Could not determine absolute path of \"%s\""), Utf8Source.c_str());
     1976        Utf8Str Utf8UserName(aUserName);
     1977        Utf8Str Utf8Password(aPassword);
     1978
     1979        /* Does our source file exist? */
     1980        if (!RTFileExists(Utf8Source.c_str()))
     1981        {
     1982            rc = setError(VBOX_E_FILE_ERROR,
     1983                          tr("Source file \"%s\" does not exist"), Utf8Source.c_str());
    19761984        }
    19771985        else
    19781986        {
     1987            RTFILE fileSource;
     1988            int vrc = RTFileOpen(&fileSource, Utf8Source.c_str(),
     1989                                 RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
     1990            if (RT_FAILURE(vrc))
     1991            {
     1992                rc = setError(VBOX_E_IPRT_ERROR,
     1993                              tr("Could not open source file \"%s\" for reading, rc=%Rrc"),
     1994                              Utf8Source.c_str(),  vrc);
     1995            }
     1996            else
     1997            {
     1998                uint64_t cbSize;
     1999                vrc = RTFileGetSize(fileSource, &cbSize);
     2000                if (RT_FAILURE(vrc))
     2001                {
     2002                    rc = setError(VBOX_E_IPRT_ERROR,
     2003                                  tr("Could not query file size of \"%s\", rc=%Rrc"),
     2004                                  Utf8Source.c_str(),  vrc);
     2005                }
     2006                else
     2007                {
     2008                    com::SafeArray<IN_BSTR> args;
     2009                    com::SafeArray<IN_BSTR> env;
     2010
     2011                    /*
     2012                     * Prepare tool command line.
     2013                     */
     2014                    args.push_back(Bstr("vbox_cat").raw()); /* The actual (internal) tool to use (as argv[0]). */
     2015                    args.push_back(Bstr("--output").raw()); /* We want to write a file ... */
     2016                    args.push_back(Bstr(Utf8Dest).raw());   /* ... which is specified here. */
     2017
     2018                    /*
     2019                     * Okay, since we gathered all stuff we need until now to start the
     2020                     * actual copying, start the guest part now.
     2021                     */
     2022                    ULONG uPID;
     2023                    ComPtr<IProgress> execProgress;
     2024                    rc = ExecuteProcess(Bstr("vbox_cat").raw(), 0 /* Flags */,
     2025                                        ComSafeArrayAsInParam(args),
     2026                                        ComSafeArrayAsInParam(env),
     2027                                        Bstr(Utf8UserName).raw(),
     2028                                        Bstr(Utf8Password).raw(), 0 /* Timeout */,
     2029                                        &uPID, execProgress.asOutParam());
     2030                    if (SUCCEEDED(rc))
     2031                    {
     2032                        /* Wait for process to exit ... */
     2033                        BOOL fCompleted = FALSE;
     2034                        BOOL fCanceled = FALSE;
     2035
     2036                        size_t cbRead;
     2037                        SafeArray<BYTE> aInputData(_64K);
     2038                        while (   SUCCEEDED(execProgress->COMGETTER(Completed(&fCompleted)))
     2039                               && !fCompleted)
     2040                        {
     2041                            vrc = RTFileRead(fileSource, (uint8_t*)aInputData.raw(), _64K, &cbRead);
     2042                            if (   cbRead == 0
     2043                                || vrc == VERR_EOF)
     2044                                break;
     2045
     2046                            aInputData.resize(cbRead);
     2047
     2048                            /* Did we reach the end of the content
     2049                             * we want to transfer (last chunk)? */
     2050                            ULONG uFlags = ProcessInputFlag_None;
     2051                            if (cbRead < _64K)
     2052                                uFlags |= ProcessInputFlag_EndOfFile;
     2053
     2054                            /* Transfer the current chunk ... */
     2055                            ULONG uBytesWritten;
     2056                            rc = SetProcessInput(uPID, uFlags,
     2057                                                 ComSafeArrayAsInParam(aInputData), &uBytesWritten);
     2058                            if (FAILED(rc))
     2059                                break;
     2060
     2061                            /* Progress canceled by Main API? */
     2062                            if (   SUCCEEDED(execProgress->COMGETTER(Canceled(&fCanceled)))
     2063                                && fCanceled)
     2064                            {
     2065                                break;
     2066                            }
     2067                        }
     2068
     2069                        if (SUCCEEDED(rc))
     2070                        {
     2071                            /* Return the progress to the caller. */
     2072                            execProgress.queryInterfaceTo(aProgress);
     2073                        }
     2074                    }
     2075                }
     2076                RTFileClose(fileSource);
     2077            }
     2078#if 0
     2079            /*
     2080             * Does the source directory exist?
     2081             */
    19792082            if (RTDirExists(pszSourceAbs))
    19802083            {
     2084                /* If no trailing slash is present, append. */
    19812085                size_t cch = strlen(pszSourceAbs);
    19822086                if (    cch > 1
     
    19892093                                      tr("Failed to extend source path, rc=%Rrc\n"), vrc);
    19902094                }
     2095            }
     2096
     2097            if (SUCCEEDED(rc))
     2098            {
     2099#endif
     2100#if 0
     2101                /*
     2102                 * Create progress object.  Note that this is a multi operation
     2103                 * object to perform an operation per file object we just gathered
     2104                 * in our list above.
     2105                 *
     2106                 * Stages:
     2107                 * - 0: Starting copy process
     2108                 * - 1: Copying file
     2109                 * - 2: Finished
     2110                 */
     2111                ComObjPtr <Progress> progress;
     2112                rc = progress.createObject();
     2113                if (SUCCEEDED(rc))
     2114                {
     2115                    rc = progress->init(static_cast<IGuest*>(this),
     2116                                        Bstr(tr("Copying to guest")).raw(),
     2117                                        TRUE,
     2118                                        3,                                  /* Number of stages. */
     2119                                        Bstr(tr("Starting ...")).raw());    /* Description of first stage. */
     2120                }
     2121                if (FAILED(rc)) return rc;
     2122
     2123                rc = guest->ExecuteProcess(Bstr(Utf8Cmd).raw(), uFlags,
     2124                                           ComSafeArrayAsInParam(args),
     2125                                           ComSafeArrayAsInParam(env),
     2126                                           Bstr(Utf8UserName).raw(),
     2127                                           Bstr(Utf8Password).raw(), u32TimeoutMS,
     2128                                           &uPID, progress.asOutParam());
     2129                if (SUCCEEDED(rc))
     2130                {
     2131
     2132                }
     2133#endif
     2134#if 0
    19912135            }
    19922136
     
    20332177                }
    20342178                if (FAILED(rc)) return rc;
     2179#endif
     2180#if 0
     2181                /*
     2182                 * Now copy all files in the list ...
     2183                 */
     2184                for (ULONG l=0; l < cObjectsToCopy; l++)
     2185                {
     2186                    rc = guest->ExecuteProcess(Bstr(Utf8Cmd).raw(), uFlags,
     2187                                       ComSafeArrayAsInParam(args),
     2188                                       ComSafeArrayAsInParam(env),
     2189                                       Bstr(Utf8UserName).raw(),
     2190                                       Bstr(Utf8Password).raw(), u32TimeoutMS,
     2191                                       &uPID, progress.asOutParam());
     2192                }
     2193#endif
    20352194#if 0
    20362195                if (SUCCEEDED(rc))
     
    20792238                }
    20802239#endif
    2081                 /* Destroy list. */
     2240#if 0
     2241                /* Destroy file list. */
    20822242                VBoxGuestDirEntry *pNode = RTListNodeGetFirst(&listEntries, VBoxGuestDirEntry, Node);
    20832243                while (pNode)
     
    20972257                }
    20982258            }
     2259#endif
    20992260        }
    21002261    }
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r33300 r33301  
    76057605  <interface
    76067606     name="IGuest" extends="$unknown"
    7607      uuid="9a2d971f-62cb-4e84-b91a-c5adc2b7c6b8"
     7607     uuid="ed69cdce-2905-4275-872b-3c743a85c584"
    76087608     wsmap="managed"
    76097609     >
     
    79117911        <desc>
    79127912          Bar.
     7913        </desc>
     7914      </param>
     7915      <param name="userName" type="wstring" dir="in">
     7916        <desc>
     7917          User name under which the copy command will be executed; the
     7918          user has to exist and have the appropriate rights to write to
     7919          the destination path.
     7920        </desc>
     7921      </param>
     7922      <param name="password" type="wstring" dir="in">
     7923        <desc>
     7924          Password of the user account specified.
    79137925        </desc>
    79147926      </param>
  • trunk/src/VBox/Main/include/GuestImpl.h

    r33247 r33301  
    101101    STDMETHOD(SetProcessInput)(ULONG aPID, ULONG aFlags, ComSafeArrayIn(BYTE, aData), ULONG *aBytesWritten);
    102102    STDMETHOD(GetProcessStatus)(ULONG aPID, ULONG *aExitCode, ULONG *aFlags, ULONG *aStatus);
    103     STDMETHOD(CopyToGuest)(IN_BSTR aSource, IN_BSTR aDest, ULONG aFlags, IProgress **aProgress);
     103    STDMETHOD(CopyToGuest)(IN_BSTR aSource, IN_BSTR aDest, IN_BSTR aUserName, IN_BSTR aPassword, ULONG aFlags, IProgress **aProgress);
    104104    STDMETHOD(InternalGetStatistics)(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
    105105                                     ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared, ULONG *aMemCache,
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