- Timestamp:
- Apr 4, 2018 5:06:34 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp
r71649 r71667 542 542 int GuestSessionTask::fileCopyFrom(const Utf8Str &strSource, const Utf8Str &strDest, FileCopyFlag_T enmFileCopyFlags) 543 543 { 544 LogFlowThisFunc(("strSource=%s, strDest=%s, enmFileCopyFlags=0x%x\n", strSource.c_str(), strDest.c_str(), enmFileCopyFlags)); 545 546 char *pszDstFile = NULL; 547 548 RTFSOBJINFO objInfo; 549 int rc = RTPathQueryInfo(strDest.c_str(), &objInfo, RTFSOBJATTRADD_NOTHING); 550 if (RT_SUCCESS(rc)) 551 { 552 if (RTFS_IS_FILE(objInfo.Attr.fMode)) 553 { 554 if (enmFileCopyFlags & FileCopyFlag_NoReplace) 555 { 556 setProgressErrorMsg(VBOX_E_IPRT_ERROR, 557 Utf8StrFmt(GuestSession::tr("Destination file \"%s\" on host already exists"), 558 strDest.c_str(), rc)); 559 return VERR_ALREADY_EXISTS; 560 } 561 562 pszDstFile = RTStrDup(strDest.c_str()); 563 } 564 else if (RTFS_IS_DIRECTORY(objInfo.Attr.fMode)) 565 { 566 if ( strDest.endsWith("\\") 567 || strDest.endsWith("/")) 568 { 569 /* Build the final file name with destination path (on the host). */ 570 char szDstPath[RTPATH_MAX]; 571 RTStrPrintf2(szDstPath, sizeof(szDstPath), "%s", strDest.c_str()); 572 573 RTPathAppend(szDstPath, sizeof(szDstPath), RTPathFilename(strSource.c_str())); 574 575 pszDstFile = RTStrDup(szDstPath); 576 } 577 else 578 { 579 setProgressErrorMsg(VBOX_E_IPRT_ERROR, 580 Utf8StrFmt(GuestSession::tr("Destination directory \"%s\" on host already exists"), 581 strDest.c_str(), rc)); 582 return VERR_ALREADY_EXISTS; 583 } 584 } 585 else if (RTFS_IS_SYMLINK(objInfo.Attr.fMode)) 586 { 587 if (!(enmFileCopyFlags & FileCopyFlag_FollowLinks)) 588 { 589 setProgressErrorMsg(VBOX_E_IPRT_ERROR, 590 Utf8StrFmt(GuestSession::tr("Destination file \"%s\" on the host is a symbolic link"), 591 strDest.c_str(), rc)); 592 return VERR_IS_A_SYMLINK; 593 } 594 595 pszDstFile = RTStrDup(strDest.c_str()); 596 } 597 } 598 else 599 pszDstFile = RTStrDup(strDest.c_str()); 600 601 if (!pszDstFile) 602 { 603 setProgressErrorMsg(VBOX_E_IPRT_ERROR, Utf8StrFmt(GuestSession::tr("No memory to allocate destination file path"))); 604 return VERR_NO_MEMORY; 605 } 606 544 607 RTFILE hFile; 545 int rc = RTFileOpen(&hFile, strDest.c_str(),546 608 rc = RTFileOpen(&hFile, pszDstFile, 609 RTFILE_O_WRITE | RTFILE_O_OPEN_CREATE | RTFILE_O_DENY_WRITE); /** @todo Use the correct open modes! */ 547 610 if (RT_FAILURE(rc)) 548 611 { 549 612 setProgressErrorMsg(VBOX_E_IPRT_ERROR, 550 613 Utf8StrFmt(GuestSession::tr("Opening/creating destination file on host \"%s\" failed: %Rrc"), 551 strDest.c_str(), rc));614 pszDstFile, rc)); 552 615 return rc; 553 616 } 554 617 555 rc = fileCopyFromEx(strSource, strDest, enmFileCopyFlags, &hFile, 0 /* Offset, unused */, 0 /* Size, unused */);618 rc = fileCopyFromEx(strSource, pszDstFile, enmFileCopyFlags, &hFile, 0 /* Offset, unused */, 0 /* Size, unused */); 556 619 557 620 int rc2 = RTFileClose(hFile); 558 621 AssertRC(rc2); 559 622 623 if (pszDstFile) 624 RTStrFree(pszDstFile); 625 626 LogFlowFuncLeaveRC(rc); 560 627 return rc; 561 628 }
Note:
See TracChangeset
for help on using the changeset viewer.