Skip to content

Conversation

@OneBlue
Copy link
Collaborator

@OneBlue OneBlue commented Sep 18, 2025

Summary of the Pull Request

This change adds logic to write various package installation loglines to C:\Windows\temp\wsl-install-log.txt, which should help us root cause #11013

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds persistent install logging functionality to help diagnose WSL package upgrade issues by creating a log file at C:\Windows\temp\wsl-install-log.txt.

Key changes:

  • Implements WriteInstallLog() function to write timestamped log entries to a persistent file
  • Modifies IsUpdateNeeded() to return both update status and existing version information
  • Adds logging calls throughout the MSI installation process to track upgrade operations

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/windows/wslinstaller/exe/WslInstaller.cpp Modified IsUpdateNeeded() to return version info and added install logging call
src/windows/wslinstall/wslinstall.def Added new WslFinalizeInstallation export
src/windows/wslinstall/DllMain.cpp Added logging calls to MSI installation functions and new finalize function
src/windows/common/wslutil.h Added WriteInstallLog() function declaration
src/windows/common/wslutil.cpp Implemented WriteInstallLog() function with file handling and mutex synchronization
msipackage/package.wix.in Added custom action for install finalization

auto logLine = std::format("{:%FT%TZ} {}[{}]: {}\n", std::chrono::system_clock::now(), processName, WSL_PACKAGE_VERSION, Content);

DWORD bytesWritten{};
THROW_IF_WIN32_BOOL_FALSE(WriteFile(file.get(), logLine.c_str(), static_cast<DWORD>(logLine.size()), &bytesWritten, nullptr));
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using c_str() on a std::string to write to a file will only write the string content without accounting for UTF-8 encoding. Since the log line contains UTF-8 formatted timestamps and potentially non-ASCII characters, this should use logLine.data() and logLine.length() to ensure proper byte handling.

Suggested change
THROW_IF_WIN32_BOOL_FALSE(WriteFile(file.get(), logLine.c_str(), static_cast<DWORD>(logLine.size()), &bytesWritten, nullptr));
THROW_IF_WIN32_BOOL_FALSE(WriteFile(file.get(), logLine.data(), static_cast<DWORD>(logLine.size()), &bytesWritten, nullptr));

Copilot uses AI. Check for mistakes.
const auto key = OpenLxssMachineKey(KEY_READ);
const auto productCode = ReadString(key.get(), L"Msi", L"ProductCode", nullptr);

WriteInstallLog(std::format("Uninstalling MSI package: {}", productCode));
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type mismatch in format string. productCode is a std::wstring (wide string) but the format string expects a narrow string. This should either convert productCode to narrow string or use a wide string format approach.

Suggested change
WriteInstallLog(std::format("Uninstalling MSI package: {}", productCode));
WriteInstallLog(std::format(L"Uninstalling MSI package: {}", productCode));

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does std::format handle this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if (type == INSTALLMESSAGE_ERROR || type == INSTALLMESSAGE_FATALEXIT || type == INSTALLMESSAGE_WARNING)
{
WriteInstallLog(std::format("MSI message: {}", message));
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type mismatch in format string. The message parameter is LPCWSTR (wide string) but std::format in this context expects a narrow string. This will cause compilation errors or incorrect output.

Suggested change
WriteInstallLog(std::format("MSI message: {}", message));
WriteInstallLog(std::format(L"MSI message: {}", std::wstring_view(message)));

Copilot uses AI. Check for mistakes.
@OneBlue OneBlue merged commit e0c6196 into master Oct 1, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants