VirtualBox

Changeset 71847 in vbox for trunk


Ignore:
Timestamp:
Apr 12, 2018 12:23:29 PM (7 years ago)
Author:
vboxsync
Message:

Guest Control/Main: More bugfixes for copyTo/copyFrom tasks, along with test cases.

Location:
trunk/src/VBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/GuestSessionImplTasks.h

    r71824 r71847  
    116116     *  asynchronously. Optional. */
    117117    ComObjPtr<Progress>     mProgress;
     118    /** The guest's path style (depending on the guest OS type set). */
     119    uint32_t                mfPathStyle;
    118120};
    119121
     
    144146
    145147    GuestSessionCopyTask(GuestSession *pSession)
    146         : GuestSessionTask(pSession) { RT_ZERO(u); }
     148        : GuestSessionTask(pSession)
     149    {
     150        RT_ZERO(u);
     151    }
    147152
    148153    virtual ~GuestSessionCopyTask() { }
     
    151156
    152157    /** Source to copy from. */
    153     Utf8Str mSource;
     158    Utf8Str  mSource;
    154159    /** Destination to copy to. */
    155     Utf8Str mDest;
     160    Utf8Str  mDest;
    156161    /** Filter (wildcard-style) when copying directories. */
    157     Utf8Str mFilter;
     162    Utf8Str  mFilter;
    158163
    159164    union
  • trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp

    r71827 r71847  
    7171{
    7272    mSession = pSession;
     73
     74    mfPathStyle = mSession->i_getPathStyle() == PathStyle_DOS
     75                ? RTPATH_STR_F_STYLE_DOS : RTPATH_STR_F_STYLE_UNIX;
    7376}
    7477
     
    516519        else if (RTFS_IS_DIRECTORY(dstObjInfo.Attr.fMode))
    517520        {
    518             if (   strDest.endsWith("\\")
    519                 || strDest.endsWith("/"))
    520             {
    521                 /* Build the final file name with destination path (on the host). */
    522                 char szDstPath[RTPATH_MAX];
    523                 RTStrPrintf2(szDstPath, sizeof(szDstPath), "%s", strDest.c_str());
    524 
    525                 RTPathAppend(szDstPath, sizeof(szDstPath), RTPathFilename(strSource.c_str()));
    526 
    527                 pszDstFile = RTStrDup(szDstPath);
    528             }
    529             else
    530             {
    531                 setProgressErrorMsg(VBOX_E_IPRT_ERROR,
    532                                     Utf8StrFmt(GuestSession::tr("Destination directory \"%s\" already exists"),
    533                                                strDest.c_str(), rc));
    534                 rc = VERR_ALREADY_EXISTS;
    535             }
     521            /* Build the final file name with destination path (on the host). */
     522            char szDstPath[RTPATH_MAX];
     523            RTStrPrintf2(szDstPath, sizeof(szDstPath), "%s", strDest.c_str());
     524
     525            if (   !strDest.endsWith("\\")
     526                && !strDest.endsWith("/"))
     527                RTPathAppend(szDstPath, sizeof(szDstPath), "/"); /* IPRT can handle / on all hosts. */
     528
     529            RTPathAppend(szDstPath, sizeof(szDstPath), RTPathFilenameEx(strSource.c_str(), mfPathStyle));
     530
     531            pszDstFile = RTStrDup(szDstPath);
    536532        }
    537533        else if (RTFS_IS_SYMLINK(dstObjInfo.Attr.fMode))
     
    992988    Utf8Str strSrcCur = strSrcDir + strSrcSubDir;
    993989
    994     LogFlowFunc(("Entering '%s'\n", strSrcCur.c_str()));
     990    LogFlowFunc(("strSrcDir=%s, strDstDir=%s, strFilter=%s, strSubDir=%s\n",
     991                 strSrcDir.c_str(), strDstDir.c_str(), strFilter.c_str(), strSubDir.c_str()));
    995992
    996993    int rc;
     
    11241121    int rc = VINF_SUCCESS;
    11251122
    1126     /* Figure out if we need to copy the entire source directory or just its contents. */
    11271123    Utf8Str strSrcDir = mSource;
    11281124    Utf8Str strDstDir = mDest;
     1125
     1126    bool fDstExists = RTDirExists(strDstDir.c_str());
     1127    if (fDstExists)
     1128    {
     1129        if (!(u.Dir.fCopyFlags & DirectoryCopyFlag_CopyIntoExisting))
     1130        {
     1131            setProgressErrorMsg(VBOX_E_IPRT_ERROR,
     1132                                Utf8StrFmt(GuestSession::tr("Destination directory \"%s\" exists when it must not"), strDstDir.c_str()));
     1133            rc = VERR_ALREADY_EXISTS;
     1134        }
     1135    }
     1136
     1137    if (RT_FAILURE(rc))
     1138        return rc;
     1139
    11291140    if (   !strSrcDir.endsWith("/")
    11301141        && !strSrcDir.endsWith("\\"))
    11311142    {
    1132         if (   strDstDir.endsWith("/")
    1133             || strDstDir.endsWith("\\"))
    1134         {
    1135             strDstDir += Utf8StrFmt("%s", RTPathFilename(strSrcDir.c_str()));
    1136         }
    1137     }
    1138 
    1139     /* Create the root target directory on the host.
     1143        if (   !strDstDir.endsWith("/")
     1144            && !strDstDir.endsWith("\\"))
     1145                strDstDir += "/"; /* IPRT can handle / on all hosts. */
     1146
     1147        strDstDir += Utf8StrFmt("%s", RTPathFilenameEx(strSrcDir.c_str(), mfPathStyle));
     1148    }
     1149
     1150    /* Create the final target directory on the host.
    11401151     * The target directory might already exist on the host (based on u.Dir.fCopyFlags). */
    1141     const bool fExists = RTDirExists(strDstDir.c_str());
    1142     if (   fExists
    1143         && !(u.Dir.fCopyFlags & DirectoryCopyFlag_CopyIntoExisting))
    1144     {
    1145         setProgressErrorMsg(VBOX_E_IPRT_ERROR,
    1146                             Utf8StrFmt(GuestSession::tr("Destination directory \"%s\" exists when it must not"), strDstDir.c_str()));
    1147         rc = VERR_ALREADY_EXISTS;
    1148     }
    1149     else if (!fExists)
     1152    fDstExists = RTDirExists(strDstDir.c_str());
     1153    if (fDstExists)
     1154    {
     1155        if (!(u.Dir.fCopyFlags & DirectoryCopyFlag_CopyIntoExisting))
     1156        {
     1157            setProgressErrorMsg(VBOX_E_IPRT_ERROR,
     1158                                Utf8StrFmt(GuestSession::tr("Destination directory \"%s\" exists when it must not"), strDstDir.c_str()));
     1159            rc = VERR_ALREADY_EXISTS;
     1160        }
     1161    }
     1162    else
    11501163    {
    11511164        rc = RTDirCreate(strDstDir.c_str(), fDirMode, 0);
     
    11681181        return rc;
    11691182    }
     1183
     1184    LogFlowFunc(("Source: %s -> %s\n", mSource.c_str(), strSrcDir.c_str()));
     1185    LogFlowFunc(("Destination: %s -> %s\n", mDest.c_str(), strDstDir.c_str()));
    11701186
    11711187    /* At this point the directory on the host was created and (hopefully) is ready
  • trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py

    r71828 r71847  
    33703370                                     sDst = sScratchHst + "/"),
    33713371                      tdTestResult(fRc = True) ],
    3372                     # Destination is a directory (should fail).
     3372                    # Destination is a directory (without a trailing slash, should also work).
    33733373                    # See "cp" syntax.
    33743374                    [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
    33753375                                     sDst = sScratchHst),
     3376                      tdTestResult(fRc = True) ],
     3377                    # Destination is a non-existing directory.
     3378                    [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
     3379                                     sDst = sScratchHst + "/non-existing-directory/"),
    33763380                      tdTestResult(fRc = False) ]
    33773381                ]);
     
    33843388                    # Copying entire directories (destination is "<sScratch>", which exists, which should fail).
    33853389                    [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web',
    3386                                     sDst = sScratchHst),
     3390                                     sDst = sScratchHst),
    33873391                      tdTestResult(fRc = False) ],
    3388                     # Copying entire directories (destination is "<sScratch>\Web").
    3389                     # Should fail, as the corresponding flag is missing.
     3392                    # Ditto, with trailing slash.
    33903393                    [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web',
    3391                                     sDst = sScratchHst + "/"),
     3394                                     sDst = sScratchHst + "/"),
    33923395                      tdTestResult(fRc = False) ],
    3393                     # Next try with correct flag being set.
     3396                    # Next try with the DirectoryCopyFlag_CopyIntoExisting flag being set.
    33943397                    [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web',
    3395                                     sDst = sScratchHst + "/", aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
     3398                                     sDst = sScratchHst, aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
    33963399                      tdTestResult(fRc = True) ],
    3397                     # Copying contents of directories (destination is "<sScratch>/").
     3400                    # Ditto, with trailing slash.
     3401                    [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web',
     3402                                     sDst = sScratchHst + "/", aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
     3403                      tdTestResult(fRc = True) ],
     3404                    # Copying contents of directories into a non-existing directory chain on the host which fail.
    33983405                    [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web\\',
    3399                                     sDst = sScratchHst + "/", aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
     3406                                     sDst = sScratchHst + "/not/existing/", aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
     3407                      tdTestResult(fRc = False) ],
     3408                    # Copying contents of directories into a non-existing directory on the host, which should succeed.
     3409                    [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web\\',
     3410                                     sDst = sScratchHst + "/no-existing/", aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
    34003411                      tdTestResult(fRc = True) ]
    34013412                ]);
Note: See TracChangeset for help on using the changeset viewer.

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