VirtualBox

Ignore:
Timestamp:
Nov 8, 2022 10:09:13 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
154453
Message:

Guest Control/Main: More fixes wrt respecting the FileCopyFlag_ flags. bugref:10286

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp

    r97446 r97448  
    496496 * Copies a file from the guest to the host.
    497497 *
     498 * @return VBox status code.
     499 * @retval VWRN_ALREADY_EXISTS  if the file already exists and FileCopyFlag_NoReplace is specified,
     500 *                              *or * the file at the destination has the same (or newer) modification time
     501 *                              and FileCopyFlag_Update is specified.
    498502 * @param  strSrc               Full path of source file on the guest to copy.
    499503 * @param  strDst               Full destination path and file name (host style) to copy file to.
     
    579583            if (fFileCopyFlags & FileCopyFlag_NoReplace)
    580584            {
    581                 setProgressErrorMsg(VBOX_E_IPRT_ERROR,
    582                                     Utf8StrFmt(tr("Host file \"%s\" already exists"), strDst.c_str()));
    583                 vrc = VERR_ALREADY_EXISTS;
    584             }
    585 
    586             if (fFileCopyFlags & FileCopyFlag_Update)
     585                LogRel2(("Guest Control: Host file \"%s\" already exists, skipping", strDst.c_str()));
     586                vrc = VWRN_ALREADY_EXISTS;
     587                fSkip = true;
     588            }
     589
     590            if (   !fSkip
     591                && fFileCopyFlags & FileCopyFlag_Update)
    587592            {
    588593                RTTIMESPEC srcModificationTimeTS;
     
    591596                {
    592597                    LogRel2(("Guest Control: Host file \"%s\" has same or newer modification date, skipping", strDst.c_str()));
     598                    vrc = VWRN_ALREADY_EXISTS;
    593599                    fSkip = true;
    594600                }
     
    601607            else if (vrc != VERR_FILE_NOT_FOUND)  /* Ditto. */
    602608                setProgressErrorMsg(VBOX_E_IPRT_ERROR,
    603                                     Utf8StrFmt(tr("Host destination file lookup for \"%s\" failed: %Rrc"), strDst.c_str(), vrc));
     609                                    Utf8StrFmt(tr("Host file lookup for \"%s\" failed: %Rrc"), strDst.c_str(), vrc));
    604610        }
    605611    }
     
    609615        int vrc2 = srcFile->i_closeFile(&vrcGuest);
    610616        AssertRC(vrc2);
    611         return VINF_SUCCESS;
     617        return vrc;
    612618    }
    613619
     
    642648    }
    643649
    644     LogRel2(("Guest Control: Copying file '%s' from guest to '%s' on host ...\n", strSrc.c_str(), strDst.c_str()));
    645 
    646650    LogFlowFunc(("vrc=%Rrc, dstFsType=%#x, pszDstFile=%s\n", vrc, dstObjInfo.Attr.fMode & RTFS_TYPE_MASK, strDst.c_str()));
    647651
     
    649653        || vrc == VERR_FILE_NOT_FOUND)
    650654    {
     655        LogRel2(("Guest Control: Copying file '%s' from guest to '%s' on host ...\n", strSrc.c_str(), strDst.c_str()));
    651656
    652657        RTFILE hDstFile;
     
    788793 * Copies a file from the host to the guest.
    789794 *
     795 * @return VBox status code.
     796 * @retval VWRN_ALREADY_EXISTS  if the file already exists and FileCopyFlag_NoReplace is specified,
     797 *                              *or * the file at the destination has the same (or newer) modification time
     798 *                              and FileCopyFlag_Update is specified.
    790799 * @param  strSrc               Full path of source file on the host.
    791800 * @param  strDst               Full destination path and file name (guest style) to copy file to. Guest-path style.
     
    794803int GuestSessionTask::fileCopyToGuest(const Utf8Str &strSrc, const Utf8Str &strDst, FileCopyFlag_T fFileCopyFlags)
    795804{
    796     LogFlowThisFunc(("strSource=%s, strDst=%s, fFileCopyFlags=0x%x\n", strSrc.c_str(), strDst.c_str(), fFileCopyFlags));
     805    LogFlowThisFunc(("strSource=%s, strDst=%s, fFileCopyFlags=%#x\n", strSrc.c_str(), strDst.c_str(), fFileCopyFlags));
    797806
    798807    GuestFileOpenInfo dstOpenInfo;
     
    840849            if (RT_SUCCESS(vrc))
    841850            {
    842                 if (fFileCopyFlags & FileCopyFlag_Update)
     851                /* Only perform a remote file query when needed.  */
     852                if (   (fFileCopyFlags & FileCopyFlag_Update)
     853                    || (fFileCopyFlags & FileCopyFlag_NoReplace))
    843854                {
    844855                    GuestFsObjData dstObjData;
     
    847858                    if (RT_SUCCESS(vrc))
    848859                    {
    849                         RTTIMESPEC dstModificationTimeTS;
    850                         RTTimeSpecSetSeconds(&dstModificationTimeTS, dstObjData.mModificationTime);
    851                         if (RTTimeSpecCompare(&dstModificationTimeTS, &srcObjInfo.ModificationTime) <= 0)
     860                        if (fFileCopyFlags & FileCopyFlag_NoReplace)
    852861                        {
    853                             LogRel2(("Guest Control: Guest file \"%s\" has same or newer modification date, skipping",
    854                                      strDst.c_str()));
     862                            LogRel2(("Guest Control: Guest file \"%s\" already exists, skipping", strDst.c_str()));
     863                            vrc = VWRN_ALREADY_EXISTS;
    855864                            fSkip = true;
     865                        }
     866
     867                        if (   !fSkip
     868                            && fFileCopyFlags & FileCopyFlag_Update)
     869                        {
     870                            RTTIMESPEC dstModificationTimeTS;
     871                            RTTimeSpecSetSeconds(&dstModificationTimeTS, dstObjData.mModificationTime);
     872                            if (RTTimeSpecCompare(&dstModificationTimeTS, &srcObjInfo.ModificationTime) <= 0)
     873                            {
     874                                LogRel2(("Guest Control: Guest file \"%s\" has same or newer modification date, skipping",
     875                                         strDst.c_str()));
     876                                vrc = VWRN_ALREADY_EXISTS;
     877                                fSkip = true;
     878                            }
    856879                        }
    857880                    }
     
    893916        int vrc2 = dstFile->i_closeFile(&vrcGuest);
    894917        AssertRC(vrc2);
    895         return VINF_SUCCESS;
     918        return vrc;
    896919    }
    897920
     
    17921815                            break;
    17931816                        }
     1817
     1818                        /* Append the actual file name to the destination. */
     1819                        strDstRootAbs += PATH_STYLE_SEP_STR(PATH_STYLE_NATIVE);
     1820                        strDstRootAbs += RTPathFilename(strSrcRootAbs.c_str());
    17941821                        break;
    17951822                    }
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette