@joebigelow / wix / commits / 352aefb0

WIXFEAT:3816-Format variables and respect absolute paths in Log/@Prefix

Sean Hall committed Nov 1, 2020 at 16:43 UTC 352aefb0ac67ffbf74cd126db710031d4944fe89
1 file changed +38 -16
src/engine/logging.cpp
+38 -16
@@ -33,6 +33,7 @@ extern "C" HRESULT LoggingOpen(
33 {
34 HRESULT hr = S_OK;
35 LPWSTR sczLoggingBaseFolder = NULL;
36 + LPWSTR sczPrefixFormatted = NULL;
37
38 // Check if the logging policy is set and configure the logging appropriately.
39 CheckLoggingPolicy(&pLog->dwAttributes);
@@ -103,30 +104,50 @@ extern "C" HRESULT LoggingOpen(
104 pLog->state = BURN_LOGGING_STATE_OPEN;
105 }
106 }
106 - else if (pLog->sczPrefix && *pLog->sczPrefix)
107 + else
108 {
108 - hr = GetNonSessionSpecificTempFolder(&sczLoggingBaseFolder);
109 - ExitOnFailure(hr, "Failed to get non-session specific TEMP folder.");
109 + if (pLog->sczPrefix && *pLog->sczPrefix)
110 + {
111 + hr = VariableFormatString(pVariables, pLog->sczPrefix, &sczPrefixFormatted, NULL);
112 + }
113
111 - // Best effort to open default logging.
112 - hr = LogOpen(sczLoggingBaseFolder, pLog->sczPrefix, NULL, pLog->sczExtension, FALSE, FALSE, &pLog->sczPath);
113 - if (FAILED(hr))
114 + if (sczPrefixFormatted && *sczPrefixFormatted)
115 {
115 - LogDisable();
116 - pLog->state = BURN_LOGGING_STATE_DISABLED;
116 + LPCWSTR wzPrefix = sczPrefixFormatted;
117 +
118 + // Best effort to open default logging.
119 + if (PathIsAbsolute(sczPrefixFormatted))
120 + {
121 + hr = PathGetDirectory(sczPrefixFormatted, &sczLoggingBaseFolder);
122 + ExitOnFailure(hr, "Failed to get parent directory from '%ls'.", sczPrefixFormatted);
123 +
124 + wzPrefix = PathFile(sczPrefixFormatted);
125 + }
126 + else
127 + {
128 + hr = GetNonSessionSpecificTempFolder(&sczLoggingBaseFolder);
129 + ExitOnFailure(hr, "Failed to get non-session specific TEMP folder.");
130 + }
131
118 - hr = S_OK;
132 + hr = LogOpen(sczLoggingBaseFolder, wzPrefix, NULL, pLog->sczExtension, FALSE, FALSE, &pLog->sczPath);
133 + if (FAILED(hr))
134 + {
135 + LogDisable();
136 + pLog->state = BURN_LOGGING_STATE_DISABLED;
137 +
138 + hr = S_OK;
139 + }
140 + else
141 + {
142 + pLog->state = BURN_LOGGING_STATE_OPEN;
143 + }
144 }
120 - else
145 + else // no logging enabled.
146 {
122 - pLog->state = BURN_LOGGING_STATE_OPEN;
147 + LogDisable();
148 + pLog->state = BURN_LOGGING_STATE_DISABLED;
149 }
150 }
125 - else // no logging enabled.
126 - {
127 - LogDisable();
128 - pLog->state = BURN_LOGGING_STATE_DISABLED;
129 - }
151
152 // If the log was opened, write the header info and update the prefix and extension to match
153 // the log name so future logs are opened with the same pattern.
@@ -155,6 +176,7 @@ extern "C" HRESULT LoggingOpen(
176
177 LExit:
178 ReleaseStr(sczLoggingBaseFolder);
179 + StrSecureZeroFreeString(sczPrefixFormatted);
180
181 return hr;
182 }