diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2022-05-26 17:34:48 -0500 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2022-05-31 13:20:44 -0500 |
| commit | 90982fbf1c887a3ed3454f9ab3ab8dfbd57a1383 (patch) | |
| tree | 7d87b21f0879de446f5db7053d349f32b4882cbe /src/libs | |
| parent | a070d8c7b57d6c9a54106abeb359a6c868b6d7ae (diff) | |
| download | wix-90982fbf1c887a3ed3454f9ab3ab8dfbd57a1383.tar.gz wix-90982fbf1c887a3ed3454f9ab3ab8dfbd57a1383.tar.bz2 wix-90982fbf1c887a3ed3454f9ab3ab8dfbd57a1383.zip | |
Add PathConcatRelativeToBase and use it in Burn.
Fixes 6707
Diffstat (limited to 'src/libs')
| -rw-r--r-- | src/libs/dutil/WixToolset.DUtil/inc/pathutil.h | 11 | ||||
| -rw-r--r-- | src/libs/dutil/WixToolset.DUtil/path2utl.cpp | 40 | ||||
| -rw-r--r-- | src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp | 107 |
3 files changed, 158 insertions, 0 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h b/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h index fc6bb3bb..941793f8 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/pathutil.h | |||
| @@ -237,6 +237,17 @@ DAPI_(HRESULT) PathConcatCch( | |||
| 237 | ); | 237 | ); |
| 238 | 238 | ||
| 239 | /******************************************************************* | 239 | /******************************************************************* |
| 240 | PathConcatRelativeToBase - canonicalizes a relative path before | ||
| 241 | concatenating it to the base path to ensure the resulting path | ||
| 242 | is inside the base path. | ||
| 243 | *******************************************************************/ | ||
| 244 | DAPI_(HRESULT) PathConcatRelativeToBase( | ||
| 245 | __in LPCWSTR wzBase, | ||
| 246 | __in_opt LPCWSTR wzRelative, | ||
| 247 | __deref_out_z LPWSTR* psczCombined | ||
| 248 | ); | ||
| 249 | |||
| 250 | /******************************************************************* | ||
| 240 | PathCompare - compares the fully expanded path of the two paths using | 251 | PathCompare - compares the fully expanded path of the two paths using |
| 241 | ::CompareStringW(). | 252 | ::CompareStringW(). |
| 242 | *******************************************************************/ | 253 | *******************************************************************/ |
diff --git a/src/libs/dutil/WixToolset.DUtil/path2utl.cpp b/src/libs/dutil/WixToolset.DUtil/path2utl.cpp index 45157d0b..61c1803a 100644 --- a/src/libs/dutil/WixToolset.DUtil/path2utl.cpp +++ b/src/libs/dutil/WixToolset.DUtil/path2utl.cpp | |||
| @@ -131,6 +131,46 @@ LExit: | |||
| 131 | return hr; | 131 | return hr; |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | DAPI_(HRESULT) PathConcatRelativeToBase( | ||
| 135 | __in LPCWSTR wzBase, | ||
| 136 | __in_opt LPCWSTR wzRelative, | ||
| 137 | __deref_out_z LPWSTR* psczCombined | ||
| 138 | ) | ||
| 139 | { | ||
| 140 | HRESULT hr = S_OK; | ||
| 141 | LPWSTR sczCanonicalizedRelative = NULL; | ||
| 142 | |||
| 143 | if (!wzBase || !*wzBase) | ||
| 144 | { | ||
| 145 | PathExitWithRootFailure(hr, E_INVALIDARG, "wzBase is required."); | ||
| 146 | } | ||
| 147 | |||
| 148 | if (PathIsRooted(wzRelative)) | ||
| 149 | { | ||
| 150 | PathExitWithRootFailure(hr, E_INVALIDARG, "wzRelative cannot be rooted."); | ||
| 151 | } | ||
| 152 | |||
| 153 | hr = StrAllocString(psczCombined, wzBase, 0); | ||
| 154 | PathExitOnFailure(hr, "Failed to copy base to output."); | ||
| 155 | |||
| 156 | if (wzRelative && *wzRelative) | ||
| 157 | { | ||
| 158 | hr = PathBackslashTerminate(psczCombined); | ||
| 159 | PathExitOnFailure(hr, "Failed to backslashify."); | ||
| 160 | |||
| 161 | hr = PathCanonicalizeForComparison(wzRelative, 0, &sczCanonicalizedRelative); | ||
| 162 | PathExitOnFailure(hr, "Failed to canonicalize wzRelative."); | ||
| 163 | |||
| 164 | hr = StrAllocConcat(psczCombined, sczCanonicalizedRelative, 0); | ||
| 165 | PathExitOnFailure(hr, "Failed to append relative to output."); | ||
| 166 | } | ||
| 167 | |||
| 168 | LExit: | ||
| 169 | ReleaseStr(sczCanonicalizedRelative); | ||
| 170 | |||
| 171 | return hr; | ||
| 172 | } | ||
| 173 | |||
| 134 | DAPI_(HRESULT) PathDirectoryContainsPath( | 174 | DAPI_(HRESULT) PathDirectoryContainsPath( |
| 135 | __in_z LPCWSTR wzDirectory, | 175 | __in_z LPCWSTR wzDirectory, |
| 136 | __in_z LPCWSTR wzPath | 176 | __in_z LPCWSTR wzPath |
diff --git a/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp index 04d0b447..52698b98 100644 --- a/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp +++ b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp | |||
| @@ -221,6 +221,113 @@ namespace DutilTests | |||
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | [Fact] | 223 | [Fact] |
| 224 | void PathConcatTest() | ||
| 225 | { | ||
| 226 | HRESULT hr = S_OK; | ||
| 227 | LPWSTR sczPath = NULL; | ||
| 228 | LPCWSTR rgwzPaths[54] = | ||
| 229 | { | ||
| 230 | L"a", NULL, L"a", | ||
| 231 | L"a", L"", L"a", | ||
| 232 | L"C:\\", L"a", L"C:\\a", | ||
| 233 | L"\\a", L"b", L"\\a\\b", | ||
| 234 | L"a", L"b", L"a\\b", | ||
| 235 | L"C:\\", L"..\\a", L"C:\\..\\a", | ||
| 236 | L"C:\\a", L"..\\b", L"C:\\a\\..\\b", | ||
| 237 | L"\\\\server\\share", L"..\\a", L"\\\\server\\share\\..\\a", | ||
| 238 | L"\\\\server\\share\\a", L"..\\b", L"\\\\server\\share\\a\\..\\b", | ||
| 239 | NULL, L"b", L"b", | ||
| 240 | L"", L"b", L"b", | ||
| 241 | L"a", L"\\b", L"\\b", | ||
| 242 | L"a", L"b:", L"b:", | ||
| 243 | L"a", L"b:\\", L"b:\\", | ||
| 244 | L"a", L"\\\\?\\b", L"\\\\?\\b", | ||
| 245 | L"a", L"\\\\?\\UNC\\b", L"\\\\?\\UNC\\b", | ||
| 246 | L"a", L"\\b", L"\\b", | ||
| 247 | L"a", L"\\\\", L"\\\\", | ||
| 248 | }; | ||
| 249 | |||
| 250 | try | ||
| 251 | { | ||
| 252 | for (DWORD i = 0; i < countof(rgwzPaths); i += 3) | ||
| 253 | { | ||
| 254 | hr = PathConcat(rgwzPaths[i], rgwzPaths[i + 1], &sczPath); | ||
| 255 | NativeAssert::Succeeded(hr, "PathConcat: {0}, {1}", rgwzPaths[i], rgwzPaths[i + 1]); | ||
| 256 | NativeAssert::StringEqual(rgwzPaths[i + 2], sczPath); | ||
| 257 | } | ||
| 258 | } | ||
| 259 | finally | ||
| 260 | { | ||
| 261 | ReleaseStr(sczPath); | ||
| 262 | } | ||
| 263 | } | ||
| 264 | |||
| 265 | [Fact] | ||
| 266 | void PathConcatRelativeToBaseTest() | ||
| 267 | { | ||
| 268 | HRESULT hr = S_OK; | ||
| 269 | LPWSTR sczPath = NULL; | ||
| 270 | LPCWSTR rgwzPaths[27] = | ||
| 271 | { | ||
| 272 | L"a", NULL, L"a", | ||
| 273 | L"a", L"", L"a", | ||
| 274 | L"C:\\", L"a", L"C:\\a", | ||
| 275 | L"\\a", L"b", L"\\a\\b", | ||
| 276 | L"a", L"b", L"a\\b", | ||
| 277 | L"C:\\", L"..\\a", L"C:\\a", | ||
| 278 | L"C:\\a", L"..\\b", L"C:\\a\\b", | ||
| 279 | L"\\\\server\\share", L"..\\a", L"\\\\server\\share\\a", | ||
| 280 | L"\\\\server\\share\\a", L"..\\b", L"\\\\server\\share\\a\\b", | ||
| 281 | }; | ||
| 282 | |||
| 283 | try | ||
| 284 | { | ||
| 285 | for (DWORD i = 0; i < countof(rgwzPaths); i += 3) | ||
| 286 | { | ||
| 287 | hr = PathConcatRelativeToBase(rgwzPaths[i], rgwzPaths[i + 1], &sczPath); | ||
| 288 | NativeAssert::Succeeded(hr, "PathConcatRelativeToBase: {0}, {1}", rgwzPaths[i], rgwzPaths[i + 1]); | ||
| 289 | NativeAssert::StringEqual(rgwzPaths[i + 2], sczPath); | ||
| 290 | } | ||
| 291 | } | ||
| 292 | finally | ||
| 293 | { | ||
| 294 | ReleaseStr(sczPath); | ||
| 295 | } | ||
| 296 | } | ||
| 297 | |||
| 298 | [Fact] | ||
| 299 | void PathConcatRelativeToBaseFailureTest() | ||
| 300 | { | ||
| 301 | HRESULT hr = S_OK; | ||
| 302 | LPWSTR sczPath = NULL; | ||
| 303 | LPCWSTR rgwzPaths[18] = | ||
| 304 | { | ||
| 305 | NULL, L"b", | ||
| 306 | L"", L"b", | ||
| 307 | L"a", L"\\b", | ||
| 308 | L"a", L"b:", | ||
| 309 | L"a", L"b:\\", | ||
| 310 | L"a", L"\\\\?\\b", | ||
| 311 | L"a", L"\\\\?\\UNC\\b", | ||
| 312 | L"a", L"\\b", | ||
| 313 | L"a", L"\\\\", | ||
| 314 | }; | ||
| 315 | |||
| 316 | try | ||
| 317 | { | ||
| 318 | for (DWORD i = 0; i < countof(rgwzPaths); i += 2) | ||
| 319 | { | ||
| 320 | hr = PathConcatRelativeToBase(rgwzPaths[i], rgwzPaths[i + 1], &sczPath); | ||
| 321 | NativeAssert::SpecificReturnCode(hr, E_INVALIDARG, "PathConcatRelativeToBase: {0}, {1}", rgwzPaths[i], rgwzPaths[i + 1]); | ||
| 322 | } | ||
| 323 | } | ||
| 324 | finally | ||
| 325 | { | ||
| 326 | ReleaseStr(sczPath); | ||
| 327 | } | ||
| 328 | } | ||
| 329 | |||
| 330 | [Fact] | ||
| 224 | void PathDirectoryContainsPathTest() | 331 | void PathDirectoryContainsPathTest() |
| 225 | { | 332 | { |
| 226 | HRESULT hr = S_OK; | 333 | HRESULT hr = S_OK; |
