Changeset 42668 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Aug 7, 2012 4:18:47 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 79866
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp
r42551 r42668 73 73 typedef struct COPYCONTEXT 74 74 { 75 IGuest *pGuest; 75 COPYCONTEXT() : fVerbose(false), fDryRun(false), fHostToGuest(false) 76 { 77 } 78 79 #ifndef VBOX_WITH_GUEST_CONTROL2 80 ComPtr<IGuest> pGuest; 81 #else 82 ComPtr<IGuestSession> pGuestSession; 83 #endif 76 84 bool fVerbose; 77 85 bool fDryRun; 78 86 bool fHostToGuest; 79 char *pszUsername; 80 char *pszPassword; 87 #ifndef VBOX_WITH_GUEST_CONTROL2 88 Utf8Str strUsername; 89 Utf8Str strPassword; 90 #endif 81 91 } COPYCONTEXT, *PCOPYCONTEXT; 82 92 … … 334 344 static int ctrlExecProcessStatusToExitCode(ExecuteProcessStatus_T enmStatus, ULONG uExitCode) 335 345 { 336 int rc = EXITCODEEXEC_SUCCESS;346 int vrc = EXITCODEEXEC_SUCCESS; 337 347 switch (enmStatus) 338 348 { 339 349 case ExecuteProcessStatus_Started: 340 rc = EXITCODEEXEC_SUCCESS;350 vrc = EXITCODEEXEC_SUCCESS; 341 351 break; 342 352 case ExecuteProcessStatus_TerminatedNormally: 343 rc = !uExitCode ? EXITCODEEXEC_SUCCESS : EXITCODEEXEC_CODE;353 vrc = !uExitCode ? EXITCODEEXEC_SUCCESS : EXITCODEEXEC_CODE; 344 354 break; 345 355 case ExecuteProcessStatus_TerminatedSignal: 346 rc = EXITCODEEXEC_TERM_SIGNAL;356 vrc = EXITCODEEXEC_TERM_SIGNAL; 347 357 break; 348 358 case ExecuteProcessStatus_TerminatedAbnormally: 349 rc = EXITCODEEXEC_TERM_ABEND;359 vrc = EXITCODEEXEC_TERM_ABEND; 350 360 break; 351 361 case ExecuteProcessStatus_TimedOutKilled: 352 rc = EXITCODEEXEC_TIMEOUT;362 vrc = EXITCODEEXEC_TIMEOUT; 353 363 break; 354 364 case ExecuteProcessStatus_TimedOutAbnormally: 355 rc = EXITCODEEXEC_TIMEOUT;365 vrc = EXITCODEEXEC_TIMEOUT; 356 366 break; 357 367 case ExecuteProcessStatus_Down: 358 368 /* Service/OS is stopping, process was killed, so 359 369 * not exactly an error of the started process ... */ 360 rc = EXITCODEEXEC_DOWN;370 vrc = EXITCODEEXEC_DOWN; 361 371 break; 362 372 case ExecuteProcessStatus_Error: 363 rc = EXITCODEEXEC_FAILED;373 vrc = EXITCODEEXEC_FAILED; 364 374 break; 365 375 default: … … 367 377 break; 368 378 } 369 return rc;379 return vrc; 370 380 } 371 381 #else … … 408 418 static int ctrlExecProcessStatusToExitCode(ProcessStatus_T enmStatus, ULONG uExitCode) 409 419 { 410 int rc = EXITCODEEXEC_SUCCESS;420 int vrc = EXITCODEEXEC_SUCCESS; 411 421 switch (enmStatus) 412 422 { 413 423 case ProcessStatus_Starting: 414 rc = EXITCODEEXEC_SUCCESS;424 vrc = EXITCODEEXEC_SUCCESS; 415 425 break; 416 426 case ProcessStatus_Started: 417 rc = EXITCODEEXEC_SUCCESS;427 vrc = EXITCODEEXEC_SUCCESS; 418 428 break; 419 429 case ProcessStatus_Paused: 420 rc = EXITCODEEXEC_SUCCESS;430 vrc = EXITCODEEXEC_SUCCESS; 421 431 break; 422 432 case ProcessStatus_Terminating: 423 rc = EXITCODEEXEC_SUCCESS;433 vrc = EXITCODEEXEC_SUCCESS; 424 434 break; 425 435 case ProcessStatus_TerminatedNormally: 426 rc = !uExitCode ? EXITCODEEXEC_SUCCESS : EXITCODEEXEC_CODE;436 vrc = !uExitCode ? EXITCODEEXEC_SUCCESS : EXITCODEEXEC_CODE; 427 437 break; 428 438 case ProcessStatus_TerminatedSignal: 429 rc = EXITCODEEXEC_TERM_SIGNAL;439 vrc = EXITCODEEXEC_TERM_SIGNAL; 430 440 break; 431 441 case ProcessStatus_TerminatedAbnormally: 432 rc = EXITCODEEXEC_TERM_ABEND;442 vrc = EXITCODEEXEC_TERM_ABEND; 433 443 break; 434 444 case ProcessStatus_TimedOutKilled: 435 rc = EXITCODEEXEC_TIMEOUT;445 vrc = EXITCODEEXEC_TIMEOUT; 436 446 break; 437 447 case ProcessStatus_TimedOutAbnormally: 438 rc = EXITCODEEXEC_TIMEOUT;448 vrc = EXITCODEEXEC_TIMEOUT; 439 449 break; 440 450 case ProcessStatus_Down: 441 451 /* Service/OS is stopping, process was killed, so 442 452 * not exactly an error of the started process ... */ 443 rc = EXITCODEEXEC_DOWN;453 vrc = EXITCODEEXEC_DOWN; 444 454 break; 445 455 case ProcessStatus_Error: 446 rc = EXITCODEEXEC_FAILED;456 vrc = EXITCODEEXEC_FAILED; 447 457 break; 448 458 default: … … 450 460 break; 451 461 } 452 return rc;462 return vrc; 453 463 } 454 464 #endif … … 718 728 * Parse arguments. 719 729 */ 720 if (pArg->argc < 2) /* At least the command we want to execute in the guest should be present :-). */721 return errorSyntax(USAGE_GUESTCONTROL, "Incorrect parameters");722 723 730 static const RTGETOPTDEF s_aOptions[] = 724 731 { … … 755 762 com::SafeArray<IN_BSTR> args; 756 763 com::SafeArray<IN_BSTR> env; 757 Utf8Str strUser Name;764 Utf8Str strUsername; 758 765 Utf8Str strPassword; 759 766 Utf8Str strDomain; … … 814 821 815 822 case 'u': /* User name */ 816 strUser Name = ValueUnion.psz;823 strUsername = ValueUnion.psz; 817 824 break; 818 825 … … 892 899 return errorSyntax(USAGE_GUESTCONTROL, "No command to execute specified!"); 893 900 894 if (strUser Name.isEmpty())901 if (strUsername.isEmpty()) 895 902 return errorSyntax(USAGE_GUESTCONTROL, "No user name specified!"); 896 903 … … 924 931 ComSafeArrayAsInParam(args), 925 932 ComSafeArrayAsInParam(env), 926 Bstr(strUser Name).raw(),933 Bstr(strUsername).raw(), 927 934 Bstr(strPassword).raw(), 928 935 cMsTimeout, … … 1067 1074 #else 1068 1075 ComPtr<IGuestSession> pGuestSession; 1069 rc = pGuest->CreateSession(Bstr(strUser Name).raw(),1076 rc = pGuest->CreateSession(Bstr(strUsername).raw(), 1070 1077 Bstr(strPassword).raw(), 1071 1078 Bstr(strDomain).raw(), … … 1210 1217 * @param fHostToGuest Flag indicating if we want to copy from host to guest 1211 1218 * or vice versa. 1212 * @param pszUsername Username of account to use on the guest side. 1213 * @param pszPassword Password of account to use. 1219 * @param strUsername Username of account to use on the guest side. 1220 * @param strPassword Password of account to use. 1221 * @param strDomain Domain of account to use. 1222 * @param strSessionName Session name (only for identification purposes). 1214 1223 * @param ppContext Pointer which receives the allocated copy context. 1215 1224 */ 1216 1225 static int ctrlCopyContextCreate(IGuest *pGuest, bool fVerbose, bool fDryRun, 1217 bool fHostToGuest, 1218 const char *pszUsername, const char *pszPassword, 1226 bool fHostToGuest, const Utf8Str &strUsername, 1227 const Utf8Str &strPassword, const Utf8Str &strDomain, 1228 const Utf8Str &strSessionName, 1219 1229 PCOPYCONTEXT *ppContext) 1220 1230 { 1221 1231 AssertPtrReturn(pGuest, VERR_INVALID_POINTER); 1222 AssertPtrReturn(pszUsername, VERR_INVALID_POINTER); 1223 AssertPtrReturn(pszPassword, VERR_INVALID_POINTER); 1224 1225 PCOPYCONTEXT pContext = (PCOPYCONTEXT)RTMemAlloc(sizeof(COPYCONTEXT)); 1226 AssertPtrReturn(pContext, VERR_NO_MEMORY); 1232 1233 PCOPYCONTEXT pContext = new COPYCONTEXT(); 1234 AssertPtrReturn(pContext, VERR_NO_MEMORY); /**< @todo r=klaus cannot happen with new */ 1235 #ifndef VBOX_WITH_GUEST_CONTROL2 1236 NOREF(strDomain); 1237 NOREF(strSessionName); 1227 1238 pContext->pGuest = pGuest; 1239 1240 pContext->strUsername = strUsername; 1241 pContext->strPassword = strPassword; 1242 #else 1243 ComPtr<IGuestSession> pGuestSession; 1244 HRESULT rc = pGuest->CreateSession(Bstr(strUsername).raw(), 1245 Bstr(strPassword).raw(), 1246 Bstr(strDomain).raw(), 1247 Bstr(strSessionName).raw(), 1248 pGuestSession.asOutParam()); 1249 if (FAILED(rc)) 1250 return ctrlPrintError(pGuest, COM_IIDOF(IGuest)); 1251 1252 #endif 1253 1228 1254 pContext->fVerbose = fVerbose; 1229 1255 pContext->fDryRun = fDryRun; 1230 1256 pContext->fHostToGuest = fHostToGuest; 1231 1257 1232 pContext->pszUsername = RTStrDup(pszUsername);1233 if (!pContext->pszUsername)1234 {1235 RTMemFree(pContext);1236 return VERR_NO_MEMORY;1237 }1238 1239 pContext->pszPassword = RTStrDup(pszPassword);1240 if (!pContext->pszPassword)1241 {1242 RTStrFree(pContext->pszUsername);1243 RTMemFree(pContext);1244 return VERR_NO_MEMORY;1245 }1246 1247 1258 *ppContext = pContext; 1248 1259 … … 1259 1270 if (pContext) 1260 1271 { 1261 RTStrFree(pContext->pszUsername); 1262 RTStrFree(pContext->pszPassword); 1263 RTMemFree(pContext); 1264 } 1265 } 1266 1267 /** 1268 * Translates a source path to a destintation path (can be both sides, 1272 #ifndef VBOX_WITH_GUEST_CONTROL2 1273 #else 1274 if (pContext->pGuestSession) 1275 pContext->pGuestSession->Close(); 1276 #endif 1277 delete pContext; 1278 } 1279 } 1280 1281 /** 1282 * Translates a source path to a destination path (can be both sides, 1269 1283 * either host or guest). The source root is needed to determine the start 1270 1284 * of the relative source path which also needs to present in the destination … … 1302 1316 AssertPtrReturn(pszDestPath, VERR_NO_MEMORY); 1303 1317 1304 int rc;1318 int vrc; 1305 1319 if (!RTPathFilename(pszDestPath)) 1306 1320 { 1307 rc = RTPathJoin(szTranslated, sizeof(szTranslated),1308 pszDestPath, &pszSource[srcOff]);1321 vrc = RTPathJoin(szTranslated, sizeof(szTranslated), 1322 pszDestPath, &pszSource[srcOff]); 1309 1323 } 1310 1324 else … … 1314 1328 { 1315 1329 RTPathStripFilename(pszDestPath); 1316 rc = RTPathJoin(szTranslated, sizeof(szTranslated),1330 vrc = RTPathJoin(szTranslated, sizeof(szTranslated), 1317 1331 pszDestPath, pszDestFileName); 1318 1332 RTStrFree(pszDestFileName); 1319 1333 } 1320 1334 else 1321 rc = VERR_NO_MEMORY;1335 vrc = VERR_NO_MEMORY; 1322 1336 } 1323 1337 RTStrFree(pszDestPath); 1324 1338 1325 if (RT_SUCCESS( rc))1339 if (RT_SUCCESS(vrc)) 1326 1340 { 1327 1341 *ppszTranslated = RTStrDup(szTranslated); … … 1331 1345 #endif 1332 1346 } 1333 return rc;1347 return vrc; 1334 1348 } 1335 1349 … … 1432 1446 if (pContext->fHostToGuest) /* We want to create directories on the guest. */ 1433 1447 { 1448 #ifndef VBOX_WITH_GUEST_CONTROL2 1434 1449 HRESULT rc = pContext->pGuest->DirectoryCreate(Bstr(pszDir).raw(), 1435 Bstr(pContext-> pszUsername).raw(), Bstr(pContext->pszPassword).raw(),1450 Bstr(pContext->strUsername).raw(), Bstr(pContext->strPassword).raw(), 1436 1451 0700, DirectoryCreateFlag_Parents); 1437 1452 if (FAILED(rc)) 1438 1453 vrc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest)); 1454 #else 1455 ComPtr<IGuestDirectory> pDirectory; 1456 SafeArray<DirectoryCreateFlag_T> dirCreateFlags; 1457 dirCreateFlags.push_back(DirectoryCreateFlag_Parents); 1458 HRESULT rc = pContext->pGuestSession->DirectoryCreate(Bstr(pszDir).raw(), 1459 0700, ComSafeArrayAsInParam(dirCreateFlags), pDirectory.asOutParam()); 1460 if (FAILED(rc)) 1461 vrc = ctrlPrintError(pContext->pGuestSession, COM_IIDOF(IGuestSession)); 1462 if (!pDirectory.isNull()) 1463 pDirectory->Close(); 1464 #endif 1439 1465 } 1440 1466 else /* ... or on the host. */ … … 1465 1491 AssertPtrReturn(fExists, false); 1466 1492 1467 int rc = VINF_SUCCESS;1493 int vrc = VINF_SUCCESS; 1468 1494 if (bGuest) 1469 1495 { 1470 1496 BOOL fDirExists = FALSE; 1497 #ifndef VBOX_WITH_GUEST_CONTROL2 1471 1498 /** @todo Replace with DirectoryExists as soon as API is in place. */ 1472 HRESULT hr= pContext->pGuest->FileExists(Bstr(pszDir).raw(),1473 Bstr(pContext-> pszUsername).raw(),1474 Bstr(pContext-> pszPassword).raw(), &fDirExists);1475 if (FAILED( hr))1476 rc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));1499 HRESULT rc = pContext->pGuest->FileExists(Bstr(pszDir).raw(), 1500 Bstr(pContext->strUsername).raw(), 1501 Bstr(pContext->strPassword).raw(), &fDirExists); 1502 if (FAILED(rc)) 1503 vrc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest)); 1477 1504 else 1478 1505 *fExists = fDirExists ? true : false; 1506 #else 1507 HRESULT rc = pContext->pGuestSession->DirectoryExists(Bstr(pszDir).raw(), &fDirExists); 1508 if (FAILED(rc)) 1509 vrc = ctrlPrintError(pContext->pGuestSession, COM_IIDOF(IGuestSession)); 1510 else 1511 *fExists = fDirExists ? true : false; 1512 #endif 1479 1513 } 1480 1514 else 1481 1515 *fExists = RTDirExists(pszDir); 1482 return rc;1516 return vrc; 1483 1517 } 1484 1518 … … 1535 1569 AssertPtrReturn(fExists, false); 1536 1570 1537 int rc = VINF_SUCCESS;1571 int vrc = VINF_SUCCESS; 1538 1572 if (bOnGuest) 1539 1573 { 1540 1574 BOOL fFileExists = FALSE; 1541 HRESULT hr = pContext->pGuest->FileExists(Bstr(pszFile).raw(), 1542 Bstr(pContext->pszUsername).raw(), 1543 Bstr(pContext->pszPassword).raw(), &fFileExists); 1544 if (FAILED(hr)) 1545 rc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest)); 1575 #ifndef VBOX_WITH_GUEST_CONTROL2 1576 HRESULT rc = pContext->pGuest->FileExists(Bstr(pszFile).raw(), 1577 Bstr(pContext->strUsername).raw(), 1578 Bstr(pContext->strPassword).raw(), &fFileExists); 1579 if (FAILED(rc)) 1580 vrc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest)); 1546 1581 else 1547 1582 *fExists = fFileExists ? true : false; 1583 #else 1584 HRESULT rc = pContext->pGuestSession->FileExists(Bstr(pszFile).raw(), &fFileExists); 1585 if (FAILED(rc)) 1586 vrc = ctrlPrintError(pContext->pGuestSession, COM_IIDOF(IGuestSession)); 1587 else 1588 *fExists = fFileExists ? true : false; 1589 #endif 1548 1590 } 1549 1591 else 1550 1592 *fExists = RTFileExists(pszFile); 1551 return rc;1593 return vrc; 1552 1594 } 1553 1595 … … 1616 1658 if (pContext->fHostToGuest) 1617 1659 { 1660 #ifndef VBOX_WITH_GUEST_CONTROL2 1618 1661 rc = pContext->pGuest->CopyToGuest(Bstr(pszFileSource).raw(), Bstr(pszFileDest).raw(), 1619 Bstr(pContext-> pszUsername).raw(), Bstr(pContext->pszPassword).raw(),1662 Bstr(pContext->strUsername).raw(), Bstr(pContext->strPassword).raw(), 1620 1663 fFlags, pProgress.asOutParam()); 1664 #else 1665 Assert(!fFlags); 1666 SafeArray<CopyFileFlag_T> copyFlags; 1667 rc = pContext->pGuestSession->CopyTo(Bstr(pszFileSource).raw(), Bstr(pszFileDest).raw(), 1668 ComSafeArrayAsInParam(copyFlags), 1669 1670 pProgress.asOutParam()); 1671 #endif 1621 1672 } 1622 1673 else 1623 1674 { 1675 #ifndef VBOX_WITH_GUEST_CONTROL2 1624 1676 rc = pContext->pGuest->CopyFromGuest(Bstr(pszFileSource).raw(), Bstr(pszFileDest).raw(), 1625 Bstr(pContext-> pszUsername).raw(), Bstr(pContext->pszPassword).raw(),1677 Bstr(pContext->strUsername).raw(), Bstr(pContext->strPassword).raw(), 1626 1678 fFlags, pProgress.asOutParam()); 1679 #else 1680 Assert(!fFlags); 1681 SafeArray<CopyFileFlag_T> copyFlags; 1682 rc = pContext->pGuestSession->CopyFrom(Bstr(pszFileSource).raw(), Bstr(pszFileDest).raw(), 1683 ComSafeArrayAsInParam(copyFlags), 1684 pProgress.asOutParam()); 1685 #endif 1627 1686 } 1628 1687 1629 1688 if (FAILED(rc)) 1689 { 1690 #ifndef VBOX_WITH_GUEST_CONTROL2 1630 1691 vrc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest)); 1692 #else 1693 vrc = ctrlPrintError(pContext->pGuestSession, COM_IIDOF(IGuestSession)); 1694 #endif 1695 } 1631 1696 else 1632 1697 { … … 1670 1735 */ 1671 1736 char szCurDir[RTPATH_MAX]; 1672 int rc = RTStrCopy(szCurDir, sizeof(szCurDir), pszSource);1673 if (RT_SUCCESS( rc) && pszSubDir)1674 rc = RTPathAppend(szCurDir, sizeof(szCurDir), pszSubDir);1737 int vrc = RTStrCopy(szCurDir, sizeof(szCurDir), pszSource); 1738 if (RT_SUCCESS(vrc) && pszSubDir) 1739 vrc = RTPathAppend(szCurDir, sizeof(szCurDir), pszSubDir); 1675 1740 1676 1741 if (pContext->fVerbose) … … 1686 1751 */ 1687 1752 PRTDIR pDir = NULL; 1688 if (RT_SUCCESS( rc))1689 { 1690 rc = RTDirOpen(&pDir, szCurDir);1691 if (RT_FAILURE( rc))1753 if (RT_SUCCESS(vrc)) 1754 { 1755 vrc = RTDirOpen(&pDir, szCurDir); 1756 if (RT_FAILURE(vrc)) 1692 1757 pDir = NULL; 1693 1758 } 1694 if (RT_SUCCESS( rc))1759 if (RT_SUCCESS(vrc)) 1695 1760 { 1696 1761 /* 1697 1762 * Enumerate the directory tree. 1698 1763 */ 1699 while (RT_SUCCESS( rc))1764 while (RT_SUCCESS(vrc)) 1700 1765 { 1701 1766 RTDIRENTRY DirEntry; 1702 rc = RTDirRead(pDir, &DirEntry, NULL);1703 if (RT_FAILURE( rc))1704 { 1705 if ( rc == VERR_NO_MORE_FILES)1706 rc = VINF_SUCCESS;1767 vrc = RTDirRead(pDir, &DirEntry, NULL); 1768 if (RT_FAILURE(vrc)) 1769 { 1770 if (vrc == VERR_NO_MORE_FILES) 1771 vrc = VINF_SUCCESS; 1707 1772 break; 1708 1773 } … … 1732 1797 if (pszNewSub) 1733 1798 { 1734 rc = ctrlCopyDirToGuest(pContext,1735 pszSource, pszFilter,1736 pszDest, fFlags, pszNewSub);1799 vrc = ctrlCopyDirToGuest(pContext, 1800 pszSource, pszFilter, 1801 pszDest, fFlags, pszNewSub); 1737 1802 RTStrFree(pszNewSub); 1738 1803 } 1739 1804 else 1740 rc = VERR_NO_MEMORY;1805 vrc = VERR_NO_MEMORY; 1741 1806 } 1742 1807 break; … … 1766 1831 { 1767 1832 char *pszDestDir; 1768 rc = ctrlCopyTranslatePath(pszSource, szCurDir,1769 pszDest, &pszDestDir);1770 if (RT_SUCCESS( rc))1833 vrc = ctrlCopyTranslatePath(pszSource, szCurDir, 1834 pszDest, &pszDestDir); 1835 if (RT_SUCCESS(vrc)) 1771 1836 { 1772 rc = ctrlCopyDirCreate(pContext, pszDestDir);1837 vrc = ctrlCopyDirCreate(pContext, pszDestDir); 1773 1838 RTStrFree(pszDestDir); 1774 1839 … … 1777 1842 } 1778 1843 1779 if (RT_SUCCESS( rc))1844 if (RT_SUCCESS(vrc)) 1780 1845 { 1781 1846 char *pszFileSource = RTPathJoinA(szCurDir, DirEntry.szName); … … 1783 1848 { 1784 1849 char *pszFileDest; 1785 rc = ctrlCopyTranslatePath(pszSource, pszFileSource,1850 vrc = ctrlCopyTranslatePath(pszSource, pszFileSource, 1786 1851 pszDest, &pszFileDest); 1787 if (RT_SUCCESS( rc))1852 if (RT_SUCCESS(vrc)) 1788 1853 { 1789 rc = ctrlCopyFileToDest(pContext, pszFileSource,1854 vrc = ctrlCopyFileToDest(pContext, pszFileSource, 1790 1855 pszFileDest, 0 /* Flags */); 1791 1856 RTStrFree(pszFileDest); … … 1800 1865 break; 1801 1866 } 1802 if (RT_FAILURE( rc))1867 if (RT_FAILURE(vrc)) 1803 1868 break; 1804 1869 } … … 1806 1871 RTDirClose(pDir); 1807 1872 } 1808 return rc;1873 return vrc; 1809 1874 } 1810 1875 … … 1836 1901 */ 1837 1902 char szCurDir[RTPATH_MAX]; 1838 int rc = RTStrCopy(szCurDir, sizeof(szCurDir), pszSource);1839 if (RT_SUCCESS( rc) && pszSubDir)1840 rc = RTPathAppend(szCurDir, sizeof(szCurDir), pszSubDir);1841 1842 if (RT_FAILURE( rc))1843 return rc;1903 int vrc = RTStrCopy(szCurDir, sizeof(szCurDir), pszSource); 1904 if (RT_SUCCESS(vrc) && pszSubDir) 1905 vrc = RTPathAppend(szCurDir, sizeof(szCurDir), pszSubDir); 1906 1907 if (RT_FAILURE(vrc)) 1908 return vrc; 1844 1909 1845 1910 if (pContext->fVerbose) … … 1850 1915 bool fDirCreated = false; 1851 1916 1917 #ifndef VBOX_WITH_GUEST_CONTROL2 1852 1918 ULONG uDirHandle; 1853 HRESULT hr= pContext->pGuest->DirectoryOpen(Bstr(szCurDir).raw(), Bstr(pszFilter).raw(),1919 HRESULT rc = pContext->pGuest->DirectoryOpen(Bstr(szCurDir).raw(), Bstr(pszFilter).raw(), 1854 1920 DirectoryOpenFlag_None /* No flags supported yet. */, 1855 Bstr(pContext-> pszUsername).raw(), Bstr(pContext->pszPassword).raw(),1921 Bstr(pContext->strUsername).raw(), Bstr(pContext->strPassword).raw(), 1856 1922 &uDirHandle); 1857 if (FAILED(hr)) 1858 rc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest)); 1859 else 1860 { 1861 ComPtr <IGuestDirEntry> dirEntry; 1862 while (SUCCEEDED(hr = pContext->pGuest->DirectoryRead(uDirHandle, dirEntry.asOutParam()))) 1863 { 1864 GuestDirEntryType_T enmType; 1865 dirEntry->COMGETTER(Type)(&enmType); 1866 1867 Bstr strName; 1868 dirEntry->COMGETTER(Name)(strName.asOutParam()); 1869 1870 switch (enmType) 1871 { 1872 case GuestDirEntryType_Directory: 1923 if (FAILED(rc)) 1924 return ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest)); 1925 ComPtr<IGuestDirEntry> dirEntry; 1926 #else 1927 ComPtr<IGuestDirectory> pDirectory; 1928 HRESULT rc = pContext->pGuestSession->DirectoryOpen(Bstr(szCurDir).raw(), Bstr(pszFilter).raw(), 1929 Bstr().raw() /* No flags supported yet. */, 1930 pDirectory.asOutParam()); 1931 if (FAILED(rc)) 1932 return ctrlPrintError(pContext->pGuestSession, COM_IIDOF(IGuestSession)); 1933 ComPtr<IFsObjInfo> dirEntry; 1934 #endif 1935 while (true) 1936 { 1937 #ifndef VBOX_WITH_GUEST_CONTROL2 1938 rc = pContext->pGuest->DirectoryRead(uDirHandle, dirEntry.asOutParam()); 1939 #else 1940 rc = pDirectory->Read(dirEntry.asOutParam()); 1941 #endif 1942 if (FAILED(rc)) 1943 break; 1944 1945 #ifndef VBOX_WITH_GUEST_CONTROL2 1946 GuestDirEntryType_T enmType; 1947 #else 1948 FsObjType_T enmType; 1949 #endif 1950 dirEntry->COMGETTER(Type)(&enmType); 1951 1952 Bstr strName; 1953 dirEntry->COMGETTER(Name)(strName.asOutParam()); 1954 1955 switch (enmType) 1956 { 1957 #ifndef VBOX_WITH_GUEST_CONTROL2 1958 case GuestDirEntryType_Directory: 1959 #else 1960 case FsObjType_Directory: 1961 #endif 1962 { 1963 Assert(!strName.isEmpty()); 1964 1965 /* Skip "." and ".." entries. */ 1966 if ( !strName.compare(Bstr(".")) 1967 || !strName.compare(Bstr(".."))) 1968 break; 1969 1970 if (pContext->fVerbose) 1873 1971 { 1874 Assert(!strName.isEmpty()); 1875 1876 /* Skip "." and ".." entries. */ 1877 if ( !strName.compare(Bstr(".")) 1878 || !strName.compare(Bstr(".."))) 1879 break; 1880 1881 if (pContext->fVerbose) 1972 Utf8Str strDir(strName); 1973 RTPrintf("Directory: %s\n", strDir.c_str()); 1974 } 1975 1976 if (fFlags & CopyFileFlag_Recursive) 1977 { 1978 Utf8Str strDir(strName); 1979 char *pszNewSub = NULL; 1980 if (pszSubDir) 1981 pszNewSub = RTPathJoinA(pszSubDir, strDir.c_str()); 1982 else 1882 1983 { 1883 Utf8Str strDir(strName);1884 RTP rintf("Directory: %s\n", strDir.c_str());1984 pszNewSub = RTStrDup(strDir.c_str()); 1985 RTPathStripTrailingSlash(pszNewSub); 1885 1986 } 1886 1887 if (fFlags & CopyFileFlag_Recursive) 1987 if (pszNewSub) 1888 1988 { 1889 Utf8Str strDir(strName); 1890 char *pszNewSub = NULL; 1891 if (pszSubDir) 1892 pszNewSub = RTPathJoinA(pszSubDir, strDir.c_str()); 1893 else 1894 { 1895 pszNewSub = RTStrDup(strDir.c_str()); 1896 RTPathStripTrailingSlash(pszNewSub); 1897 } 1898 if (pszNewSub) 1899 { 1900 rc = ctrlCopyDirToHost(pContext, 1901 pszSource, pszFilter, 1902 pszDest, fFlags, pszNewSub); 1903 RTStrFree(pszNewSub); 1904 } 1905 else 1906 rc = VERR_NO_MEMORY; 1907 } 1908 break; 1909 } 1910 1911 case GuestDirEntryType_Symlink: 1912 if ( (fFlags & CopyFileFlag_Recursive) 1913 && (fFlags & CopyFileFlag_FollowLinks)) 1914 { 1915 /* Fall through to next case is intentional. */ 1989 vrc = ctrlCopyDirToHost(pContext, 1990 pszSource, pszFilter, 1991 pszDest, fFlags, pszNewSub); 1992 RTStrFree(pszNewSub); 1916 1993 } 1917 1994 else 1918 break; 1919 1920 case GuestDirEntryType_File: 1995 vrc = VERR_NO_MEMORY; 1996 } 1997 break; 1998 } 1999 2000 #ifndef VBOX_WITH_GUEST_CONTROL2 2001 case GuestDirEntryType_Symlink: 2002 #else 2003 case FsObjType_Symlink: 2004 #endif 2005 if ( (fFlags & CopyFileFlag_Recursive) 2006 && (fFlags & CopyFileFlag_FollowLinks)) 1921 2007 { 1922 Assert(!strName.isEmpty()); 1923 1924 Utf8Str strFile(strName); 1925 if ( pszFilter 1926 && !RTStrSimplePatternMatch(pszFilter, strFile.c_str())) 2008 /* Fall through to next case is intentional. */ 2009 } 2010 else 2011 break; 2012 2013 #ifndef VBOX_WITH_GUEST_CONTROL2 2014 case GuestDirEntryType_File: 2015 #else 2016 case FsObjType_File: 2017 #endif 2018 { 2019 Assert(!strName.isEmpty()); 2020 2021 Utf8Str strFile(strName); 2022 if ( pszFilter 2023 && !RTStrSimplePatternMatch(pszFilter, strFile.c_str())) 2024 { 2025 break; /* Filter does not match. */ 2026 } 2027 2028 if (pContext->fVerbose) 2029 RTPrintf("File: %s\n", strFile.c_str()); 2030 2031 if (!fDirCreated) 2032 { 2033 char *pszDestDir; 2034 vrc = ctrlCopyTranslatePath(pszSource, szCurDir, 2035 pszDest, &pszDestDir); 2036 if (RT_SUCCESS(vrc)) 1927 2037 { 1928 break; /* Filter does not match. */ 2038 vrc = ctrlCopyDirCreate(pContext, pszDestDir); 2039 RTStrFree(pszDestDir); 2040 2041 fDirCreated = true; 1929 2042 } 1930 1931 if (pContext->fVerbose) 1932 RTPrintf("File: %s\n", strFile.c_str()); 1933 1934 if (!fDirCreated) 2043 } 2044 2045 if (RT_SUCCESS(vrc)) 2046 { 2047 char *pszFileSource = RTPathJoinA(szCurDir, strFile.c_str()); 2048 if (pszFileSource) 1935 2049 { 1936 char *psz DestDir;1937 rc = ctrlCopyTranslatePath(pszSource, szCurDir,1938 pszDest, &psz DestDir);1939 if (RT_SUCCESS( rc))2050 char *pszFileDest; 2051 vrc = ctrlCopyTranslatePath(pszSource, pszFileSource, 2052 pszDest, &pszFileDest); 2053 if (RT_SUCCESS(vrc)) 1940 2054 { 1941 rc = ctrlCopyDirCreate(pContext, pszDestDir); 1942 RTStrFree(pszDestDir); 1943 1944 fDirCreated = true; 2055 vrc = ctrlCopyFileToDest(pContext, pszFileSource, 2056 pszFileDest, 0 /* Flags */); 2057 RTStrFree(pszFileDest); 1945 2058 } 2059 RTStrFree(pszFileSource); 1946 2060 } 1947 1948 if (RT_SUCCESS(rc)) 1949 { 1950 char *pszFileSource = RTPathJoinA(szCurDir, strFile.c_str()); 1951 if (pszFileSource) 1952 { 1953 char *pszFileDest; 1954 rc = ctrlCopyTranslatePath(pszSource, pszFileSource, 1955 pszDest, &pszFileDest); 1956 if (RT_SUCCESS(rc)) 1957 { 1958 rc = ctrlCopyFileToDest(pContext, pszFileSource, 1959 pszFileDest, 0 /* Flags */); 1960 RTStrFree(pszFileDest); 1961 } 1962 RTStrFree(pszFileSource); 1963 } 1964 else 1965 rc = VERR_NO_MEMORY; 1966 } 1967 break; 2061 else 2062 vrc = VERR_NO_MEMORY; 1968 2063 } 1969 1970 default: 1971 RTPrintf("Warning: Directory entry of type %ld not handled, skipping ...\n", 1972 enmType); 1973 break; 1974 } 1975 1976 if (RT_FAILURE(rc)) 1977 break; 1978 } 1979 1980 if (RT_UNLIKELY(FAILED(hr))) 1981 { 1982 switch (hr) 1983 { 1984 case E_ABORT: /* No more directory entries left to process. */ 1985 break; 1986 1987 case VBOX_E_FILE_ERROR: /* Current entry cannot be accessed to 1988 to missing rights. */ 1989 { 1990 RTPrintf("Warning: Cannot access \"%s\", skipping ...\n", 1991 szCurDir); 1992 break; 1993 } 1994 1995 default: 1996 rc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest)); 1997 break; 1998 } 1999 } 2000 2001 HRESULT hr2 = pContext->pGuest->DirectoryClose(uDirHandle); 2002 if (FAILED(hr2)) 2003 { 2004 int rc2 = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest)); 2005 if (RT_SUCCESS(rc)) 2006 rc = rc2; 2007 } 2008 else if (SUCCEEDED(hr)) 2009 hr = hr2; 2010 } 2011 2012 return rc; 2064 break; 2065 } 2066 2067 default: 2068 RTPrintf("Warning: Directory entry of type %ld not handled, skipping ...\n", 2069 enmType); 2070 break; 2071 } 2072 2073 if (RT_FAILURE(vrc)) 2074 break; 2075 } 2076 2077 if (RT_UNLIKELY(FAILED(rc))) 2078 { 2079 switch (rc) 2080 { 2081 case E_ABORT: /* No more directory entries left to process. */ 2082 break; 2083 2084 case VBOX_E_FILE_ERROR: /* Current entry cannot be accessed to 2085 to missing rights. */ 2086 { 2087 RTPrintf("Warning: Cannot access \"%s\", skipping ...\n", 2088 szCurDir); 2089 break; 2090 } 2091 2092 default: 2093 #ifndef VBOX_WITH_GUEST_CONTROL2 2094 vrc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest)); 2095 #else 2096 vrc = ctrlPrintError(pDirectory, COM_IIDOF(IGuestDirectory)); 2097 #endif 2098 break; 2099 } 2100 } 2101 2102 #ifndef VBOX_WITH_GUEST_CONTROL2 2103 HRESULT rc2 = pContext->pGuest->DirectoryClose(uDirHandle); 2104 #else 2105 HRESULT rc2 = pDirectory->Close(); 2106 #endif 2107 if (FAILED(rc2)) 2108 { 2109 #ifndef VBOX_WITH_GUEST_CONTROL2 2110 int vrc2 = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest)); 2111 #else 2112 int vrc2 = ctrlPrintError(pDirectory, COM_IIDOF(IGuestDirectory)); 2113 #endif 2114 if (RT_SUCCESS(vrc)) 2115 vrc = vrc2; 2116 } 2117 else if (SUCCEEDED(rc)) 2118 rc = rc2; 2119 2120 return vrc; 2013 2121 } 2014 2122 … … 2127 2235 Utf8Str strSource; 2128 2236 Utf8Str strDest; 2129 Utf8Str strUser Name;2237 Utf8Str strUsername; 2130 2238 Utf8Str strPassword; 2131 2239 Utf8Str strDomain; … … 2152 2260 2153 2261 case 'u': /* User name */ 2154 strUser Name = ValueUnion.psz;2262 strUsername = ValueUnion.psz; 2155 2263 break; 2156 2264 … … 2214 2322 "No destination specified!"); 2215 2323 2216 if (strUser Name.isEmpty())2324 if (strUsername.isEmpty()) 2217 2325 return errorSyntax(USAGE_GUESTCONTROL, 2218 2326 "No user name specified!"); … … 2235 2343 PCOPYCONTEXT pContext; 2236 2344 vrc = ctrlCopyContextCreate(guest, fVerbose, fDryRun, fHostToGuest, 2237 strUser Name.c_str(), strPassword.c_str(),2238 &pContext);2345 strUsername.c_str(), strPassword.c_str(), 2346 strDomain.c_str(), "guest copy", &pContext); 2239 2347 if (RT_FAILURE(vrc)) 2240 2348 { … … 2397 2505 s_aOptions, RT_ELEMENTS(s_aOptions), 0, RTGETOPTINIT_FLAGS_OPTS_FIRST); 2398 2506 2399 Utf8Str strUser Name;2507 Utf8Str strUsername; 2400 2508 Utf8Str strPassword; 2401 2509 Utf8Str strDomain; … … 2420 2528 2421 2529 case 'u': /* User name */ 2422 strUser Name = ValueUnion.psz;2530 strUsername = ValueUnion.psz; 2423 2531 break; 2424 2532 … … 2458 2566 return errorSyntax(USAGE_GUESTCONTROL, "No directory to create specified!"); 2459 2567 2460 if (strUser Name.isEmpty())2568 if (strUsername.isEmpty()) 2461 2569 return errorSyntax(USAGE_GUESTCONTROL, "No user name specified!"); 2462 2570 … … 2475 2583 2476 2584 hrc = guest->DirectoryCreate(Bstr(it->first).raw(), 2477 Bstr(strUser Name).raw(), Bstr(strPassword).raw(),2585 Bstr(strUsername).raw(), Bstr(strPassword).raw(), 2478 2586 fDirMode, fFlags); 2479 2587 if (FAILED(hrc)) … … 2512 2620 s_aOptions, RT_ELEMENTS(s_aOptions), 0, RTGETOPTINIT_FLAGS_OPTS_FIRST); 2513 2621 2514 Utf8Str strUser Name;2622 Utf8Str strUsername; 2515 2623 Utf8Str strPassword; 2516 2624 Utf8Str strDomain; … … 2525 2633 { 2526 2634 case 'u': /* User name */ 2527 strUser Name = ValueUnion.psz;2635 strUsername = ValueUnion.psz; 2528 2636 break; 2529 2637 … … 2571 2679 return errorSyntax(USAGE_GUESTCONTROL, "No element(s) to check specified!"); 2572 2680 2573 if (strUser Name.isEmpty())2681 if (strUsername.isEmpty()) 2574 2682 return errorSyntax(USAGE_GUESTCONTROL, "No user name specified!"); 2575 2683 … … 2587 2695 BOOL fExists; 2588 2696 hrc = guest->FileExists(Bstr(it->first).raw(), 2589 Bstr(strUser Name).raw(), Bstr(strPassword).raw(),2697 Bstr(strUsername).raw(), Bstr(strPassword).raw(), 2590 2698 &fExists); 2591 2699 if (FAILED(hrc))
Note:
See TracChangeset
for help on using the changeset viewer.