Changeset 33301 in vbox
- Timestamp:
- Oct 21, 2010 11:41:49 AM (14 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp
r33294 r33301 80 80 " copyto <vmname>|<uuid>\n" 81 81 " <source on host> <destination on guest>\n" 82 " --username <name> --password <password>\n" 82 83 " [--recursive] [--verbose] [--flags <flags>]\n" 83 84 #endif … … 368 369 RTPrintf("Waiting for process to exit ...\n"); 369 370 370 /* setup signal handling if cancelable*/371 /* Setup signal handling if cancelable. */ 371 372 ASSERT(progress); 372 373 bool fCanceledAlready = false; … … 441 442 } 442 443 443 #if 0444 #if 1 444 445 static int sent = 0; 445 446 if (sent < 1) … … 627 628 Utf8Str Utf8Source(a->argv[1]); 628 629 Utf8Str Utf8Dest(a->argv[2]); 629 uint32_t uFlags = 0; 630 Utf8Str Utf8UserName; 631 Utf8Str Utf8Password; 632 uint32_t uFlags = CopyFileFlag_None; 630 633 bool fVerbose = false; 631 634 bool fCopyRecursive = false; … … 635 638 for (int i = 3; usageOK && i < a->argc; i++) 636 639 { 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")) 638 663 { 639 664 if (i + 1 >= a->argc) … … 678 703 return errorSyntax(USAGE_GUESTCONTROL, 679 704 "No destination specified!"); 705 706 if (Utf8UserName.isEmpty()) 707 return errorSyntax(USAGE_GUESTCONTROL, 708 "No user name specified!"); 680 709 681 710 /* lookup VM. */ … … 716 745 /* Do the copy. */ 717 746 rc = guest->CopyToGuest(Bstr(Utf8Source).raw(), Bstr(Utf8Dest).raw(), 747 Bstr(Utf8UserName).raw(), Bstr(Utf8Password).raw(), 718 748 uFlags, progress.asOutParam()); 719 749 if (FAILED(rc)) … … 733 763 else 734 764 { 735 /* setup signal handling if cancelable*/765 /* Setup signal handling if cancelable. */ 736 766 ASSERT(progress); 737 767 bool fCanceledAlready = false; … … 751 781 BOOL fCompleted = FALSE; 752 782 BOOL fCanceled = FALSE; 753 while (SUCCEEDED(progress->COMGETTER(Completed(&fCompleted)))) 783 while ( SUCCEEDED(progress->COMGETTER(Completed(&fCompleted))) 784 && !fCompleted) 754 785 { 755 786 /* Process async cancelation */ -
trunk/src/VBox/Main/GuestImpl.cpp
r33253 r33301 34 34 #include <iprt/cpp/utils.h> 35 35 #include <iprt/dir.h> 36 #include <iprt/file.h> 36 37 #include <iprt/getopt.h> 37 38 #include <iprt/list.h> … … 1521 1522 && fCompleted) 1522 1523 { 1523 PCALLBACKDATAEXECINSTATUS p Data = (PCALLBACKDATAEXECINSTATUS)it->second.pvData;1524 PCALLBACKDATAEXECINSTATUS pStatusData = (PCALLBACKDATAEXECINSTATUS)it->second.pvData; 1524 1525 Assert(it->second.cbData == sizeof(CALLBACKDATAEXECINSTATUS)); 1525 AssertPtr(p Data);1526 1527 *aBytesWritten = p Data->cbProcessed;1526 AssertPtr(pStatusData); 1527 1528 *aBytesWritten = pStatusData->cbProcessed; 1528 1529 } 1529 1530 } … … 1930 1931 #endif 1931 1932 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). */ 1937 STDMETHODIMP Guest::CopyToGuest(IN_BSTR aSource, IN_BSTR aDest, 1938 IN_BSTR aUserName, IN_BSTR aPassword, 1939 ULONG aFlags, IProgress **aProgress) 1934 1940 { 1935 1941 #ifndef VBOX_WITH_GUEST_CONTROL … … 1949 1955 1950 1956 /* Validate flags. */ 1951 if (aFlags )1957 if (aFlags != CopyFileFlag_None) 1952 1958 { 1953 1959 if ( !(aFlags & CopyFileFlag_Recursive) … … 1963 1969 try 1964 1970 { 1965 ULONG cObjectsToCopy = 0;1966 RTLISTNODE listEntries; 1971 /*ULONG cObjectsToCopy = 0; 1972 RTLISTNODE listEntries;*/ 1967 1973 1968 1974 Utf8Str Utf8Source(aSource); 1969 1975 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()); 1976 1984 } 1977 1985 else 1978 1986 { 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 */ 1979 2082 if (RTDirExists(pszSourceAbs)) 1980 2083 { 2084 /* If no trailing slash is present, append. */ 1981 2085 size_t cch = strlen(pszSourceAbs); 1982 2086 if ( cch > 1 … … 1989 2093 tr("Failed to extend source path, rc=%Rrc\n"), vrc); 1990 2094 } 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 1991 2135 } 1992 2136 … … 2033 2177 } 2034 2178 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 2035 2194 #if 0 2036 2195 if (SUCCEEDED(rc)) … … 2079 2238 } 2080 2239 #endif 2081 /* Destroy list. */ 2240 #if 0 2241 /* Destroy file list. */ 2082 2242 VBoxGuestDirEntry *pNode = RTListNodeGetFirst(&listEntries, VBoxGuestDirEntry, Node); 2083 2243 while (pNode) … … 2097 2257 } 2098 2258 } 2259 #endif 2099 2260 } 2100 2261 } -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r33300 r33301 7605 7605 <interface 7606 7606 name="IGuest" extends="$unknown" 7607 uuid=" 9a2d971f-62cb-4e84-b91a-c5adc2b7c6b8"7607 uuid="ed69cdce-2905-4275-872b-3c743a85c584" 7608 7608 wsmap="managed" 7609 7609 > … … 7911 7911 <desc> 7912 7912 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. 7913 7925 </desc> 7914 7926 </param> -
trunk/src/VBox/Main/include/GuestImpl.h
r33247 r33301 101 101 STDMETHOD(SetProcessInput)(ULONG aPID, ULONG aFlags, ComSafeArrayIn(BYTE, aData), ULONG *aBytesWritten); 102 102 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); 104 104 STDMETHOD(InternalGetStatistics)(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle, 105 105 ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared, ULONG *aMemCache,
Note:
See TracChangeset
for help on using the changeset viewer.