VirtualBox

Changeset 97553 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Nov 15, 2022 4:29:49 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
154584
Message:

Guest Control/Main: Some more fixes wrt resolving host sources which are symbolic links. bugref:10286

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp

    r97541 r97553  
    16141614        if (strErrorInfo.isEmpty())
    16151615            strErrorInfo.printf(tr("Failed with %Rrc"), vrc);
    1616         hrc = setProgressErrorMsg(VBOX_E_IPRT_ERROR, strErrorInfo);
     1616        setProgressErrorMsg(VBOX_E_IPRT_ERROR, strErrorInfo);
    16171617    }
    16181618
     
    19731973
    19741974            RTFSOBJINFO srcFsObjInfo;
    1975             vrc = RTPathQueryInfoEx(strSrc.c_str(), &srcFsObjInfo, RTFSOBJATTRADD_NOTHING,
    1976                                     fFollowSymlinks ? RTPATH_F_FOLLOW_LINK : RTPATH_F_ON_LINK /* fFlags */);
     1975            vrc = RTPathQueryInfoEx(strSrc.c_str(), &srcFsObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK /* fFlags */);
    19771976            if (RT_FAILURE(vrc))
    19781977            {
     
    19811980            }
    19821981
    1983             if (RTFS_IS_DIRECTORY(srcFsObjInfo.Attr.fMode))
    1984             {
    1985                 if (itSrc->enmType != FsObjType_Directory)
    1986                 {
    1987                     strErrorInfo.printf(tr("Host source is not a file: %s"), strSrc.c_str());
    1988                     vrc = VERR_NOT_A_FILE;
     1982            switch (srcFsObjInfo.Attr.fMode & RTFS_TYPE_MASK)
     1983            {
     1984                case RTFS_TYPE_DIRECTORY:
     1985                {
     1986                    if (itSrc->enmType != FsObjType_Directory)
     1987                    {
     1988                        strErrorInfo.printf(tr("Host source \"%s\" is not a file (is a directory)"), strSrc.c_str());
     1989                        vrc = VERR_NOT_A_FILE;
     1990                    }
    19891991                    break;
    19901992                }
    1991             }
    1992             else
    1993             {
    1994                 if (itSrc->enmType == FsObjType_Directory)
    1995                 {
    1996                     strErrorInfo.printf(tr("Host source is not a directory: %s"), strSrc.c_str());
    1997                     vrc = VERR_NOT_A_DIRECTORY;
     1993
     1994                case RTFS_TYPE_FILE:
     1995                {
     1996                    if (itSrc->enmType == FsObjType_Directory)
     1997                    {
     1998                        strErrorInfo.printf(tr("Host source \"%s\" is not a directory (is a file)"), strSrc.c_str());
     1999                        vrc = VERR_NOT_A_DIRECTORY;
     2000                    }
    19982001                    break;
    19992002                }
    2000             }
     2003
     2004                case RTFS_TYPE_SYMLINK:
     2005                {
     2006                    if (!fFollowSymlinks)
     2007                    {
     2008                        strErrorInfo.printf(tr("Host source \"%s\" is a symbolic link"), strSrc.c_str());
     2009                        vrc = VERR_IS_A_SYMLINK;
     2010                        break;
     2011                    }
     2012
     2013                    char szPathReal[RTPATH_MAX];
     2014                    vrc = RTPathReal(strSrc.c_str(), szPathReal, sizeof(szPathReal));
     2015                    if (RT_SUCCESS(vrc))
     2016                    {
     2017                        vrc = RTPathQueryInfoEx(szPathReal, &srcFsObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_FOLLOW_LINK);
     2018                        if (RT_SUCCESS(vrc))
     2019                        {
     2020                            LogRel2(("Guest Control: Host source symbolic link '%s' -> '%s' (%s)\n",
     2021                                     strSrc.c_str(), szPathReal,
     2022                                     GuestBase::fsObjTypeToStr(GuestBase::fileModeToFsObjType(srcFsObjInfo.Attr.fMode))));
     2023
     2024                            /* We want to keep the symbolic link name of the source instead of the target pointing to,
     2025                             * so don't touch the source's name here. */
     2026                            itSrc->enmType = GuestBase::fileModeToFsObjType(srcFsObjInfo.Attr.fMode);
     2027                        }
     2028                        else
     2029                        {
     2030                            strErrorInfo.printf(tr("Querying symbolic link info for host source \"%s\" failed"), strSrc.c_str());
     2031                            break;
     2032                        }
     2033                    }
     2034                    else
     2035                    {
     2036                        strErrorInfo.printf(tr("Resolving symbolic link for host source \"%s\" failed"), strSrc.c_str());
     2037                        break;
     2038                    }
     2039                    break;
     2040                }
     2041
     2042                default:
     2043                    LogRel2(("Guest Control: Warning: Unknown host file system type %#x for source \"%s\", skipping\n",
     2044                             srcFsObjInfo.Attr.fMode & RTFS_TYPE_MASK, strSrc.c_str()));
     2045                    break;
     2046            }
     2047
     2048            if (RT_FAILURE(vrc))
     2049                break;
    20012050
    20022051            FsList *pFsList = NULL;
     
    20222071                            break;
    20232072
     2073                        case FsObjType_Symlink:
     2074                            AssertFailed(); /* Should never get here, as we do the resolving above. */
     2075                            break;
     2076
    20242077                        default:
    2025                             LogRel2(("Guest Control: Warning: Unknown guest host system type %#x for source \"%s\", skipping\n",
     2078                            LogRel2(("Guest Control: Warning: Unknown source type %#x for host source \"%s\", skipping\n",
    20262079                                     itSrc->enmType, strSrc.c_str()));
    20272080                            break;
     
    20862139        if (strErrorInfo.isEmpty())
    20872140            strErrorInfo.printf(tr("Failed with %Rrc"), vrc);
    2088         hrc = setProgressErrorMsg(VBOX_E_IPRT_ERROR, strErrorInfo);
     2141        setProgressErrorMsg(VBOX_E_IPRT_ERROR, strErrorInfo);
    20892142    }
    20902143
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