diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2022-06-03 17:48:39 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2022-06-07 19:44:36 -0500 |
| commit | 6b0f2d978504da82070523eb6adb0b59f9812e93 (patch) | |
| tree | 6f0b258519a0f51bf589e4313206b3ffeaa32a41 /src/libs/dutil/WixToolset.DUtil/path2utl.cpp | |
| parent | b652e93a460b4b822a01382e5992f96f1d805ffe (diff) | |
| download | wix-6b0f2d978504da82070523eb6adb0b59f9812e93.tar.gz wix-6b0f2d978504da82070523eb6adb0b59f9812e93.tar.bz2 wix-6b0f2d978504da82070523eb6adb0b59f9812e93.zip | |
Add PathSkipPastRoot.
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/path2utl.cpp')
| -rw-r--r-- | src/libs/dutil/WixToolset.DUtil/path2utl.cpp | 53 |
1 files changed, 18 insertions, 35 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/path2utl.cpp b/src/libs/dutil/WixToolset.DUtil/path2utl.cpp index 1957a8c5..9e48f9d5 100644 --- a/src/libs/dutil/WixToolset.DUtil/path2utl.cpp +++ b/src/libs/dutil/WixToolset.DUtil/path2utl.cpp | |||
| @@ -64,31 +64,12 @@ DAPI_(HRESULT) PathCanonicalizeForComparison( | |||
| 64 | 64 | ||
| 65 | if (PATH_CANONICALIZE_KEEP_UNC_ROOT & dwCanonicalizeFlags) | 65 | if (PATH_CANONICALIZE_KEEP_UNC_ROOT & dwCanonicalizeFlags) |
| 66 | { | 66 | { |
| 67 | if (L'\\' == sczNormalizedPath[0] && (L'\\' == sczNormalizedPath[1] || L'?' == sczNormalizedPath[1]) && L'?' == sczNormalizedPath[2] && L'\\' == sczNormalizedPath[3]) | 67 | BOOL fUNC = FALSE; |
| 68 | LPCWSTR wzPastRoot = PathSkipPastRoot(sczNormalizedPath, NULL, NULL, &fUNC); | ||
| 69 | if (fUNC) | ||
| 68 | { | 70 | { |
| 69 | if (L'U' == sczNormalizedPath[4] && L'N' == sczNormalizedPath[5] && L'C' == sczNormalizedPath[6] && L'\\' == sczNormalizedPath[7]) | 71 | wzNormalizedPath = wzPastRoot; |
| 70 | { | 72 | cchUncRootLength = wzPastRoot - sczNormalizedPath; |
| 71 | cchUncRootLength = 8; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | else if (L'\\' == sczNormalizedPath[0] && L'\\' == sczNormalizedPath[1]) | ||
| 75 | { | ||
| 76 | cchUncRootLength = 2; | ||
| 77 | } | ||
| 78 | |||
| 79 | if (cchUncRootLength) | ||
| 80 | { | ||
| 81 | DWORD dwRemainingSlashes = 2; | ||
| 82 | |||
| 83 | for (wzNormalizedPath += cchUncRootLength; *wzNormalizedPath && dwRemainingSlashes; ++wzNormalizedPath) | ||
| 84 | { | ||
| 85 | ++cchUncRootLength; | ||
| 86 | |||
| 87 | if (L'\\' == *wzNormalizedPath) | ||
| 88 | { | ||
| 89 | --dwRemainingSlashes; | ||
| 90 | } | ||
| 91 | } | ||
| 92 | } | 73 | } |
| 93 | } | 74 | } |
| 94 | 75 | ||
| @@ -115,22 +96,24 @@ DAPI_(HRESULT) PathCanonicalizeForComparison( | |||
| 115 | if (PATH_CANONICALIZE_BACKSLASH_TERMINATE & dwCanonicalizeFlags) | 96 | if (PATH_CANONICALIZE_BACKSLASH_TERMINATE & dwCanonicalizeFlags) |
| 116 | { | 97 | { |
| 117 | hr = PathBackslashTerminate(psczCanonicalized); | 98 | hr = PathBackslashTerminate(psczCanonicalized); |
| 118 | PathExitOnFailure(hr, "Failed to backslash terminate the canonicalized path"); | 99 | PathExitOnFailure(hr, "Failed to backslash terminate the canonicalized path."); |
| 119 | } | 100 | } |
| 120 | 101 | ||
| 121 | if (PathIsFullyQualified(*psczCanonicalized, &fHasPrefix) && !fHasPrefix && | 102 | if (PATH_CANONICALIZE_APPEND_EXTENDED_PATH_PREFIX & dwCanonicalizeFlags) |
| 122 | (PATH_CANONICALIZE_APPEND_LONG_PATH_PREFIX & dwCanonicalizeFlags)) | ||
| 123 | { | 103 | { |
| 124 | hr = PathPrefix(psczCanonicalized); | 104 | hr = PathPrefix(psczCanonicalized, 0, PATH_PREFIX_SHORT_PATHS); |
| 125 | PathExitOnFailure(hr, "Failed to ensure the long path prefix on the canonicalized path"); | 105 | PathExitOnFailure(hr, "Failed to ensure the extended path prefix on the canonicalized path."); |
| 126 | |||
| 127 | fHasPrefix = TRUE; | ||
| 128 | } | 106 | } |
| 129 | 107 | ||
| 108 | PathSkipPastRoot(*psczCanonicalized, &fHasPrefix, NULL, NULL); | ||
| 109 | |||
| 130 | if (fHasPrefix) | 110 | if (fHasPrefix) |
| 131 | { | 111 | { |
| 132 | // Canonicalize \??\ into \\?\. | 112 | // Canonicalize prefix into \\?\. |
| 113 | (*psczCanonicalized)[0] = L'\\'; | ||
| 133 | (*psczCanonicalized)[1] = L'\\'; | 114 | (*psczCanonicalized)[1] = L'\\'; |
| 115 | (*psczCanonicalized)[2] = L'?'; | ||
| 116 | (*psczCanonicalized)[3] = L'\\'; | ||
| 134 | } | 117 | } |
| 135 | 118 | ||
| 136 | LExit: | 119 | LExit: |
| @@ -188,7 +171,7 @@ DAPI_(HRESULT) PathCompareCanonicalized( | |||
| 188 | HRESULT hr = S_OK; | 171 | HRESULT hr = S_OK; |
| 189 | LPWSTR sczCanonicalized1 = NULL; | 172 | LPWSTR sczCanonicalized1 = NULL; |
| 190 | LPWSTR sczCanonicalized2 = NULL; | 173 | LPWSTR sczCanonicalized2 = NULL; |
| 191 | DWORD dwDefaultFlags = PATH_CANONICALIZE_APPEND_LONG_PATH_PREFIX | PATH_CANONICALIZE_KEEP_UNC_ROOT; | 174 | DWORD dwDefaultFlags = PATH_CANONICALIZE_APPEND_EXTENDED_PATH_PREFIX | PATH_CANONICALIZE_KEEP_UNC_ROOT; |
| 192 | int nResult = 0; | 175 | int nResult = 0; |
| 193 | 176 | ||
| 194 | if (!wzPath1 || !wzPath2) | 177 | if (!wzPath1 || !wzPath2) |
| @@ -221,7 +204,7 @@ DAPI_(HRESULT) PathDirectoryContainsPath( | |||
| 221 | HRESULT hr = S_OK; | 204 | HRESULT hr = S_OK; |
| 222 | LPWSTR sczCanonicalizedDirectory = NULL; | 205 | LPWSTR sczCanonicalizedDirectory = NULL; |
| 223 | LPWSTR sczCanonicalizedPath = NULL; | 206 | LPWSTR sczCanonicalizedPath = NULL; |
| 224 | DWORD dwDefaultFlags = PATH_CANONICALIZE_APPEND_LONG_PATH_PREFIX | PATH_CANONICALIZE_KEEP_UNC_ROOT; | 207 | DWORD dwDefaultFlags = PATH_CANONICALIZE_APPEND_EXTENDED_PATH_PREFIX | PATH_CANONICALIZE_KEEP_UNC_ROOT; |
| 225 | size_t cchDirectory = 0; | 208 | size_t cchDirectory = 0; |
| 226 | 209 | ||
| 227 | if (!wzDirectory || !*wzDirectory) | 210 | if (!wzDirectory || !*wzDirectory) |
| @@ -239,7 +222,7 @@ DAPI_(HRESULT) PathDirectoryContainsPath( | |||
| 239 | hr = PathCanonicalizeForComparison(wzPath, dwDefaultFlags, &sczCanonicalizedPath); | 222 | hr = PathCanonicalizeForComparison(wzPath, dwDefaultFlags, &sczCanonicalizedPath); |
| 240 | PathExitOnFailure(hr, "Failed to canonicalize the path."); | 223 | PathExitOnFailure(hr, "Failed to canonicalize the path."); |
| 241 | 224 | ||
| 242 | if (!PathIsFullyQualified(sczCanonicalizedDirectory, NULL)) | 225 | if (!PathIsFullyQualified(sczCanonicalizedDirectory)) |
| 243 | { | 226 | { |
| 244 | PathExitWithRootFailure(hr, E_INVALIDARG, "wzDirectory must be a fully qualified path."); | 227 | PathExitWithRootFailure(hr, E_INVALIDARG, "wzDirectory must be a fully qualified path."); |
| 245 | } | 228 | } |
