- Timestamp:
- Oct 26, 2022 2:28:53 PM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 154295
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h
r97303 r97304 1405 1405 /** @name Static helper functions. 1406 1406 * @{ */ 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); 1408 1408 /** @} */ 1409 1409 }; -
trunk/src/VBox/Main/src-client/GuestCtrlPrivate.cpp
r97303 r97304 1698 1698 * @param enmSrcPathStyle Source path style \a strPath is expected in. 1699 1699 * @param enmDstPathStyle Destination path style to convert to. 1700 * @param fForce Whether to force the translation to the destination path style or not. 1700 1701 * 1701 1702 * @note This does NOT remove any trailing slashes and/or perform file system lookups! 1702 1703 */ 1703 1704 /* static */ 1704 int GuestPath::Translate(Utf8Str &strPath, PathStyle_T enmSrcPathStyle, PathStyle_T enmDstPathStyle )1705 int GuestPath::Translate(Utf8Str &strPath, PathStyle_T enmSrcPathStyle, PathStyle_T enmDstPathStyle, bool fForce /* = false */) 1705 1706 { 1706 1707 if (strPath.isEmpty()) … … 1717 1718 Utf8Str strTranslated; 1718 1719 1719 if ( enmSrcPathStyle == PathStyle_DOS 1720 && enmDstPathStyle == PathStyle_UNIX) 1720 if ( ( enmSrcPathStyle == PathStyle_DOS 1721 && enmDstPathStyle == PathStyle_UNIX) 1722 || (fForce && enmDstPathStyle == PathStyle_UNIX)) 1721 1723 { 1722 1724 strTranslated = RTPathChangeToUnixSlashes(strPath.mutableRaw(), true /* fForce */); 1723 1725 } 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) 1744 1740 { 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] == '\\') 1748 1751 { 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 } 1751 1765 } 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++; 1758 1769 } 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) 1765 1775 { 1766 1776 strTranslated = strPath; 1767 1777 } 1768 else1769 AssertFailedReturn(VERR_NOT_IMPLEMENTED);1770 1778 1771 1779 if (RT_FAILURE(vrc)) -
trunk/src/VBox/Main/testcase/tstGuestCtrlPaths.cpp
r97276 r97304 89 89 tstPathTranslate("foo/bar/dir with space/", PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "foo/bar/dir with space/"); 90 90 91 tstPathTranslate("foo/bar/dir_with_escape_sequence\\ space", PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "foo/bar/dir_with_escape_sequence\\ space");92 91 /** Do a mapping of "\", which marks an escape sequence for paths on UNIX-y OSes to DOS-based OSes (like Windows), 93 92 * 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"); 96 97 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 "); 97 98
Note:
See TracChangeset
for help on using the changeset viewer.