VirtualBox

Changeset 71533 in vbox for trunk/src


Ignore:
Timestamp:
Mar 28, 2018 9:35:16 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
121510
Message:

Guest Control/Main: Bugfixes for IGuestSession::fileCopyToGuest() -- allow the destination to be a directory also (needed for test cases).

File:
1 edited

Legend:

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

    r71510 r71533  
    13901390    }
    13911391
    1392     const char *pszFileName = mSource.c_str();
    1393 
    1394     if (   !pszFileName
    1395         || !RTFileExists(pszFileName))
     1392    const char *pszSrcFile = mSource.c_str();
     1393
     1394    if (   !pszSrcFile
     1395        || !RTFileExists(pszSrcFile))
    13961396    {
    13971397        setProgressErrorMsg(VBOX_E_IPRT_ERROR,
    1398                             Utf8StrFmt(GuestSession::tr("Source file \"%s\" not valid or does not exist"), pszFileName));
     1398                            Utf8StrFmt(GuestSession::tr("Source file \"%s\" not valid or does not exist"), pszSrcFile));
    13991399        return VERR_FILE_NOT_FOUND;
    14001400    }
     
    14081408    }
    14091409
    1410     /** @todo Try to lock the destination directory on the guest here first? */
     1410    /** @todo Try to lock the destination file / directory on the guest here first? */
     1411    char *pszDstFile = NULL;
    14111412
    14121413    int rc = VINF_SUCCESS;
     
    14261427            {
    14271428                setProgressErrorMsg(VBOX_E_IPRT_ERROR,
    1428                                     Utf8StrFmt(GuestSession::tr("Path \"%s\" is not a directory on guest"), mDest.c_str()));
     1429                                    Utf8StrFmt(GuestSession::tr("Path \"%s\" is not a directory on guest"), pszDstFile));
    14291430                rc = VERR_NOT_A_DIRECTORY;
    14301431            }
    14311432            else
    14321433            {
    1433                 AssertPtr(pszFileName);
    1434                 mDest += pszFileName;
     1434                /* Build the final file name with destination path (on the guest). */
     1435                char szDstPath[RTPATH_MAX];
     1436                RTStrPrintf2(szDstPath, sizeof(szDstPath), "%s", mDest.c_str());
     1437
     1438                RTPathAppend(szDstPath, sizeof(szDstPath), RTPathFilename(pszSrcFile));
     1439
     1440                pszDstFile = RTStrDup(szDstPath);
    14351441            }
    14361442        }
     
    14471453                    setProgressErrorMsg(VBOX_E_IPRT_ERROR,
    14481454                                        Utf8StrFmt(GuestSession::tr("Unable to query information for directory \"%s\" on the guest: %Rrc"),
    1449                                                    mDest.c_str(), rc));
     1455                                                   pszDstFile, rc));
    14501456                    break;
    14511457            }
    14521458        }
    14531459    }
     1460    else
     1461        pszDstFile = RTStrDup(mDest.c_str());
    14541462
    14551463    if (RT_SUCCESS(rc))
    14561464    {
     1465        AssertPtrReturn(pszDstFile, VERR_NO_MEMORY);
     1466
    14571467        if (mSourceFile) /* Use existing file handle. */
    1458             rc = fileCopyToEx(mSource, mDest, (FileCopyFlag_T)mFileCopyFlags, mSourceFile, mSourceOffset, mSourceSize);
     1468            rc = fileCopyToEx(pszSrcFile, pszDstFile, (FileCopyFlag_T)mFileCopyFlags, mSourceFile, mSourceOffset, mSourceSize);
    14591469        else
    1460             rc = fileCopyTo(mSource, mDest, (FileCopyFlag_T)mFileCopyFlags);
     1470            rc = fileCopyTo(pszSrcFile, pszDstFile, (FileCopyFlag_T)mFileCopyFlags);
    14611471
    14621472        if (RT_SUCCESS(rc))
    14631473            rc = setProgressSuccess();
    14641474    }
     1475
     1476    if (pszDstFile)
     1477        RTStrFree(pszDstFile);
    14651478
    14661479    LogFlowFuncLeaveRC(rc);
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