VirtualBox

Changeset 79467 in vbox


Ignore:
Timestamp:
Jul 2, 2019 3:14:30 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131729
Message:

IPRT/RTDirRemove/posix: Ignore trailing slash when statting final component to check whether to return VERR_NOT_A_DIRECTORY or VERR_PATH_NOT_FOUND. bugref:9172

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/dir-posix.cpp

    r79421 r79467  
    169169        {
    170170            rc = errno;
    171             if (rc == EEXIST) /* Solaris returns this, the rest have ENOTDIR. */
     171            if (rc == EEXIST) /* Solaris returns this, the rest have ENOTEMPTY. */
    172172                rc = VERR_DIR_NOT_EMPTY;
    173173            else if (rc != ENOTDIR)
     
    175175            else
    176176            {
    177                 rc = RTErrConvertFromErrno(rc);
     177                /*
     178                 * This may be a valid path-not-found or it may be a non-directory in
     179                 * the final component.  FsPerf want us to distinguish between the two,
     180                 * and trailing slash shouldn't matter because it doesn't on windows...
     181                 */
     182                char       *pszFree = NULL;
     183                const char *pszStat = pszNativePath;
     184                size_t      cch     = strlen(pszNativePath);
     185                if (cch > 2 && pszNativePath[cch - 1] == '/')
     186                {
     187                    pszStat = pszFree = RTMemTmpAlloc(cch);
     188                    memcpy(pszFree, pszNativePath, cch);
     189                    do
     190                        pszFree[--cch] = '\0';
     191                    while (cch > 2 && pszFree[cch - 1] == '/');
     192                }
     193
    178194                struct stat st;
    179                 if (!stat(pszNativePath, &st) && !S_ISDIR(st.st_mode))
     195                if (!stat(pszStat, &st) && !S_ISDIR(st.st_mode))
    180196                    rc = VERR_NOT_A_DIRECTORY;
     197                else
     198                    rc = VERR_PATH_NOT_FOUND;
     199
     200                if (pszFree)
     201                    RTMemTmpFree(pszFree);
    181202            }
    182203        }
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