Changeset 37633 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Jun 24, 2011 2:24:34 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 72482
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp
r37447 r37633 1044 1044 /* Source is a single file. */ 1045 1045 char *pszFileName = RTPathFilename(pszSource); 1046 mapDest[Utf8Str( pszDestRoot)].push_back(DESTFILEENTRY(pszFileName));1047 1048 *pcObjects ++;1046 mapDest[Utf8Str("")].push_back(DESTFILEENTRY(pszFileName)); 1047 1048 *pcObjects += 1; 1049 1049 } 1050 1050 else … … 1093 1093 } 1094 1094 return rc; 1095 }1096 1097 /**1098 * Determines the destination root for a specified source entry.1099 *1100 * @return IPRT status code.1101 * @param ppszDestRoot Receives pointer of allocated destination root. Must be1102 * free'd with ctrlCopyFreeDestinationRoot().1103 * @param sourceEntry Source entry to determine the destination root for.1104 * @param pszDest Original destination string to use.1105 */1106 static int ctrlCopyAllocDestinationRoot(char **ppszDestRoot, SOURCEFILEENTRY &sourceEntry, const char *pszDest)1107 {1108 AssertPtrReturn(ppszDestRoot, VERR_INVALID_POINTER);1109 AssertPtrReturn(pszDest, VERR_INVALID_POINTER);1110 1111 int rc = VINF_SUCCESS;1112 1113 /*1114 * If a source filter is set (e.g. *.dll) use the original1115 * destination as our final root, because we want to copy all filtered1116 * files directly into the original root (and its sub directories if apply).1117 */1118 char *pszDestRoot;1119 if (!sourceEntry.mFilter.isEmpty())1120 pszDestRoot = RTStrDup(pszDest);1121 else1122 {1123 /*1124 * However, if no source filter is set we want to also copy the original1125 * source directory to our destination so that source "c:\foo", dest "c:\temp"1126 * becomes "c:\temp\foo".1127 */1128 int iLen = RTStrAPrintf(&pszDestRoot, "%s/%s",1129 pszDest, RTPathFilename(sourceEntry.mSource.c_str()));1130 if (!iLen)1131 rc = VERR_NO_MEMORY;1132 }1133 1134 if (RT_SUCCESS(rc))1135 *ppszDestRoot = pszDestRoot;1136 return rc;1137 }1138 1139 /**1140 * Frees a formerly allocated destination root.1141 *1142 * @param pszDestRoot Pointer to destination root to free.1143 */1144 static void ctrlCopyFreeDestinationRoot(char *pszDestRoot)1145 {1146 RTStrFree(pszDestRoot);1147 1095 } 1148 1096 … … 1160 1108 */ 1161 1109 static int ctrlCopyPrepareDestDirectory(IGuest *pGuest, bool fHostToGuest, 1162 DESTDIRMAPITER itDest, const char *pszDestRoot,1110 const char *pszDestRoot, const char *pszDestSub, 1163 1111 const char *pszUsername, const char *pszPassword) 1164 1112 { 1165 1113 AssertPtrReturn(pGuest, VERR_INVALID_POINTER); 1166 1114 AssertPtrReturn(pszDestRoot, VERR_INVALID_POINTER); 1115 AssertPtrReturn(pszDestSub, VERR_INVALID_POINTER); 1167 1116 AssertPtrReturn(pszUsername, VERR_INVALID_POINTER); 1168 1117 AssertPtrReturn(pszPassword, VERR_INVALID_POINTER); … … 1173 1122 /* Create root directory (= empty name) and skip the rest for 1174 1123 * this round. */ 1175 if ( itDest->first.isEmpty())1124 if (!strlen(pszDestSub)) 1176 1125 { 1177 1126 pszDestFinal = RTStrDup(pszDestRoot); … … 1181 1130 else /* Create sub-directories, also empty ones. */ 1182 1131 { 1183 if (!RTStrAPrintf(&pszDestFinal, "%s/%s", pszDestRoot, itDest->first.c_str()))1132 if (!RTStrAPrintf(&pszDestFinal, "%s/%s", pszDestRoot, pszDestSub)) 1184 1133 rc = VERR_NO_MEMORY; 1185 1134 } … … 1278 1227 } 1279 1228 1280 static int ctrlCopyToDestDirectory(IGuest *pGuest, bool fVerbose, bool fDryRun, bool fHostToGuest, DESTDIRMAPITER itDest, const char *pszDestRoot, 1281 SOURCEFILEENTRY &sourceEntry, uint32_t uFlags, const char *pszUsername, const char *pszPassword) 1229 static int ctrlCopyToDestDirectory(IGuest *pGuest, bool fVerbose, bool fDryRun, bool fHostToGuest, 1230 const char *pszSourceDir, 1231 const char *pszDestRoot, const char *pszDestSub, const char *pszFileName, 1232 uint32_t uFlags, const char *pszUsername, const char *pszPassword) 1282 1233 { 1283 1234 AssertPtrReturn(pGuest, VERR_INVALID_POINTER); 1284 1235 AssertPtrReturn(pszDestRoot, VERR_INVALID_POINTER); 1236 AssertPtrReturn(pszDestSub, VERR_INVALID_POINTER); 1237 AssertPtrReturn(pszFileName, VERR_INVALID_POINTER); 1238 AssertPtrReturn(pszSourceDir, VERR_INVALID_POINTER); 1285 1239 AssertPtrReturn(pszUsername, VERR_INVALID_POINTER); 1286 1240 AssertPtrReturn(pszPassword, VERR_INVALID_POINTER); 1287 1241 1242 int iLen; 1243 char *pszSource; 1244 if (!strlen(pszDestSub)) 1245 iLen = RTStrAPrintf(&pszSource, "%s/%s", pszSourceDir, pszFileName); 1246 else 1247 iLen = RTStrAPrintf(&pszSource, "%s/%s/%s", 1248 pszSourceDir, pszDestSub, pszFileName); 1249 if (!iLen) 1250 return VERR_NO_MEMORY; 1251 1252 char *pszDest; 1253 if (!strlen(pszDestSub)) 1254 iLen = RTStrAPrintf(&pszDest, "%s/%s", pszDestRoot, pszFileName); 1255 else 1256 iLen = RTStrAPrintf(&pszDest, "%s/%s/%s", pszDestRoot, pszDestSub, 1257 pszFileName); 1258 if (!iLen) 1259 { 1260 RTStrFree(pszSource); 1261 return VERR_NO_MEMORY; 1262 } 1263 1264 if (fVerbose) 1265 RTPrintf("\"%s\" -> \"%s\"\n", pszSource, pszDest); 1266 1288 1267 int rc = VINF_SUCCESS; 1289 for (unsigned long l = 0; l < itDest->second.size(); l++) 1290 {1291 int iLen;1292 char *pszSource;1293 if ( itDest->first.isEmpty())1294 iLen = RTStrAPrintf(&pszSource, "%s/%s", sourceEntry.mSource.c_str(),1295 itDest->second[l].mFileName.c_str());1268 1269 /* Finally copy the desired file (if no dry run selected). */ 1270 if (!fDryRun) 1271 { 1272 if (fHostToGuest) 1273 rc = ctrlCopyFileToGuest(pGuest, pszSource, pszDest, 1274 pszUsername, pszPassword, uFlags); 1296 1275 else 1297 iLen = RTStrAPrintf(&pszSource, "%s/%s/%s", sourceEntry.mSource.c_str(), 1298 itDest->first.c_str(), itDest->second[l].mFileName.c_str()); 1299 if (!iLen) 1300 { 1301 rc = VERR_NO_MEMORY; 1302 break; 1303 } 1304 1305 char *pszDest; 1306 if (itDest->first.isEmpty()) 1307 iLen = RTStrAPrintf(&pszDest, "%s/%s", pszDestRoot, 1308 itDest->second[l].mFileName.c_str()); 1309 else 1310 iLen = RTStrAPrintf(&pszDest, "%s/%s/%s", pszDestRoot, itDest->first.c_str(), 1311 itDest->second[l].mFileName.c_str()); 1312 if (!iLen) 1313 { 1314 rc = VERR_NO_MEMORY; 1315 RTStrFree(pszSource); 1316 break; 1317 } 1318 1319 if (fVerbose) 1320 RTPrintf("\"%s\" -> \"%s\"\n", pszSource, pszDest); 1321 1322 /* Finally copy the desired file (if no dry run selected). */ 1323 if (!fDryRun) 1324 { 1325 if (fHostToGuest) 1326 rc = ctrlCopyFileToGuest(pGuest, pszSource, pszDest, 1327 pszUsername, pszPassword, uFlags); 1328 else 1329 rc = ctrlCopyFileToHost(pGuest, pszSource, pszDest, 1330 pszUsername, pszPassword, uFlags); 1331 } 1332 RTStrFree(pszSource); 1333 RTStrFree(pszDest); 1334 } 1276 rc = ctrlCopyFileToHost(pGuest, pszSource, pszDest, 1277 pszUsername, pszPassword, uFlags); 1278 } 1279 RTStrFree(pszSource); 1280 RTStrFree(pszDest); 1281 1335 1282 return rc; 1336 1283 } … … 1475 1422 for (unsigned long s = 0; s < vecSources.size(); s++) 1476 1423 { 1424 char *pszSourceDir; 1425 if (RTDirExists(vecSources[s].mSource.c_str())) 1426 pszSourceDir = RTStrDup(vecSources[s].mSource.c_str()); 1427 else 1428 { 1429 pszSourceDir = RTStrDup(vecSources[s].mSource.c_str()); 1430 RTPathStripFilename(pszSourceDir); 1431 } 1432 1477 1433 uint32_t cObjects = 0; 1478 1434 DESTDIRMAP mapDest; 1479 1480 char *pszDestRoot; 1481 vrc = ctrlCopyAllocDestinationRoot(&pszDestRoot, vecSources[s], Utf8Dest.c_str()); 1482 if (RT_SUCCESS(vrc)) 1483 { 1484 if (fHostToGuest) 1485 vrc = ctrlCopyConstructDestinationsForGuest(vecSources[s], fFlags, pszDestRoot, 1486 mapDest, &cObjects); 1487 else 1488 vrc = ctrlCopyConstructDestinationsForHost(guest, Utf8UserName.c_str(), Utf8Password.c_str(), 1489 vecSources[s], fFlags, pszDestRoot, 1490 mapDest, &cObjects); 1435 const char *pszDestRoot = Utf8Dest.c_str(); 1436 1437 if (fHostToGuest) 1438 vrc = ctrlCopyConstructDestinationsForGuest(vecSources[s], fFlags, pszDestRoot, 1439 mapDest, &cObjects); 1440 else 1441 vrc = ctrlCopyConstructDestinationsForHost(guest, Utf8UserName.c_str(), Utf8Password.c_str(), 1442 vecSources[s], fFlags, pszDestRoot, 1443 mapDest, &cObjects); 1444 if (RT_FAILURE(vrc)) 1445 { 1446 if ( fVerbose 1447 && vrc == VERR_FILE_NOT_FOUND) 1448 { 1449 RTPrintf("Warning: Source \"%s\" does not exist, skipping!\n", 1450 vecSources[s].mSource.c_str()); 1451 } 1452 } 1453 else 1454 { 1455 /* 1456 * Prepare directory structure of each destination directory. 1457 */ 1458 DESTDIRMAPITER itDest; 1459 for (itDest = mapDest.begin(); itDest != mapDest.end(); itDest++) 1460 { 1461 if (fVerbose) 1462 { 1463 const char *pszSubDir = itDest->first.c_str(); 1464 AssertPtr(pszSubDir); 1465 if (!strlen(pszSubDir)) 1466 RTPrintf("Preparing directory \"%s\" ...\n", pszDestRoot); 1467 else 1468 RTPrintf("Preparing directory \"%s/%s\" ...\n", pszDestRoot, 1469 itDest->first.c_str()); 1470 } 1471 if (!fDryRun) 1472 vrc = ctrlCopyPrepareDestDirectory(guest, fHostToGuest, 1473 pszDestRoot, itDest->first.c_str(), 1474 Utf8UserName.c_str(), Utf8Password.c_str()); 1475 if (RT_FAILURE(vrc)) 1476 break; 1477 } 1478 1491 1479 if (RT_FAILURE(vrc)) 1480 break; 1481 1482 if (fVerbose) 1492 1483 { 1493 if ( fVerbose 1494 && vrc == VERR_FILE_NOT_FOUND) 1484 if (!cObjects) 1485 RTPrintf("Warning: Source \"%s\" has no (matching) files to copy, skipping!\n", 1486 vecSources[s].mSource.c_str()); 1487 else 1488 RTPrintf("Copying \"%s\" (%u files) ...\n", 1489 vecSources[s].mSource.c_str(), cObjects); 1490 } 1491 1492 /* 1493 * Copy files of each destination root directory to the guest. 1494 */ 1495 for (itDest = mapDest.begin(); itDest != mapDest.end(); itDest++) 1496 { 1497 if (fVerbose && itDest->second.size()) 1495 1498 { 1496 RTPrintf("Warning: Source \"%s\" does not exist, skipping!\n", 1497 vecSources[s].mSource.c_str()); 1499 if (itDest->first.isEmpty()) 1500 RTPrintf("Copying %u files ...\n", itDest->second.size()); 1501 else 1502 RTPrintf("Copying directory \"%s\" (%u files) ...\n", 1503 itDest->first.c_str(), itDest->second.size()); 1498 1504 } 1499 } 1500 else 1501 { 1502 /* 1503 * Prepare directory structure of each destination directory. 1504 */ 1505 DESTDIRMAPITER itDest; 1506 ComPtr<IProgress> progress; 1507 for (itDest = mapDest.begin(); itDest != mapDest.end(); itDest++) 1505 1506 for (unsigned long l = 0; l < itDest->second.size(); l++) 1508 1507 { 1509 if (!fDryRun) 1510 vrc = ctrlCopyPrepareDestDirectory(guest, fHostToGuest, itDest, pszDestRoot, 1511 Utf8UserName.c_str(), Utf8Password.c_str()); 1508 vrc = ctrlCopyToDestDirectory(guest, fVerbose, fDryRun, fHostToGuest, 1509 pszSourceDir, 1510 pszDestRoot, itDest->first.c_str() /* Sub directory */, 1511 itDest->second[l].mFileName.c_str() /* Filename */, 1512 fFlags, Utf8UserName.c_str(), Utf8Password.c_str()); 1512 1513 if (RT_FAILURE(vrc)) 1513 1514 break; 1514 1515 } 1515 1516 1516 if (fVerbose) 1517 { 1518 if (!cObjects) 1519 RTPrintf("Warning: Source \"%s\" has no (matching) files to copy, skipping!\n", 1520 vecSources[s].mSource.c_str()); 1521 else 1522 RTPrintf("Copying \"%s\" (%u files) ...\n", 1523 vecSources[s].mSource.c_str(), cObjects); 1524 } 1525 1526 /* 1527 * Copy files of each destination root directory to the guest. 1528 */ 1529 for (itDest = mapDest.begin(); itDest != mapDest.end(); itDest++) 1530 { 1531 if (fVerbose && itDest->second.size()) 1532 { 1533 if (itDest->first.isEmpty()) 1534 RTPrintf("Copying %u files ...\n", itDest->second.size()); 1535 else 1536 RTPrintf("Copying directory \"%s\" (%u files) ...\n", 1537 itDest->first.c_str(), itDest->second.size()); 1538 } 1539 1540 vrc = ctrlCopyToDestDirectory(guest, fVerbose, fDryRun, fHostToGuest, itDest, pszDestRoot, 1541 vecSources[s], fFlags, Utf8UserName.c_str(), Utf8Password.c_str()); 1542 if (RT_FAILURE(vrc)) 1543 break; 1544 } 1517 if (RT_FAILURE(vrc)) 1518 break; 1545 1519 } 1546 ctrlCopyFreeDestinationRoot(pszDestRoot); 1547 } 1520 1521 if (RT_FAILURE(vrc)) 1522 break; 1523 } 1524 1525 RTStrFree(pszSourceDir); 1548 1526 } 1549 1527
Note:
See TracChangeset
for help on using the changeset viewer.