VirtualBox

Changeset 85422 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 23, 2020 8:11:39 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
139465
Message:

DnD/TransferList: More fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/DragAndDrop/DnDTransferList.cpp

    r85417 r85422  
    279279    }
    280280
     281    rc = dndTransferListObjAdd(pList, pszDir, pDirEntry->Info.Attr.fMode, fFlags);
     282    AssertRCReturn(rc, rc);
     283
    281284    LogFlowFunc(("pszDir=%s\n", pszDir));
    282285
     
    359362 * @param   fFlags              Flags of type DNDTRANSFERLISTFLAGS.
    360363 */
    361 static int dndTransferListAppendPathNativeRecursive(PDNDTRANSFERLIST pList,
    362                                                     const char *pcszPathAbs, DNDTRANSFERLISTFLAGS fFlags)
     364static int dndTransferListAppendDirectoryRecursive(PDNDTRANSFERLIST pList,
     365                                                   const char *pcszPathAbs, DNDTRANSFERLISTFLAGS fFlags)
    363366{
    364367    char szPathAbs[RTPATH_MAX];
     
    372375        RTDIRENTRYEX    DirEntry;
    373376    } 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
    377385    return dndTransferListAppendPathRecursiveSub(pList, szPathAbs, cchPathAbs, &uBuf.DirEntry, fFlags);
    378386}
     
    385393 * @param   pszPathAbs          Absolute path of directory to append.
    386394 * @param   cbPathAbs           Size (in bytes) of absolute path of directory to append.
     395 * @param   pObjInfo            Pointer to directory object info to append.
    387396 * @param   fFlags              Transfer list flags to use for appending.
    388397 */
    389398static int dndTransferListAppendDirectory(PDNDTRANSFERLIST pList, char* pszPathAbs, size_t cbPathAbs,
    390                                           DNDTRANSFERLISTFLAGS fFlags)
     399                                          PRTFSOBJINFO pObjInfo, DNDTRANSFERLISTFLAGS fFlags)
    391400{
    392401    RTDIR hDir;
    393402    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);
    398410
    399411    for (;;)
    400412    {
    401         /* Get the next directory. */
     413        /* Get the next entry. */
    402414        RTDIRENTRYEX dirEntry;
    403415        rc = RTDirReadEx(hDir, &dirEntry, NULL, RTFSOBJATTRADD_UNIX,
     
    416428
    417429            /* 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 */);
    419431
    420432            LogFlowFunc(("szName=%s, pszPathAbs=%s\n", dirEntry.szName, pszPathAbs));
     
    424436                case RTFS_TYPE_DIRECTORY:
    425437                {
    426                     rc = dndTransferListAppendPathNativeRecursive(pList, pszPathAbs, fFlags);
     438                    if (fFlags & DNDTRANSFERLIST_FLAGS_RECURSIVE)
     439                        rc = dndTransferListAppendDirectoryRecursive(pList, pszPathAbs, fFlags);
    427440                    break;
    428441                }
     
    466479
    467480    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);
    477489    AssertReturn(cchPathAbs, VERR_INVALID_PARAMETER);
    478490
    479491    /* Convert path to transport style. */
    480     rc = DnDPathConvert(szPathAbs, sizeof(szPathAbs), DNDPATHCONVERT_FLAGS_TRANSPORT);
     492    rc = DnDPathConvert(szPathAbs, cbPathAbs, DNDPATHCONVERT_FLAGS_TRANSPORT);
    481493    if (RT_SUCCESS(rc))
    482494    {
     
    488500            if (RT_SUCCESS(rc))
    489501            {
    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))
    491506                {
    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);
    504514                }
     515                else
     516                    rc = VERR_NOT_SUPPORTED;
    505517
    506518                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                }
    508539            }
    509540        }
     
    9821013static int dndTransferListRootAdd(PDNDTRANSFERLIST pList, const char *pcszRoot)
    9831014{
     1015    AssertPtrReturn(pList->pszPathRootAbs, VERR_WRONG_ORDER); /* The list's root path must be set first. */
     1016
    9841017    int rc;
    9851018
    9861019    /** @todo Handle / reject double entries. */
    9871020
    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. */
    9891022    const size_t idxPathToAdd = strlen(pList->pszPathRootAbs);
    9901023    AssertReturn(strlen(pcszRoot) > idxPathToAdd, VERR_INVALID_PARAMETER); /* Should never happen (tm). */
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