VirtualBox

Changeset 97304 in vbox for trunk/src


Ignore:
Timestamp:
Oct 26, 2022 2:28:53 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
154295
Message:

Main/Guest Control: Added a force parameter to GuestPath::Translate() and made a little more flexible wrt same-same conversions. Adjusted testcase. ​bugref:10286

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h

    r97303 r97304  
    14051405    /** @name Static helper functions.
    14061406     * @{ */
    1407     static int Translate(Utf8Str &strPath, PathStyle_T enmSrcPathStyle, PathStyle_T enmDstPathStyle);
     1407    static int Translate(Utf8Str &strPath, PathStyle_T enmSrcPathStyle, PathStyle_T enmDstPathStyle, bool fForce = false);
    14081408    /** @}  */
    14091409};
  • trunk/src/VBox/Main/src-client/GuestCtrlPrivate.cpp

    r97303 r97304  
    16981698 * @param   enmSrcPathStyle     Source path style \a strPath is expected in.
    16991699 * @param   enmDstPathStyle     Destination path style to convert to.
     1700 * @param   fForce              Whether to force the translation to the destination path style or not.
    17001701 *
    17011702 * @note    This does NOT remove any trailing slashes and/or perform file system lookups!
    17021703 */
    17031704/* static */
    1704 int GuestPath::Translate(Utf8Str &strPath, PathStyle_T enmSrcPathStyle, PathStyle_T enmDstPathStyle)
     1705int GuestPath::Translate(Utf8Str &strPath, PathStyle_T enmSrcPathStyle, PathStyle_T enmDstPathStyle, bool fForce /* = false */)
    17051706{
    17061707    if (strPath.isEmpty())
     
    17171718    Utf8Str strTranslated;
    17181719
    1719     if (   enmSrcPathStyle == PathStyle_DOS
    1720         && enmDstPathStyle == PathStyle_UNIX)
     1720    if (   (   enmSrcPathStyle == PathStyle_DOS
     1721            && enmDstPathStyle == PathStyle_UNIX)
     1722        || (fForce && enmDstPathStyle == PathStyle_UNIX))
    17211723    {
    17221724        strTranslated = RTPathChangeToUnixSlashes(strPath.mutableRaw(), true /* fForce */);
    17231725    }
    1724     else if (   enmSrcPathStyle == PathStyle_UNIX
    1725              && enmDstPathStyle == PathStyle_DOS)
    1726     {
    1727         /** @todo Check for quoted (sub) strings, e.g. '/foo/bar/\ baz' vs . '/foo/bar/"\ baz"'? */
    1728 
    1729         const char  *psz = strPath.c_str();
    1730         size_t const cch = strPath.length();
    1731         size_t       off = 0;
    1732         while (off < cch)
    1733         {
    1734             /* Most likely cases first. */
    1735             if (psz[off] == '/') /* Just transform slashes. */
    1736                 strTranslated += '\\';
    1737             /*
    1738              * Do a mapping of "\", which marks an escape sequence for paths on UNIX-y OSes to DOS-based OSes (like Windows),
    1739              * however, on DOS "\" is a path separator.
    1740              *
    1741              * See @bugref{21095}.
    1742              */
    1743             else if (psz[off] == '\\')
     1726    else if (enmDstPathStyle == PathStyle_DOS)
     1727    {
     1728        if (   enmSrcPathStyle == PathStyle_DOS
     1729            && fForce)
     1730        {
     1731            strTranslated = RTPathChangeToDosSlashes(strPath.mutableRaw(), true /* fForce */);
     1732        }
     1733        else if (enmSrcPathStyle == PathStyle_UNIX)
     1734        {
     1735            /** @todo Check for quoted (sub) strings, e.g. '/foo/bar/\ baz' vs . '/foo/bar/"\ baz"'? */
     1736            const char  *psz = strPath.c_str();
     1737            size_t const cch = strPath.length();
     1738            size_t       off = 0;
     1739            while (off < cch)
    17441740            {
    1745                 /* "\ " is valid on UNIX-system and mark a space in a path component. */
    1746                 if (   off + 1      <= cch
    1747                     && psz[off + 1] == ' ')
     1741                /* Most likely cases first. */
     1742                if (psz[off] == '/') /* Just transform slashes. */
     1743                    strTranslated += '\\';
     1744                /*
     1745                 * Do a mapping of "\", which marks an escape sequence for paths on UNIX-y OSes to DOS-based OSes (like Windows),
     1746                 * however, on DOS "\" is a path separator.
     1747                 *
     1748                 * See @bugref{21095}.
     1749                 */
     1750                else if (psz[off] == '\\')
    17481751                {
    1749                     strTranslated += ' ';
    1750                     off++; /* Skip actual escape sequence char (space in this case). */
     1752                    /* "\ " is valid on UNIX-system and mark a space in a path component. */
     1753                    if (   off + 1      <= cch
     1754                        && psz[off + 1] == ' ')
     1755                    {
     1756                        strTranslated += ' ';
     1757                        off++; /* Skip actual escape sequence char (space in this case). */
     1758                    }
     1759                    else
     1760                    {
     1761                        /* Every other escape sequence is not supported and would lead to different paths anyway, so bail out here. */
     1762                        vrc = VERR_NOT_SUPPORTED;
     1763                        break;
     1764                    }
    17511765                }
    1752                 else
    1753                 {
    1754                     /* Every other escape sequence is not supported and would lead to different paths anyway, so bail out here. */
    1755                     vrc = VERR_NOT_SUPPORTED;
    1756                     break;
    1757                 }
     1766                else /* Just add it unmodified. */
     1767                    strTranslated += psz[off];
     1768                off++;
    17581769            }
    1759             else /* Just add it unmodified. */
    1760                 strTranslated += psz[off];
    1761             off++;
    1762         }
    1763     }
    1764     else if (enmSrcPathStyle == enmDstPathStyle)
     1770        }
     1771    }
     1772
     1773    if (   strTranslated.isEmpty() /* Not forced. */
     1774        && enmSrcPathStyle == enmDstPathStyle)
    17651775    {
    17661776        strTranslated = strPath;
    17671777    }
    1768     else
    1769         AssertFailedReturn(VERR_NOT_IMPLEMENTED);
    17701778
    17711779    if (RT_FAILURE(vrc))
  • trunk/src/VBox/Main/testcase/tstGuestCtrlPaths.cpp

    r97276 r97304  
    8989    tstPathTranslate("foo/bar/dir with space/",    PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "foo/bar/dir with space/");
    9090
    91     tstPathTranslate("foo/bar/dir_with_escape_sequence\\ space", PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "foo/bar/dir_with_escape_sequence\\ space");
    9291    /** Do a mapping of "\", which marks an escape sequence for paths on UNIX-y OSes to DOS-based OSes (like Windows),
    9392      * however, on DOS "\" is a path separator.  See @bugref{21095} */
    94     tstPathTranslate("foo/bar/dir_with_escape_sequence/the\\ space", PathStyle_UNIX,    PathStyle_DOS,  VINF_SUCCESS, "foo\\bar\\dir_with_escape_sequence\\the space");
    95     tstPathTranslate("foo/bar/dir_with_escape_sequence/the\\ \\ space", PathStyle_UNIX, PathStyle_DOS,  VINF_SUCCESS, "foo\\bar\\dir_with_escape_sequence\\the  space");
     93    tstPathTranslate("foo/bar/dir_with_escape_sequence\\ space", PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "foo/bar/dir_with_escape_sequence\\ space");
     94    tstPathTranslate("foo/bar/dir_with_escape_sequence\\ space", PathStyle_UNIX, PathStyle_DOS, VINF_SUCCESS, "foo\\bar\\dir_with_escape_sequence space");
     95    tstPathTranslate("foo/bar/1_dir_with_escape_sequence/the\\ space", PathStyle_UNIX,    PathStyle_DOS,  VINF_SUCCESS, "foo\\bar\\1_dir_with_escape_sequence\\the space");
     96    tstPathTranslate("foo/bar/2_dir_with_escape_sequence/the\\ \\ space", PathStyle_UNIX, PathStyle_DOS,  VINF_SUCCESS, "foo\\bar\\2_dir_with_escape_sequence\\the  space");
    9697    tstPathTranslate("foo/bar/dir_with_escape_sequence/spaces at end\\  \\ ", PathStyle_UNIX, PathStyle_DOS,  VINF_SUCCESS, "foo\\bar\\dir_with_escape_sequence\\spaces at end   ");
    9798
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