VirtualBox

Changeset 79421 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Jun 28, 2019 8:34:58 PM (6 years ago)
Author:
vboxsync
Message:

IPRT: Added a flag to RTDirCreate for ignoring the umask and added RTDirCreateFullPathEx so it can be used when creating paths. bugref:9151

Location:
trunk/src/VBox/Runtime/r3
Files:
2 edited

Legend:

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

    r78207 r79421  
    5959RTDECL(int) RTDirCreateFullPath(const char *pszPath, RTFMODE fMode)
    6060{
     61    return RTDirCreateFullPathEx(pszPath, fMode, 0);
     62}
     63
     64
     65RTDECL(int) RTDirCreateFullPathEx(const char *pszPath, RTFMODE fMode, uint32_t fFlags)
     66{
    6167    /*
    6268     * Resolve the path.
    6369     */
    64     char szAbsPath[RTPATH_MAX];
    65     int rc = RTPathAbs(pszPath, szAbsPath, sizeof(szAbsPath));
    66     if (RT_FAILURE(rc))
    67         return rc;
     70    char *pszAbsPath = RTPathAbsDup(pszPath);
     71    if (!pszAbsPath)
     72        return VERR_NO_TMP_MEMORY;
    6873
    6974    /*
     
    7176     */
    7277    /* skip volume name */
    73     char *psz = &szAbsPath[rtPathVolumeSpecLen(szAbsPath)];
     78    char *psz = &pszAbsPath[rtPathVolumeSpecLen(pszAbsPath)];
    7479
    7580    /* skip the root slash if any */
    76     if (    psz[0] == '/'
    77 #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
    78         ||  psz[0] == '\\'
    79 #endif
    80         )
     81    if (RTPATH_IS_SLASH(*psz))
    8182        psz++;
    8283
    8384    /* iterate over path components. */
     85    int rc = VINF_SUCCESS;
    8486    do
    8587    {
     
    8789        if (!*psz)
    8890            break;
    89 #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
    90         psz = strpbrk(psz, "\\/");
     91#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
     92        char *psz2 = strchr(psz, '/');
     93        psz = strchr(psz, RTPATH_SLASH);
     94        if (psz2 && (!psz || (uintptr_t)psz2 < (uintptr_t)psz))
     95            psz = psz;
    9196#else
    92         psz = strchr(psz, '/');
     97        psz = strchr(psz, RTPATH_SLASH);
    9398#endif
    9499        if (psz)
    95100            *psz = '\0';
     101
    96102        /*
    97103         * ASSUME that RTDirCreate will return VERR_ALREADY_EXISTS and not VERR_ACCESS_DENIED in those cases
    98104         * where the directory exists but we don't have write access to the parent directory.
    99105         */
    100         rc = RTDirCreate(szAbsPath, fMode, 0);
     106        rc = RTDirCreate(pszAbsPath, fMode, fFlags);
    101107        if (rc == VERR_ALREADY_EXISTS)
    102108            rc = VINF_SUCCESS;
     109
    103110        if (!psz)
    104111            break;
     
    106113    } while (RT_SUCCESS(rc));
    107114
     115    RTStrFree(pszAbsPath);
    108116    return rc;
    109117}
  • trunk/src/VBox/Runtime/r3/posix/dir-posix.cpp

    r79155 r79421  
    9191        if (RT_SUCCESS(rc))
    9292        {
     93            struct stat st;
    9394            if (mkdir(pszNativePath, fMode & RTFS_UNIX_MASK) == 0)
     95            {
     96                /* If requested, we try make use the permission bits are set
     97                   correctly when asked.  For now, we'll just ignore errors here. */
     98                if (fCreate & RTDIRCREATE_FLAGS_IGNORE_UMASK)
     99                {
     100                    if (   stat(pszNativePath, &st)
     101                        || (st.st_mode & 07777) != (fMode & 07777) )
     102                        chmod(pszNativePath, fMode & RTFS_UNIX_MASK);
     103                }
    94104                rc = VINF_SUCCESS;
     105            }
    95106            else
    96107            {
     
    109120                    rc = RTErrConvertFromErrno(rc);
    110121                    /*fVerifyIsDir = false;   We'll check if it's a dir ourselves since we're going to stat() anyway. */
    111                     struct stat st;
    112122                    if (!stat(pszNativePath, &st))
    113123                    {
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