Changeset 85422 in vbox for trunk/src/VBox
- Timestamp:
- Jul 23, 2020 8:11:39 AM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 139465
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/DragAndDrop/DnDTransferList.cpp
r85417 r85422 279 279 } 280 280 281 rc = dndTransferListObjAdd(pList, pszDir, pDirEntry->Info.Attr.fMode, fFlags); 282 AssertRCReturn(rc, rc); 283 281 284 LogFlowFunc(("pszDir=%s\n", pszDir)); 282 285 … … 359 362 * @param fFlags Flags of type DNDTRANSFERLISTFLAGS. 360 363 */ 361 static int dndTransferListAppend PathNativeRecursive(PDNDTRANSFERLIST pList,362 364 static int dndTransferListAppendDirectoryRecursive(PDNDTRANSFERLIST pList, 365 const char *pcszPathAbs, DNDTRANSFERLISTFLAGS fFlags) 363 366 { 364 367 char szPathAbs[RTPATH_MAX]; … … 372 375 RTDIRENTRYEX DirEntry; 373 376 } uBuf; 374 const size_t cchPathAbs = strlen(szPathAbs); 375 if (!cchPathAbs) 376 return VINF_SUCCESS; 377 378 const size_t cchPathAbs = RTStrNLen(szPathAbs, RTPATH_MAX); 379 AssertReturn(cchPathAbs, VERR_BUFFER_OVERFLOW); 380 381 /* Use the directory entry to hand-in the directorie's information. */ 382 rc = RTPathQueryInfo(pcszPathAbs, &uBuf.DirEntry.Info, RTFSOBJATTRADD_NOTHING); 383 AssertRCReturn(rc, rc); 384 377 385 return dndTransferListAppendPathRecursiveSub(pList, szPathAbs, cchPathAbs, &uBuf.DirEntry, fFlags); 378 386 } … … 385 393 * @param pszPathAbs Absolute path of directory to append. 386 394 * @param cbPathAbs Size (in bytes) of absolute path of directory to append. 395 * @param pObjInfo Pointer to directory object info to append. 387 396 * @param fFlags Transfer list flags to use for appending. 388 397 */ 389 398 static int dndTransferListAppendDirectory(PDNDTRANSFERLIST pList, char* pszPathAbs, size_t cbPathAbs, 390 DNDTRANSFERLISTFLAGS fFlags)399 PRTFSOBJINFO pObjInfo, DNDTRANSFERLISTFLAGS fFlags) 391 400 { 392 401 RTDIR hDir; 393 402 int rc = RTDirOpen(&hDir, pszPathAbs); 394 if (RT_FAILURE(rc)) 395 return rc; 396 397 const size_t cchPathAbs = RTStrNLen(pszPathAbs, cbPathAbs); 403 AssertRCReturn(rc, rc); 404 405 const size_t cchPathAbs = RTPathEnsureTrailingSeparator(pszPathAbs, sizeof(cbPathAbs)); 406 AssertReturn(cchPathAbs, VERR_BUFFER_OVERFLOW); 407 408 rc = dndTransferListObjAdd(pList, pszPathAbs, pObjInfo->Attr.fMode, fFlags); 409 AssertRCReturn(rc, rc); 398 410 399 411 for (;;) 400 412 { 401 /* Get the next directory. */413 /* Get the next entry. */ 402 414 RTDIRENTRYEX dirEntry; 403 415 rc = RTDirReadEx(hDir, &dirEntry, NULL, RTFSOBJATTRADD_UNIX, … … 416 428 417 429 /* Append the directory entry to our absolute path. */ 418 memcpy(&pszPathAbs[cchPathAbs], dirEntry.szName, dirEntry.cbName + 1 );430 memcpy(&pszPathAbs[cchPathAbs], dirEntry.szName, dirEntry.cbName + 1 /* Include terminator */); 419 431 420 432 LogFlowFunc(("szName=%s, pszPathAbs=%s\n", dirEntry.szName, pszPathAbs)); … … 424 436 case RTFS_TYPE_DIRECTORY: 425 437 { 426 rc = dndTransferListAppendPathNativeRecursive(pList, pszPathAbs, fFlags); 438 if (fFlags & DNDTRANSFERLIST_FLAGS_RECURSIVE) 439 rc = dndTransferListAppendDirectoryRecursive(pList, pszPathAbs, fFlags); 427 440 break; 428 441 } … … 466 479 467 480 int rc = DnDPathValidate(pcszPath, false /* fMustExist */); 468 if (RT_FAILURE(rc)) 469 return rc; 470 471 char szPathAbs[RTPATH_MAX]; 472 rc = RTStrCopy(szPathAbs, sizeof(szPathAbs), pcszPath); 473 if (RT_FAILURE(rc)) 474 return rc; 475 476 size_t cchPathAbs = RTStrNLen(szPathAbs, sizeof(szPathAbs)); 481 AssertRCReturn(rc, rc); 482 483 char szPathAbs[RTPATH_MAX]; 484 size_t cbPathAbs = sizeof(szPathAbs); 485 rc = RTStrCopy(szPathAbs, cbPathAbs, pcszPath); 486 AssertRCReturn(rc, rc); 487 488 size_t cchPathAbs = RTStrNLen(szPathAbs, cbPathAbs); 477 489 AssertReturn(cchPathAbs, VERR_INVALID_PARAMETER); 478 490 479 491 /* Convert path to transport style. */ 480 rc = DnDPathConvert(szPathAbs, sizeof(szPathAbs), DNDPATHCONVERT_FLAGS_TRANSPORT);492 rc = DnDPathConvert(szPathAbs, cbPathAbs, DNDPATHCONVERT_FLAGS_TRANSPORT); 481 493 if (RT_SUCCESS(rc)) 482 494 { … … 488 500 if (RT_SUCCESS(rc)) 489 501 { 490 switch (objInfo.Attr.fMode & RTFS_TYPE_MASK) 502 const uint32_t fType = objInfo.Attr.fMode & RTFS_TYPE_MASK; 503 504 if ( RTFS_IS_DIRECTORY(fType) 505 || RTFS_IS_FILE(fType)) 491 506 { 492 case RTFS_TYPE_DIRECTORY: 493 if (fFlags & DNDTRANSFERLIST_FLAGS_RECURSIVE) 494 rc = dndTransferListAppendDirectory(pList, szPathAbs, sizeof(szPathAbs), fFlags); 495 break; 496 497 case RTFS_TYPE_FILE: 498 rc = dndTransferListObjAdd(pList, szPathAbs, objInfo.Attr.fMode, fFlags); 499 break; 500 501 default: 502 /* Silently skip everything else. */ 503 break; 507 if (RTFS_IS_DIRECTORY(fType)) 508 { 509 cchPathAbs = RTPathEnsureTrailingSeparator(szPathAbs, cbPathAbs); 510 AssertReturn(cchPathAbs, VERR_BUFFER_OVERFLOW); 511 } 512 513 rc = dndTransferListRootAdd(pList, szPathAbs); 504 514 } 515 else 516 rc = VERR_NOT_SUPPORTED; 505 517 506 518 if (RT_SUCCESS(rc)) 507 rc = dndTransferListRootAdd(pList, szPathAbs); 519 { 520 switch (fType) 521 { 522 case RTFS_TYPE_DIRECTORY: 523 { 524 rc = dndTransferListAppendDirectory(pList, szPathAbs, cbPathAbs, &objInfo, fFlags); 525 break; 526 } 527 528 case RTFS_TYPE_FILE: 529 { 530 rc = dndTransferListObjAdd(pList, szPathAbs, objInfo.Attr.fMode, fFlags); 531 break; 532 } 533 534 default: 535 AssertFailed(); 536 break; 537 } 538 } 508 539 } 509 540 } … … 982 1013 static int dndTransferListRootAdd(PDNDTRANSFERLIST pList, const char *pcszRoot) 983 1014 { 1015 AssertPtrReturn(pList->pszPathRootAbs, VERR_WRONG_ORDER); /* The list's root path must be set first. */ 1016 984 1017 int rc; 985 1018 986 1019 /** @todo Handle / reject double entries. */ 987 1020 988 /* Calculate the path to add as the destination path to our URI object. */1021 /* Get the index pointing to the relative path in relation to set the root path. */ 989 1022 const size_t idxPathToAdd = strlen(pList->pszPathRootAbs); 990 1023 AssertReturn(strlen(pcszRoot) > idxPathToAdd, VERR_INVALID_PARAMETER); /* Should never happen (tm). */
Note:
See TracChangeset
for help on using the changeset viewer.