VirtualBox

Changeset 97426 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Nov 7, 2022 7:44:16 AM (2 years ago)
Author:
vboxsync
Message:

Guest Control/Main: Resolved a @todo: Removed the escaping stuff from GuestPath::Translate() and only remove (clean up) double slashes according to the destination's path style. Also, don't force any path conversions when source path style == dest path style, as this would lose (i.e. forcefully get converted) stuff which actually would be valid ('\' in UNIX paths, for instance). ​bugref:10286

Location:
trunk/src/VBox/Main/src-client
Files:
2 edited

Legend:

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

    r97417 r97426  
    17941794        RTPathChangeToUnixSlashes(strTranslated.mutableRaw(), true /* fForce */);
    17951795    }
    1796     else if (enmDstPathStyle == PathStyle_DOS)
    1797     {
    1798         if (   enmSrcPathStyle == PathStyle_DOS
    1799             && fForce)
    1800         {
    1801             strTranslated = strPath;
    1802             RTPathChangeToDosSlashes(strTranslated.mutableRaw(), true /* fForce */);
    1803         }
    1804         else if (enmSrcPathStyle == PathStyle_UNIX)
    1805         {
    1806             /** @todo Check for quoted (sub) strings, e.g. '/foo/bar/\ baz' vs . '/foo/bar/"\ baz"'? */
    1807             const char  *psz = strPath.c_str();
    1808             size_t const cch = strPath.length();
    1809             size_t       off = 0;
    1810             while (off < cch)
    1811             {
    1812                 /* Most likely cases first. */
    1813                 if (psz[off] == '/') /* Just transform slashes. */
    1814                     strTranslated += '\\';
    1815                 /*
    1816                  * Do a mapping of "\", which marks an escape sequence for paths on UNIX-y OSes to DOS-based OSes (like Windows),
    1817                  * however, on DOS "\" is a path separator.
    1818                  *
    1819                  * See @ticketref{21095}.
    1820                  */
    1821                 /** @todo r=bird: Seeing that callers like GuestSessionTaskCopyFrom::Run() has
    1822                  * passed strPath to RTPathQueryInfoEx() prior to calling this function, I don't
    1823                  * get the comments about escape sequence stuff here.
    1824                  *
    1825                  * "\" ("\\" in C/C++) is not an escape sequence on unix unless you're in a
    1826                  * typical unix shell like bash.  It's just a filename character that doesn't
    1827                  * get interpreted as anything special by the kernel (unlike '/' and '\0' (C/C++
    1828                  * encoding)).
    1829                  *
    1830                  * "\ " (or "\\ " in C/C++) does not mark a single space in a path component, it
    1831                  * signifies two characters, a backslash and a space, neither with any special
    1832                  * meaning to a UNIX host.
    1833                  */
    1834                 else if (psz[off] == '\\')
    1835                 {
    1836                     /* "\ " is valid on UNIX-system and mark a space in a path component. */
    1837                     if (   off + 1      <= cch
    1838                         && psz[off + 1] == ' ')
    1839                     {
    1840                         strTranslated += ' ';
    1841                         off++; /* Skip actual escape sequence char (space in this case). */
    1842                     }
    1843                     else
    1844                     {
    1845                         /* Every other escape sequence is not supported and would lead to different paths anyway, so bail out here. */
    1846                         vrc = VERR_NOT_SUPPORTED;
    1847                         break;
    1848                     }
    1849                 }
    1850                 else /* Just add it unmodified. */
    1851                     strTranslated += psz[off];
    1852                 off++;
    1853             }
    1854         }
     1796    else if (  (   enmSrcPathStyle == PathStyle_UNIX
     1797                && enmDstPathStyle == PathStyle_DOS)
     1798            || (fForce && enmDstPathStyle == PathStyle_DOS))
     1799
     1800    {
     1801        strTranslated = strPath;
     1802        RTPathChangeToDosSlashes(strTranslated.mutableRaw(), true /* fForce */);
    18551803    }
    18561804
     
    18771825        if (off + 1 > cch)
    18781826            break;
    1879         /* Remove double slashes. */
    1880         if (   psz[off]     == '\\'
     1827        /* Remove double back slashes (DOS only). */
     1828        if (   enmDstPathStyle == PathStyle_DOS
     1829            && psz[off]     == '\\'
    18811830            && psz[off + 1] == '\\')
    18821831        {
     
    18841833            off++;
    18851834        }
    1886         if (   psz[off]     == '/'
     1835        /* Remove double forward slashes (UNIX only). */
     1836        if (   enmDstPathStyle == PathStyle_UNIX
     1837            && psz[off]     == '/'
    18871838            && psz[off + 1] == '/')
    18881839        {
  • trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp

    r97425 r97426  
    17261726
    17271727                /* Clean up the final guest source path (for cleaning up mixed path separators). */
    1728                 vrc = GuestPath::Translate(strSrcAbs, pList->mSourceSpec.enmPathStyle /* Source */, pList->mSourceSpec.enmPathStyle /* Dest */,
    1729                                            true /* fForce */);
     1728                vrc = GuestPath::Translate(strSrcAbs, pList->mSourceSpec.enmPathStyle /* Source */,
     1729                                           pList->mSourceSpec.enmPathStyle /* Dest */);
    17301730                if (RT_FAILURE(vrc))
    17311731                {
     
    17371737
    17381738                /* Translate the final host destination path. */
    1739                 vrc = GuestPath::Translate(strDstAbs, PATH_STYLE_NATIVE /* Source */, PATH_STYLE_NATIVE /* Dest */, true /* fForce */);
     1739                vrc = GuestPath::Translate(strDstAbs, PATH_STYLE_NATIVE /* Source */, PATH_STYLE_NATIVE /* Dest */);
    17401740                if (RT_FAILURE(vrc))
    17411741                {
     
    20452045        /* Translate the destination path to a path compatible with the guest.
    20462046         * Note: This needs to be done *before* GuestPath::BuildDestinationPath() below! */
    2047         vrc = GuestPath::Translate(strDstRootAbs,
    2048                                    mSession->i_getGuestPathStyle() /* Source */, mSession->i_getGuestPathStyle() /* Dest */,
    2049                                    true /* fForce */);
     2047        vrc = GuestPath::Translate(strDstRootAbs, mSession->i_getGuestPathStyle() /* Source */,
     2048                                   mSession->i_getGuestPathStyle() /* Dest */);
    20502049
    20512050        GuestPath::BuildDestinationPath(strSrcRootAbs, PATH_STYLE_NATIVE,
     
    21612160            /* Clean up the final guest destination root path (for cleaning up mixed path separators). */
    21622161            vrc = GuestPath::Translate(strDstRootAbs,
    2163                                        mSession->i_getGuestPathStyle() /* Source */, mSession->i_getGuestPathStyle() /* Dest */,
    2164                                        true /* fForce */);
     2162                                       mSession->i_getGuestPathStyle() /* Source */, mSession->i_getGuestPathStyle() /* Dest */);
    21652163            if (RT_FAILURE(vrc))
    21662164            {
     
    21982196
    21992197                /* Clean up the final host source path (for cleaning up mixed path separators). */
    2200                 vrc = GuestPath::Translate(strSrcAbs,
    2201                                            PATH_STYLE_NATIVE /* Source */, PATH_STYLE_NATIVE /* Dest */,
    2202                                            true /* fForce */);
     2198                vrc = GuestPath::Translate(strSrcAbs, PATH_STYLE_NATIVE /* Source */, PATH_STYLE_NATIVE /* Dest */);
    22032199                if (RT_FAILURE(vrc))
    22042200                {
     
    22112207                /* Translate the final guest destination path. */
    22122208                vrc = GuestPath::Translate(strDstAbs,
    2213                                            mSession->i_getGuestPathStyle() /* Source */, mSession->i_getGuestPathStyle() /* Dest */,
    2214                                            true /* fForce */);
     2209                                           mSession->i_getGuestPathStyle() /* Source */, mSession->i_getGuestPathStyle() /* Dest */);
    22152210                if (RT_FAILURE(vrc))
    22162211                {
     
    23022297
    23032298            /* Cleanup the destination path. */
    2304             vrc = GuestPath::Translate(strDstRootAbs, mSession->i_getGuestPathStyle() /* Source */,
    2305                                        mSession->i_getGuestPathStyle() /* Dest */, true /* fForce */);
     2299            vrc = GuestPath::Translate(strDstRootAbs,
     2300                                       mSession->i_getGuestPathStyle() /* Source */,  mSession->i_getGuestPathStyle() /* Dest */);
    23062301            if (RT_FAILURE(vrc))
    23072302            {
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