Changeset 72023 in vbox for trunk/src/VBox/Main
- Timestamp:
- Apr 25, 2018 4:03:00 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp
r72001 r72023 1344 1344 } 1345 1345 1346 #if 01347 /**1348 * Copys a directory (tree) from guest to the host.1349 *1350 * @return IPRT status code.1351 * @param strSource Source directory on the guest to copy to the host.1352 * @param strFilter DOS-style wildcard filter (?, *). Optional.1353 * @param strDest Destination directory on the host.1354 * @param fRecursive Whether to recursively copy the directory contents or not.1355 * @param fFollowSymlinks Whether to follow symlinks or not.1356 * @param strSubDir Current sub directory to handle. Needs to NULL and only1357 * is needed for recursion.1358 */1359 int SessionTaskCopyDirFrom::directoryCopyToHost(const Utf8Str &strSource, const Utf8Str &strFilter,1360 const Utf8Str &strDest, bool fRecursive, bool fFollowSymlinks,1361 const Utf8Str &strSubDir /* For recursion. */)1362 {1363 Utf8Str strSrcDir = strSource;1364 Utf8Str strDstDir = strDest;1365 Utf8Str strSrcSubDir = strSubDir;1366 1367 /* Validation and sanity. */1368 if ( !strSrcDir.endsWith("/")1369 && !strSrcDir.endsWith("\\"))1370 strSrcDir += "/";1371 1372 if ( !strDstDir.endsWith("/")1373 && !strDstDir.endsWith("\\"))1374 strDstDir+= "/";1375 1376 if ( strSrcSubDir.isNotEmpty() /* Optional, for recursion. */1377 && !strSrcSubDir.endsWith("/")1378 && !strSrcSubDir.endsWith("\\"))1379 strSrcSubDir += "/";1380 1381 Utf8Str strSrcCur = strSrcDir + strSrcSubDir;1382 1383 LogFlowFunc(("strSrcDir=%s, strDstDir=%s, strFilter=%s, strSubDir=%s\n",1384 strSrcDir.c_str(), strDstDir.c_str(), strFilter.c_str(), strSubDir.c_str()));1385 1386 int rc;1387 1388 if (strSrcSubDir.isNotEmpty())1389 {1390 const uint32_t fMode = 0700; /** @todo */1391 1392 rc = RTDirCreate(Utf8Str(strDstDir + strSrcSubDir).c_str(), fMode, 0);1393 if (RT_FAILURE(rc))1394 return rc;1395 }1396 1397 GuestDirectoryOpenInfo dirOpenInfo;1398 dirOpenInfo.mFilter = strFilter;1399 dirOpenInfo.mPath = strSrcCur;1400 dirOpenInfo.mFlags = 0; /** @todo Handle flags? */1401 1402 ComObjPtr <GuestDirectory> pDir; int rcGuest;1403 rc = mSession->i_directoryOpen(dirOpenInfo, pDir, &rcGuest);1404 1405 if (RT_FAILURE(rc))1406 {1407 switch (rc)1408 {1409 case VERR_INVALID_PARAMETER:1410 setProgressErrorMsg(VBOX_E_IPRT_ERROR,1411 Utf8StrFmt(GuestSession::tr("Opening directory \"%s\" failed: Invalid parameter"), dirOpenInfo.mPath.c_str()));1412 break;1413 1414 case VERR_GSTCTL_GUEST_ERROR:1415 setProgressErrorMsg(VBOX_E_IPRT_ERROR, GuestProcess::i_guestErrorToString(rcGuest));1416 break;1417 1418 default:1419 setProgressErrorMsg(VBOX_E_IPRT_ERROR,1420 Utf8StrFmt(GuestSession::tr("Opening directory \"%s\" failed: %Rrc"), dirOpenInfo.mPath.c_str(), rc));1421 break;1422 }1423 1424 return rc;1425 }1426 1427 ComObjPtr<GuestFsObjInfo> fsObjInfo;1428 while (RT_SUCCESS(rc = pDir->i_readInternal(fsObjInfo, &rcGuest)))1429 {1430 FsObjType_T enmObjType = FsObjType_Unknown; /* Shut up MSC. */1431 HRESULT hr2 = fsObjInfo->COMGETTER(Type)(&enmObjType);1432 AssertComRC(hr2);1433 1434 com::Bstr bstrName;1435 hr2 = fsObjInfo->COMGETTER(Name)(bstrName.asOutParam());1436 AssertComRC(hr2);1437 1438 Utf8Str strName(bstrName);1439 1440 switch (enmObjType)1441 {1442 case FsObjType_Directory:1443 {1444 bool fSkip = false;1445 1446 if ( strName.equals(".")1447 || strName.equals(".."))1448 {1449 fSkip = true;1450 }1451 1452 if ( strFilter.isNotEmpty()1453 && !RTStrSimplePatternMatch(strFilter.c_str(), strName.c_str()))1454 fSkip = true;1455 1456 if ( fRecursive1457 && !fSkip)1458 rc = directoryCopyToHost(strSrcDir, strFilter, strDstDir, fRecursive, fFollowSymlinks,1459 strSrcSubDir + strName);1460 break;1461 }1462 1463 case FsObjType_Symlink:1464 {1465 if (fFollowSymlinks)1466 { /* Fall through to next case is intentional. */ }1467 else1468 break;1469 RT_FALL_THRU();1470 }1471 1472 case FsObjType_File:1473 {1474 if ( strFilter.isNotEmpty()1475 && !RTStrSimplePatternMatch(strFilter.c_str(), strName.c_str()))1476 {1477 break; /* Filter does not match. */1478 }1479 1480 if (RT_SUCCESS(rc))1481 {1482 Utf8Str strSrcFile = strSrcDir + strSrcSubDir + strName;1483 Utf8Str strDstFile = strDstDir + strSrcSubDir + strName;1484 rc = fileCopyFromGuest(strSrcFile, strDstFile, FileCopyFlag_None);1485 }1486 break;1487 }1488 1489 default:1490 break;1491 }1492 1493 BOOL fCanceled = FALSE;1494 if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))1495 && fCanceled)1496 break;1497 }1498 1499 if (rc == VERR_NO_MORE_FILES) /* Reading done? */1500 rc = VINF_SUCCESS;1501 1502 pDir->i_closeInternal(&rcGuest);1503 1504 LogFlowFunc(("Leaving '%s', rc=%Rrc\n", strSrcCur.c_str(), rc));1505 return rc;1506 }1507 #endif1508 1509 1346 HRESULT GuestSessionTaskCopyFrom::Init(const Utf8Str &strTaskDesc) 1510 1347 { … … 2004 1841 return rc; 2005 1842 } 2006 2007 #if 02008 SessionTaskCopyFileFrom::SessionTaskCopyFileFrom(GuestSession *pSession,2009 const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T fFileCopyFlags)2010 : GuestSessionCopyTask(pSession)2011 {2012 m_strTaskName = "gctlCpyFileFrm";2013 2014 mSource = strSource;2015 mDest = strDest;2016 2017 Type.File.fCopyFlags = fFileCopyFlags;2018 }2019 2020 SessionTaskCopyFileFrom::~SessionTaskCopyFileFrom(void)2021 {2022 2023 }2024 2025 int SessionTaskCopyFileFrom::Run(void)2026 {2027 LogFlowThisFuncEnter();2028 2029 AutoCaller autoCaller(mSession);2030 if (FAILED(autoCaller.rc())) return autoCaller.rc();2031 2032 int rc = fileCopyFromGuest(mSource, mDest, Type.File.fCopyFlags);2033 if (RT_SUCCESS(rc))2034 rc = setProgressSuccess();2035 2036 LogFlowFuncLeaveRC(rc);2037 return rc;2038 }2039 #endif2040 1843 2041 1844 GuestSessionTaskUpdateAdditions::GuestSessionTaskUpdateAdditions(GuestSession *pSession,
Note:
See TracChangeset
for help on using the changeset viewer.