PathEnsureQuoted is not generally useful.
Sean Hall committed
May 26, 2022 at 17:31 UTC
8b6f46af50651e0b1faf7adf94a179c6e16a05b1
4 files changed
+59
-68
src/ext/NetFx/ca/netfxca.cpp
+58
@@ -280,6 +280,64 @@ LExit:
280
return hr;
281
}
282
283
+// This has netfxca specific functionality, like turning " into "" and leaving an unescaped \ at the end of a directory.
284
+static HRESULT PathEnsureQuoted(
285
+ __inout LPWSTR* ppszPath,
286
+ __in BOOL fDirectory
287
+ )
288
+{
289
+ Assert(ppszPath && *ppszPath);
290
+
291
+ HRESULT hr = S_OK;
292
+ size_t cchPath = 0;
293
+
294
+ hr = ::StringCchLengthW(*ppszPath, STRSAFE_MAX_CCH, &cchPath);
295
+ ExitOnFailure(hr, "Failed to get the length of the path.");
296
+
297
+ // Handle simple special cases.
298
+ if (0 == cchPath || (1 == cchPath && L'"' == (*ppszPath)[0]))
299
+ {
300
+ hr = StrAllocString(ppszPath, L"\"\"", 2);
301
+ ExitOnFailure(hr, "Failed to allocate a quoted empty string.");
302
+
303
+ ExitFunction();
304
+ }
305
+
306
+ if (L'"' != (*ppszPath)[0])
307
+ {
308
+ hr = StrAllocPrefix(ppszPath, L"\"", 1);
309
+ ExitOnFailure(hr, "Failed to allocate an opening quote.");
310
+
311
+ // Add a char for the opening quote.
312
+ ++cchPath;
313
+ }
314
+
315
+ if (L'"' != (*ppszPath)[cchPath - 1])
316
+ {
317
+ hr = StrAllocConcat(ppszPath, L"\"", 1);
318
+ ExitOnFailure(hr, "Failed to allocate a closing quote.");
319
+
320
+ // Add a char for the closing quote.
321
+ ++cchPath;
322
+ }
323
+
324
+ if (fDirectory)
325
+ {
326
+ if (L'\\' != (*ppszPath)[cchPath - 2])
327
+ {
328
+ // Change the last char to a backslash and re-append the closing quote.
329
+ (*ppszPath)[cchPath - 1] = L'\\';
330
+
331
+ hr = StrAllocConcat(ppszPath, L"\"", 1);
332
+ ExitOnFailure(hr, "Failed to allocate another closing quote after the backslash.");
333
+ }
334
+ }
335
+
336
+LExit:
337
+
338
+ return hr;
339
+}
340
+
341
static HRESULT CreateInstallCommand(
342
__out LPWSTR* ppwzCommandLine,
343
__in LPCWSTR pwzNgenPath,
src/ext/NetFx/ca/precomp.h
+1
@@ -4,6 +4,7 @@
4
5
#include <windows.h>
6
#include <msiquery.h>
7
+#include <strsafe.h>
8
9
#include "wcautil.h"
10
#include "fileutil.h"
src/libs/dutil/WixToolset.DUtil/inc/pathutil.h
-10
@@ -195,16 +195,6 @@ DAPI_(HRESULT) PathConcatCch(
195
__deref_out_z LPWSTR* psczCombined
196
);
197
198
-/*******************************************************************
199
- PathEnsureQuoted - ensures that a path is quoted; optionally,
200
- this function also terminates a directory with a backslash
201
- if it is not already.
202
-*******************************************************************/
203
-DAPI_(HRESULT) PathEnsureQuoted(
204
- __inout LPWSTR* ppszPath,
205
- __in BOOL fDirectory
206
- );
207
-
198
/*******************************************************************
199
PathCompare - compares the fully expanded path of the two paths using
200
::CompareStringW().
src/libs/dutil/WixToolset.DUtil/pathutil.cpp
-58
@@ -875,64 +875,6 @@ LExit:
875
}
876
877
878
-DAPI_(HRESULT) PathEnsureQuoted(
879
- __inout LPWSTR* ppszPath,
880
- __in BOOL fDirectory
881
- )
882
-{
883
- Assert(ppszPath && *ppszPath);
884
-
885
- HRESULT hr = S_OK;
886
- size_t cchPath = 0;
887
-
888
- hr = ::StringCchLengthW(*ppszPath, STRSAFE_MAX_CCH, &cchPath);
889
- PathExitOnFailure(hr, "Failed to get the length of the path.");
890
-
891
- // Handle simple special cases.
892
- if (0 == cchPath || (1 == cchPath && L'"' == (*ppszPath)[0]))
893
- {
894
- hr = StrAllocString(ppszPath, L"\"\"", 2);
895
- PathExitOnFailure(hr, "Failed to allocate a quoted empty string.");
896
-
897
- ExitFunction();
898
- }
899
-
900
- if (L'"' != (*ppszPath)[0])
901
- {
902
- hr = StrAllocPrefix(ppszPath, L"\"", 1);
903
- PathExitOnFailure(hr, "Failed to allocate an opening quote.");
904
-
905
- // Add a char for the opening quote.
906
- ++cchPath;
907
- }
908
-
909
- if (L'"' != (*ppszPath)[cchPath - 1])
910
- {
911
- hr = StrAllocConcat(ppszPath, L"\"", 1);
912
- PathExitOnFailure(hr, "Failed to allocate a closing quote.");
913
-
914
- // Add a char for the closing quote.
915
- ++cchPath;
916
- }
917
-
918
- if (fDirectory)
919
- {
920
- if (L'\\' != (*ppszPath)[cchPath - 2])
921
- {
922
- // Change the last char to a backslash and re-append the closing quote.
923
- (*ppszPath)[cchPath - 1] = L'\\';
924
-
925
- hr = StrAllocConcat(ppszPath, L"\"", 1);
926
- PathExitOnFailure(hr, "Failed to allocate another closing quote after the backslash.");
927
- }
928
- }
929
-
930
-LExit:
931
-
932
- return hr;
933
-}
934
-
935
-
878
DAPI_(HRESULT) PathCompare(
879
__in_z LPCWSTR wzPath1,
880
__in_z LPCWSTR wzPath2,