VirtualBox

Changeset 23291 in vbox for trunk/src/VBox/Runtime/r3/posix


Ignore:
Timestamp:
Sep 24, 2009 4:08:19 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
52784
Message:

IPRT: RTPathQueryInfo and RTPathSetTimes should work on symbolic links when specified. Introduced Ex versions of these to work around this issue. Should also address the lack of symlinks in the RTDirReadEx output as well VWRN_NO_DIRENT_INFO on broken links.

File:
1 edited

Legend:

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

    r20819 r23291  
    463463RTR3DECL(int) RTPathQueryInfo(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs)
    464464{
     465    return RTPathQueryInfoEx(pszPath, pObjInfo, enmAdditionalAttribs, RTPATH_F_ON_LINK);
     466}
     467
     468
     469RTR3DECL(int) RTPathQueryInfoEx(const char *pszPath, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags)
     470{
    465471    /*
    466472     * Validate input.
    467473     */
    468     AssertMsgReturn(VALID_PTR(pszPath), ("%p\n", pszPath), VERR_INVALID_POINTER);
     474    AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
    469475    AssertReturn(*pszPath, VERR_INVALID_PARAMETER);
    470     AssertMsgReturn(VALID_PTR(pObjInfo), ("%p\n", pszPath), VERR_INVALID_POINTER);
     476    AssertPtrReturn(pObjInfo, VERR_INVALID_POINTER);
    471477    AssertMsgReturn(    enmAdditionalAttribs >= RTFSOBJATTRADD_NOTHING
    472478                    &&  enmAdditionalAttribs <= RTFSOBJATTRADD_LAST,
    473479                    ("Invalid enmAdditionalAttribs=%p\n", enmAdditionalAttribs),
    474480                    VERR_INVALID_PARAMETER);
     481    AssertMsgReturn(RTPATH_F_IS_VALID(fFlags, 0), ("%#x\n", fFlags), VERR_INVALID_PARAMETER);
    475482
    476483    /*
     
    482489    {
    483490        struct stat Stat;
    484         if (!stat(pszNativePath, &Stat))
     491        if (fFlags & RTPATH_F_FOLLOW_LINK)
     492            rc = stat(pszNativePath, &Stat);
     493        else
     494            rc = lstat(pszNativePath, &Stat); /** @todo how doesn't have lstat again? */
     495        if (!rc)
    485496        {
    486497            rtFsConvertStatToObjInfo(pObjInfo, &Stat, pszPath, 0);
     
    517528                             PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime)
    518529{
     530    return RTPathSetTimesEx(pszPath, pAccessTime, pModificationTime, pChangeTime, pBirthTime, RTPATH_F_ON_LINK);
     531}
     532
     533
     534RTR3DECL(int) RTPathSetTimesEx(const char *pszPath, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
     535                               PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime, uint32_t fFlags)
     536{
    519537    /*
    520538     * Validate input.
    521539     */
    522     AssertMsgReturn(VALID_PTR(pszPath), ("%p\n", pszPath), VERR_INVALID_POINTER);
    523     AssertMsgReturn(*pszPath, ("%p\n", pszPath), VERR_INVALID_PARAMETER);
    524     AssertMsgReturn(!pAccessTime || VALID_PTR(pAccessTime), ("%p\n", pAccessTime), VERR_INVALID_POINTER);
    525     AssertMsgReturn(!pModificationTime || VALID_PTR(pModificationTime), ("%p\n", pModificationTime), VERR_INVALID_POINTER);
    526     AssertMsgReturn(!pChangeTime || VALID_PTR(pChangeTime), ("%p\n", pChangeTime), VERR_INVALID_POINTER);
    527     AssertMsgReturn(!pBirthTime || VALID_PTR(pBirthTime), ("%p\n", pBirthTime), VERR_INVALID_POINTER);
     540    AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
     541    AssertReturn(*pszPath, VERR_INVALID_PARAMETER);
     542    AssertPtrNullReturn(pAccessTime, VERR_INVALID_POINTER);
     543    AssertPtrNullReturn(pModificationTime, VERR_INVALID_POINTER);
     544    AssertPtrNullReturn(pChangeTime, VERR_INVALID_POINTER);
     545    AssertPtrNullReturn(pBirthTime, VERR_INVALID_POINTER);
     546    AssertMsgReturn(RTPATH_F_IS_VALID(fFlags, 0), ("%#x\n", fFlags), VERR_INVALID_PARAMETER);
    528547
    529548    /*
     
    534553    if (RT_SUCCESS(rc))
    535554    {
     555        RTFSOBJINFO ObjInfo;
     556
    536557        /*
    537558         * If it's a no-op, we'll only verify the existance of the file.
    538559         */
    539560        if (!pAccessTime && !pModificationTime)
    540         {
    541             struct stat Stat;
    542             if (!stat(pszNativePath, &Stat))
    543                 rc = VINF_SUCCESS;
    544             else
    545             {
    546                 rc = RTErrConvertFromErrno(errno);
    547                 Log(("RTPathSetTimes('%s',,,,): failed with %Rrc and errno=%d\n", pszPath, rc, errno));
    548             }
    549         }
     561            rc = RTPathQueryInfoEx(pszPath, &ObjInfo, RTFSOBJATTRADD_NOTHING, fFlags);
    550562        else
    551563        {
     
    562574            else
    563575            {
    564                 RTFSOBJINFO ObjInfo;
    565                 int rc = RTPathQueryInfo(pszPath, &ObjInfo, RTFSOBJATTRADD_UNIX);
     576                rc = RTPathQueryInfoEx(pszPath, &ObjInfo, RTFSOBJATTRADD_UNIX, fFlags);
    566577                if (RT_SUCCESS(rc))
    567578                {
     
    575586            if (RT_SUCCESS(rc))
    576587            {
    577                 if (utimes(pszNativePath, aTimevals))
     588                if (fFlags & RTPATH_F_FOLLOW_LINK)
    578589                {
    579                     rc = RTErrConvertFromErrno(errno);
     590                    if (utimes(pszNativePath, aTimevals))
     591                        rc = RTErrConvertFromErrno(errno);
     592                }
     593#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) /** @todo who really has lutimes? */
     594                else
     595                {
     596                    if (lutimes(pszNativePath, aTimevals))
     597                        rc = RTErrConvertFromErrno(errno);
     598                }
     599#else
     600                else
     601                {
     602                    if (pAccessTime && pModificationTime)
     603                        rc = RTPathQueryInfoEx(pszPath, &ObjInfo, RTFSOBJATTRADD_UNIX, fFlags);
     604                    if (RT_SUCCESS(rc) && RTFS_IS_SYMLINK(ObjInfo.Attr.fMode))
     605                        rc = VERR_NS_SYMLINK_SET_TIME;
     606                    else if (RT_SUCCESS(rc))
     607                    {
     608                        if (utimes(pszNativePath, aTimevals))
     609                            rc = RTErrConvertFromErrno(errno);
     610                    }
     611                }
     612#endif
     613                if (RT_FAILURE(rc))
    580614                    Log(("RTPathSetTimes('%s',%p,%p,,): failed with %Rrc and errno=%d\n",
    581615                         pszPath, pAccessTime, pModificationTime, rc, errno));
    582                 }
    583616            }
    584617        }
     
    788821RTDECL(bool) RTPathExists(const char *pszPath)
    789822{
     823    return RTPathExistsEx(pszPath, RTPATH_F_FOLLOW_LINK);
     824}
     825
     826
     827RTDECL(bool) RTPathExistsEx(const char *pszPath, uint32_t fFlags)
     828{
    790829    /*
    791830     * Validate input.
     
    793832    AssertPtrReturn(pszPath, false);
    794833    AssertReturn(*pszPath, false);
     834    Assert(RTPATH_F_IS_VALID(fFlags, 0));
    795835
    796836    /*
     
    802842    {
    803843        struct stat Stat;
    804         if (!stat(pszNativePath, &Stat))
     844        if (fFlags & RTPATH_F_FOLLOW_LINK)
     845            rc = stat(pszNativePath, &Stat);
     846        else
     847            rc = lstat(pszNativePath, &Stat);
     848        if (!rc)
    805849            rc = VINF_SUCCESS;
    806850        else
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