VirtualBox

儲存庫 vbox 的更動 78186


忽略:
時間撮記:
2019-4-17 下午09:36:59 (6 年 以前)
作者:
vboxsync
訊息:

IPRT,FsPerf: Added RTDIR_F_NO_ABS_PATH and RTDIRRMREC_F_NO_ABS_PATH to help FsPerf work below PATH_MAX on linux. bugref:9172

位置:
trunk
檔案:
修改 4 筆資料

圖例:

未更動
新增
刪除
  • trunk/include/iprt/dir.h

    r76585 r78186  
    186186/** Only delete the content of the directory, omit the directory it self. */
    187187#define RTDIRRMREC_F_CONTENT_ONLY       RT_BIT_32(0)
     188/** Long path hack: Don't apply RTPathAbs to the path. */
     189#define RTDIRRMREC_F_NO_ABS_PATH        RT_BIT_32(1)
    188190/** Mask of valid flags. */
    189 #define RTDIRRMREC_F_VALID_MASK         UINT32_C(0x00000001)
     191#define RTDIRRMREC_F_VALID_MASK         UINT32_C(0x00000003)
    190192/** @} */
    191193
     
    357359/** Don't follow symbolic links in the final component. */
    358360#define RTDIR_F_NO_FOLLOW       RT_BIT_32(2)
     361/** Long path hack: Don't apply RTPathAbs to the path. */
     362#define RTDIR_F_NO_ABS_PATH     RT_BIT_32(3)
    359363/** Valid flag mask.   */
    360 #define RTDIR_F_VALID_MASK      UINT32_C(0x00000007)
     364#define RTDIR_F_VALID_MASK      UINT32_C(0x0000000f)
    361365/** @} */
    362366
  • trunk/src/VBox/Runtime/r3/dir.cpp

    r78184 r78186  
    527527     * for querying extra information about the objects we list.
    528528     * As a sideeffect we also validate the path here.
     529     *
     530     * Note! The RTDIR_F_NO_ABS_PATH mess is there purely for allowing us to
     531     *       work around PATH_MAX using CWD on linux and other unixy systems.
    529532     */
    530533    char  *pszAbsPath;
     
    542545
    543546        cbFilter = cucFilter0 = 0;
    544         pszAbsPath = RTPathAbsExDup(NULL, pszPath, RTPATHABS_F_ENSURE_TRAILING_SLASH);
     547        if (!(fFlags & RTDIR_F_NO_ABS_PATH))
     548            pszAbsPath = RTPathAbsExDup(NULL, pszPath, RTPATHABS_F_ENSURE_TRAILING_SLASH);
     549        else
     550        {
     551            size_t cchTmp = strlen(pszPath);
     552            pszAbsPath = RTStrAlloc(cchTmp + 2);
     553            if (pszAbsPath)
     554            {
     555                memcpy(pszAbsPath, pszPath, cchTmp);
     556                pszAbsPath[cchTmp] = RTPATH_SLASH;
     557                pszAbsPath[cchTmp + 1 - fDirSlash] = '\0';
     558            }
     559        }
    545560    }
    546561    else
     
    556571                return VERR_NO_MEMORY;
    557572            pszTmp[pszFilter - pszPath] = '\0';
    558             pszAbsPath = RTPathAbsExDup(NULL, pszTmp, RTPATHABS_F_ENSURE_TRAILING_SLASH);
    559             RTStrFree(pszTmp);
    560         }
     573            if (!(fFlags & RTDIR_F_NO_ABS_PATH))
     574            {
     575                pszAbsPath = RTPathAbsExDup(NULL, pszTmp, RTPATHABS_F_ENSURE_TRAILING_SLASH);
     576                RTStrFree(pszTmp);
     577            }
     578            else
     579            {
     580                pszAbsPath = pszTmp;
     581                RTPathEnsureTrailingSeparator(pszAbsPath, strlen(pszPath) + 1);
     582            }
     583        }
     584        else if (!(fFlags & RTDIR_F_NO_ABS_PATH))
     585            pszAbsPath = RTPathAbsExDup(NULL, ".", RTPATHABS_F_ENSURE_TRAILING_SLASH);
    561586        else
    562             pszAbsPath = RTPathAbsExDup(NULL, ".", RTPATHABS_F_ENSURE_TRAILING_SLASH);
     587            pszAbsPath = RTStrDup("." RTPATH_SLASH_STR);
    563588        fDirSlash = true;
    564589    }
  • trunk/src/VBox/Runtime/r3/dir2.cpp

    r78178 r78186  
    5656 * @param   pDirEntry           The dir entry buffer.  (Shared to save stack.)
    5757 * @param   pObjInfo            The object info buffer.  (ditto)
     58 * @param   fFlags              RTDIRRMREC_F_XXX.
    5859 */
    59 static int rtDirRemoveRecursiveSub(char *pszBuf, size_t cchDir, size_t cbBuf, PRTDIRENTRY pDirEntry, PRTFSOBJINFO pObjInfo)
     60static int rtDirRemoveRecursiveSub(char *pszBuf, size_t cchDir, size_t cbBuf, PRTDIRENTRY pDirEntry, PRTFSOBJINFO pObjInfo,
     61                                   uint32_t fFlags)
    6062{
    6163    AssertReturn(RTPATH_IS_SLASH(pszBuf[cchDir - 1]), VERR_INTERNAL_ERROR_4);
     
    6567     */
    6668    RTDIR hDir;
    67     int rc = RTDirOpen(&hDir, pszBuf);
     69    int rc = RTDirOpenFiltered(&hDir, pszBuf, RTDIRFILTER_NONE, fFlags & RTDIRRMREC_F_NO_ABS_PATH ? RTDIR_F_NO_ABS_PATH : 0);
    6870    if (RT_FAILURE(rc))
    6971        return rc;
     
    104106                    pszBuf[cchSubDir++] = '/';
    105107                    pszBuf[cchSubDir]   = '\0';
    106                     rc = rtDirRemoveRecursiveSub(pszBuf, cchSubDir, cbBuf, pDirEntry, pObjInfo);
     108                    rc = rtDirRemoveRecursiveSub(pszBuf, cchSubDir, cbBuf, pDirEntry, pObjInfo, fFlags);
    107109                    if (RT_SUCCESS(rc))
    108110                    {
     
    153155     * eliminates any races with changing CWD.
    154156     */
    155     /** @todo use RTPathReal here instead? */
    156     int rc = RTPathAbs(pszPath, pszAbsPath, cbAbsPathBuf);
     157    int rc;
     158    if (!(fFlags & RTDIRRMREC_F_NO_ABS_PATH))
     159        rc = RTPathAbs(pszPath, pszAbsPath, cbAbsPathBuf);
     160    else if (*pszPath != '\0')
     161        rc = RTStrCopy(pszAbsPath, cbAbsPathBuf, pszPath);
     162    else
     163        rc = VERR_PATH_ZERO_LENGTH;
    157164    if (RT_SUCCESS(rc))
    158165    {
     
    160167         * This API is not permitted applied to the root of anything.
    161168         */
    162         if (RTPathCountComponents(pszAbsPath) <= 1)
     169        union
     170        {
     171            RTPATHPARSED    Parsed;
     172            uint8_t         abParsed[RT_UOFFSETOF(RTPATHPARSED, aComps[1])];
     173        } uBuf;
     174        RTPathParse(pszPath, &uBuf.Parsed, sizeof(uBuf), RTPATH_STR_F_STYLE_HOST);
     175        if (   uBuf.Parsed.cComps <= 1
     176            && (uBuf.Parsed.fProps & RTPATH_PROP_ROOT_SLASH))
    163177            rc = VERR_ACCESS_DENIED;
    164178        else
     
    191205                     */
    192206                    RTDIRENTRY SharedDirEntryBuf;
    193                     rc = rtDirRemoveRecursiveSub(pszAbsPath, cchAbsPath, cbAbsPathBuf, &SharedDirEntryBuf, &SharedObjInfoBuf);
     207                    rc = rtDirRemoveRecursiveSub(pszAbsPath, cchAbsPath, cbAbsPathBuf,
     208                                                 &SharedDirEntryBuf, &SharedObjInfoBuf, fFlags);
    194209
    195210                    /*
  • trunk/src/VBox/ValidationKit/utils/fs/FsPerf.cpp

    r78180 r78186  
    12211221
    12221222
     1223/**
     1224 * Wrapper around RTDirOpen/RTDirOpenFiltered which takes g_fRelativeDir into
     1225 * account.
     1226 */
     1227DECL_FORCE_INLINE(int) fsPerfOpenDirWrap(PRTDIR phDir, const char *pszPath)
     1228{
     1229    if (!g_fRelativeDir)
     1230        return RTDirOpen(phDir, pszPath);
     1231    return RTDirOpenFiltered(phDir, pszPath, RTDIRFILTER_NONE, RTDIR_F_NO_ABS_PATH);
     1232}
     1233
     1234
    12231235DECL_FORCE_INLINE(int) fsPerfOpenClose(const char *pszDir)
    12241236{
    12251237    RTDIR hDir;
    1226     RTTESTI_CHECK_RC_RET(RTDirOpen(&hDir, pszDir), VINF_SUCCESS, rcCheck);
     1238    RTTESTI_CHECK_RC_RET(fsPerfOpenDirWrap(&hDir, pszDir), VINF_SUCCESS, rcCheck);
    12271239    RTTESTI_CHECK_RC(RTDirClose(hDir), VINF_SUCCESS);
    12281240    return VINF_SUCCESS;
     
    12381250     * Non-existing files.
    12391251     */
    1240     RTTESTI_CHECK_RC(RTDirOpen(&hDir, InEmptyDir(RT_STR_TUPLE("no-such-file"))), VERR_FILE_NOT_FOUND);
    1241     RTTESTI_CHECK_RC(RTDirOpen(&hDir, InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file"))), FSPERF_VERR_PATH_NOT_FOUND);
    1242     RTTESTI_CHECK_RC(RTDirOpen(&hDir, InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file"))), VERR_PATH_NOT_FOUND);
     1252    RTTESTI_CHECK_RC(fsPerfOpenDirWrap(&hDir, InEmptyDir(RT_STR_TUPLE("no-such-file"))), VERR_FILE_NOT_FOUND);
     1253    RTTESTI_CHECK_RC(fsPerfOpenDirWrap(&hDir, InEmptyDir(RT_STR_TUPLE("no-such-dir" RTPATH_SLASH_STR "no-such-file"))), FSPERF_VERR_PATH_NOT_FOUND);
     1254    RTTESTI_CHECK_RC(fsPerfOpenDirWrap(&hDir, InDir(RT_STR_TUPLE("known-file" RTPATH_SLASH_STR "no-such-file"))), VERR_PATH_NOT_FOUND);
    12431255
    12441256    /*
     
    12461258     */
    12471259    g_szEmptyDir[g_cchEmptyDir] = '\0';
    1248     RTTESTI_CHECK_RC_RETV(RTDirOpen(&hDir, g_szEmptyDir), VINF_SUCCESS);
     1260    RTTESTI_CHECK_RC_RETV(fsPerfOpenDirWrap(&hDir, g_szEmptyDir), VINF_SUCCESS);
    12491261    RTTESTI_CHECK_RC(RTDirClose(hDir), VINF_SUCCESS);
    12501262
     
    12671279    RTDIR hDir;
    12681280    g_szEmptyDir[g_cchEmptyDir] = '\0';
    1269     RTTESTI_CHECK_RC_RET(RTDirOpen(&hDir, g_szEmptyDir), VINF_SUCCESS, rcCheck);
     1281    RTTESTI_CHECK_RC_RET(fsPerfOpenDirWrap(&hDir, g_szEmptyDir), VINF_SUCCESS, rcCheck);
    12701282
    12711283    RTDIRENTRY Entry;
     
    12821294{
    12831295    RTDIR hDir;
    1284     RTTESTI_CHECK_RC_RET(RTDirOpen(&hDir, InDir(RT_STR_TUPLE("manyfiles"))), VINF_SUCCESS, rcCheck);
     1296    RTTESTI_CHECK_RC_RET(fsPerfOpenDirWrap(&hDir, InDir(RT_STR_TUPLE("manyfiles"))), VINF_SUCCESS, rcCheck);
    12851297    uint32_t cLeft = g_cManyFiles + 2;
    12861298    for (;;)
     
    13101322     */
    13111323    g_szEmptyDir[g_cchEmptyDir] = '\0';
    1312     RTTESTI_CHECK_RC_RETV(RTDirOpen(&hDir, g_szEmptyDir), VINF_SUCCESS);
     1324    RTTESTI_CHECK_RC_RETV(fsPerfOpenDirWrap(&hDir, g_szEmptyDir), VINF_SUCCESS);
    13131325
    13141326    uint32_t   fDots = 0;
     
    13401352
    13411353        uint32_t cFiles = 0;
    1342         RTTESTI_CHECK_RC_RETV(RTDirOpen(&hDir, InDir(RT_STR_TUPLE("manyfiles"))), VINF_SUCCESS);
     1354        RTTESTI_CHECK_RC_RETV(fsPerfOpenDirWrap(&hDir, InDir(RT_STR_TUPLE("manyfiles"))), VINF_SUCCESS);
    13431355        for (;;)
    13441356        {
     
    46894701            /* Cleanup: */
    46904702            g_szDir[g_cchDir] = '\0';
    4691             rc = RTDirRemoveRecursive(g_szDir, RTDIRRMREC_F_CONTENT_AND_DIR);
     4703            rc = RTDirRemoveRecursive(g_szDir, RTDIRRMREC_F_CONTENT_AND_DIR | (g_fRelativeDir ? RTDIRRMREC_F_NO_ABS_PATH : 0));
    46924704            if (RT_FAILURE(rc))
    46934705                RTTestFailed(g_hTest, "RTDirRemoveRecursive(%s,) -> %Rrc\n", g_szDir, rc);
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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