Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

Summary of the Pull Request

Addresses code review feedback from #14121 requesting extraction of ~80% duplicated code between SaveImageImpl and ExportContainerImpl into a shared helper function.

PR Checklist

  • 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

Extracted common logic into HandleImageLikeOperation helper

  • Consolidates HTTP response handling, data relay setup, and error parsing
  • Takes optional callback parameter for operation-specific logic (e.g., WSL_LOG in export)
  • Removes redundant m_dockerClient validation already performed by callers

Before:

void WSLASession::SaveImageImpl(...) {
    wil::unique_handle imageFileHandle{...};
    THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), !m_dockerClient.has_value());
    relay::MultiHandleWait io;
    auto onCompleted = [&]() { io.Cancel(); };
    std::string errorJson;
    auto accumulateError = [&](const gsl::span<char>& buffer) { ... };
    // ... 30+ lines of identical logic
}

void WSLASession::ExportContainerImpl(...) {
    // Nearly identical code with minor variations
}

After:

void HandleImageLikeOperation(
    std::pair<uint32_t, std::unique_ptr<DockerHTTPClient::HTTPRequestContext>>& RequestCodePair,
    ULONG OutputHandle,
    HANDLE SessionTerminatingEvent,
    WSLA_ERROR_INFO* ErrorInfo,
    const char* FailureMessageFormat,
    std::function<void()> OnCompletedCallback = nullptr)
{
    // Consolidated logic with callback extension point
}

void WSLASession::SaveImageImpl(...) {
    HandleImageLikeOperation(RequestCodePair, OutputHandle, m_sessionTerminatingEvent.get(), 
                            Error, "Image save failed: %hs");
}

void WSLASession::ExportContainerImpl(...) {
    auto onCompletedCallback = []() { WSL_LOG("OnCompletedCalledForExport", ...); };
    HandleImageLikeOperation(RequestCodePair, OutputHandle, m_sessionTerminatingEvent.get(),
                            Error, "Container export failed: %hs", onCompletedCallback);
}

Net change: -1 LOC (67 removed, 66 added) with improved maintainability.

Validation Steps Performed

This PR targets the base branch of #14121 (not main). Validation will occur when #14121 is built and tested on Windows with Visual Studio.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits January 30, 2026 16:28
Co-authored-by: ptrivedi <1638019+ptrivedi@users.noreply.github.com>
Co-authored-by: ptrivedi <1638019+ptrivedi@users.noreply.github.com>
Co-authored-by: ptrivedi <1638019+ptrivedi@users.noreply.github.com>
Co-authored-by: ptrivedi <1638019+ptrivedi@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 30, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • archives.boost.io
    • Triggering command: /usr/local/bin/cmake /usr/local/bin/cmake -DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE -P /home/REDACTED/work/WSL/WSL/_codeql_build_dir/_deps/x64/boost_headers-subbuild/boost_headers-populate-prefix/src/boost_headers-populate-stamp/download-boost_headers-populate.cmake (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Refactor image save and export container based on feedback Refactor SaveImageImpl and ExportContainerImpl to eliminate code duplication Jan 30, 2026
Copilot AI requested a review from ptrivedi January 30, 2026 16:37
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.

2 participants