Skip to content

Commit

Permalink
fixed: windows version detection broken
Browse files Browse the repository at this point in the history
When more than one line of output appears at the start of cmd (because of AUTORUN), we parsed only the first line which failed the version detection.

This version simply search every line instead of just the first one.

It also clarifies through more precise logs the exact reason why enabling long-paths actually failed.
  • Loading branch information
Klaim committed Oct 18, 2024
1 parent dfb2bac commit a5c7f59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
24 changes: 16 additions & 8 deletions libmamba/src/core/util_os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,25 @@ namespace mamba
{
// Needs to be set system-wide & can only be run as admin ...

auto win_ver = util::windows_version();
const auto win_ver = util::windows_version();
LOG_DEBUG << fmt::format("Windows version : {}", win_ver ? win_ver.value() : win_ver.error().message);

static constexpr auto error_message_wrong_version = "Not setting long path registry key;"
"Windows version must be at least 10 with the fall 2016 \"Anniversary update\" or newer.";

if (!win_ver.has_value())
{
LOG_WARNING << "Not setting long path registry key; Windows version must be at least 10 "
"with the fall 2016 \"Anniversary update\" or newer.";
LOG_WARNING << "failed to acquire Windows version - " << error_message_wrong_version;
return false;
}


auto split_out = util::split(win_ver.value(), ".");
if (!(split_out.size() >= 3 && std::stoull(split_out[0]) >= 10
&& std::stoull(split_out[2]) >= 14352))
{
LOG_WARNING << "Not setting long path registry key; Windows version must be at least 10 "
"with the fall 2016 \"Anniversary update\" or newer.";
LOG_WARNING << "Windows version found:" << win_ver.value() << " - "
<< error_message_wrong_version;
return false;
}

Expand All @@ -164,7 +170,8 @@ namespace mamba
}
catch (const winreg::RegException& /*e*/)
{
LOG_INFO << "No LongPathsEnabled key detected.";
LOG_INFO << "No LongPathsEnabled key detected. (Windows version = " << win_ver.value()
<< ")";
return false;
}

Expand All @@ -173,8 +180,9 @@ namespace mamba
auto out = Console::stream();
fmt::print(
out,
"{}",
fmt::styled("Windows long-path support already enabled.", palette.ignored)
"{} (Windows version = {})",
fmt::styled("Windows long-path support already enabled.", palette.ignored),
win_ver.value()
);
return true;
}
Expand Down
6 changes: 5 additions & 1 deletion libmamba/src/util/os_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ namespace mamba::util
// from python
static const auto ver_output_regex = std::regex(R"((?:([\w ]+) ([\w.]+) .*\[.* ([\d.]+)\]))");

if (auto rmatch = std::smatch(); std::regex_match(out, rmatch, ver_output_regex))
// The output of the command could contain multiple unrelated lines, so we need to check
// every lines, which is why we need to search in a loop until reaching the end of the output.
std::smatch rmatch;
auto start_it = out.cbegin();
while (std::regex_search(start_it, out.cend(), rmatch, ver_output_regex))
{
std::string full_version = rmatch[3];
auto version_elems = util::split(full_version, ".");
Expand Down

0 comments on commit a5c7f59

Please sign in to comment.