|
36 | 36 | #include "mamba/core/util_os.hpp"
|
37 | 37 | #include "mamba/util/build.hpp"
|
38 | 38 | #include "mamba/util/environment.hpp"
|
| 39 | +#include "mamba/util/os_win.hpp" |
39 | 40 | #include "mamba/util/string.hpp"
|
40 | 41 |
|
41 | 42 | #ifdef _WIN32
|
@@ -138,8 +139,15 @@ namespace mamba
|
138 | 139 | bool enable_long_paths_support(bool force, Palette palette)
|
139 | 140 | {
|
140 | 141 | // Needs to be set system-wide & can only be run as admin ...
|
141 |
| - std::string win_ver = windows_version(); |
142 |
| - auto splitted = util::split(win_ver, "."); |
| 142 | + |
| 143 | + auto win_ver = util::windows_version(); |
| 144 | + if (!win_ver.has_value()) |
| 145 | + { |
| 146 | + LOG_WARNING << "Not setting long path registry key; Windows version must be at least 10 " |
| 147 | + "with the fall 2016 \"Anniversary update\" or newer."; |
| 148 | + return false; |
| 149 | + } |
| 150 | + auto splitted = util::split(win_ver.value(), "."); |
143 | 151 | if (!(splitted.size() >= 3 && std::stoull(splitted[0]) >= 10
|
144 | 152 | && std::stoull(splitted[2]) >= 14352))
|
145 | 153 | {
|
@@ -209,141 +217,7 @@ namespace mamba
|
209 | 217 | LOG_WARNING << "Changing registry value did not succeed.";
|
210 | 218 | return false;
|
211 | 219 | }
|
212 |
| -#endif |
213 |
| - |
214 |
| - std::string windows_version() |
215 |
| - { |
216 |
| - LOG_DEBUG << "Loading Windows virtual package"; |
217 |
| - auto override_version = util::get_env("CONDA_OVERRIDE_WIN"); |
218 |
| - if (override_version) |
219 |
| - { |
220 |
| - return override_version.value(); |
221 |
| - } |
222 |
| - |
223 |
| - if (!util::on_win) |
224 |
| - { |
225 |
| - return ""; |
226 |
| - } |
227 |
| - |
228 |
| - std::string out, err; |
229 |
| - std::vector<std::string> args = { util::get_env("COMSPEC").value_or(""), "/c", "ver" }; |
230 |
| - auto [status, ec] = reproc::run( |
231 |
| - args, |
232 |
| - reproc::options{}, |
233 |
| - reproc::sink::string(out), |
234 |
| - reproc::sink::string(err) |
235 |
| - ); |
236 |
| - |
237 |
| - if (ec) |
238 |
| - { |
239 |
| - LOG_WARNING << "Could not find Windows version by calling 'ver'\n" |
240 |
| - << "Please file a bug report.\nError: " << ec.message(); |
241 |
| - return ""; |
242 |
| - } |
243 |
| - std::string xout(util::strip(out)); |
244 |
| - |
245 |
| - // from python |
246 |
| - std::regex ver_output_regex("(?:([\\w ]+) ([\\w.]+) .*\\[.* ([\\d.]+)\\])"); |
247 |
| - |
248 |
| - std::smatch rmatch; |
249 |
| - |
250 |
| - std::string full_version, norm_version; |
251 |
| - if (std::regex_match(xout, rmatch, ver_output_regex)) |
252 |
| - { |
253 |
| - full_version = rmatch[3]; |
254 |
| - auto version_els = util::split(full_version, "."); |
255 |
| - norm_version = util::concat(version_els[0], ".", version_els[1], ".", version_els[2]); |
256 |
| - LOG_DEBUG << "Windows version found: " << norm_version; |
257 |
| - } |
258 |
| - else |
259 |
| - { |
260 |
| - LOG_DEBUG << "Windows version not found"; |
261 |
| - norm_version = "0.0.0"; |
262 |
| - } |
263 |
| - return norm_version; |
264 |
| - } |
265 |
| - |
266 |
| - std::string macos_version() |
267 |
| - { |
268 |
| - LOG_DEBUG << "Loading macos virtual package"; |
269 |
| - auto override_version = util::get_env("CONDA_OVERRIDE_OSX"); |
270 |
| - if (override_version) |
271 |
| - { |
272 |
| - return override_version.value(); |
273 |
| - } |
274 | 220 |
|
275 |
| - if (!util::on_mac) |
276 |
| - { |
277 |
| - return ""; |
278 |
| - } |
279 |
| - |
280 |
| - std::string out, err; |
281 |
| - // Note: we could also inspect /System/Library/CoreServices/SystemVersion.plist which is |
282 |
| - // an XML file |
283 |
| - // that contains the same information. However, then we'd either need an xml |
284 |
| - // parser or some other crude method to read the data |
285 |
| - std::vector<std::string> args = { "sw_vers", "-productVersion" }; |
286 |
| - auto [status, ec] = reproc::run( |
287 |
| - args, |
288 |
| - reproc::options{}, |
289 |
| - reproc::sink::string(out), |
290 |
| - reproc::sink::string(err) |
291 |
| - ); |
292 |
| - |
293 |
| - if (ec) |
294 |
| - { |
295 |
| - LOG_WARNING << "Could not find macOS version by calling 'sw_vers -productVersion'\nPlease file a bug report.\nError: " |
296 |
| - << ec.message(); |
297 |
| - return ""; |
298 |
| - } |
299 |
| - |
300 |
| - auto version = std::string(util::strip(out)); |
301 |
| - LOG_DEBUG << "macos version found: " << version; |
302 |
| - return version; |
303 |
| - } |
304 |
| - |
305 |
| - std::string linux_version() |
306 |
| - { |
307 |
| - LOG_DEBUG << "Loading linux virtual package"; |
308 |
| - auto override_version = util::get_env("CONDA_OVERRIDE_LINUX"); |
309 |
| - if (override_version) |
310 |
| - { |
311 |
| - return override_version.value(); |
312 |
| - } |
313 |
| - if (!util::on_linux) |
314 |
| - { |
315 |
| - return ""; |
316 |
| - } |
317 |
| - |
318 |
| -#ifndef _WIN32 |
319 |
| - struct utsname uname_result = {}; |
320 |
| - const auto ret = ::uname(&uname_result); |
321 |
| - if (ret != 0) |
322 |
| - { |
323 |
| - LOG_DEBUG << "Error calling uname (skipping): " |
324 |
| - << std::system_error(errno, std::generic_category()).what(); |
325 |
| - } |
326 |
| - |
327 |
| - static const std::regex re("([0-9]+\\.[0-9]+\\.[0-9]+)(?:-.*)?"); |
328 |
| - std::smatch m; |
329 |
| - std::string const version = uname_result.release; |
330 |
| - if (std::regex_search(version, m, re)) |
331 |
| - { |
332 |
| - if (m.size() == 2) |
333 |
| - { |
334 |
| - std::ssub_match linux_version = m[1]; |
335 |
| - LOG_DEBUG << "linux version found: " << linux_version; |
336 |
| - return linux_version.str(); |
337 |
| - } |
338 |
| - } |
339 |
| - |
340 |
| - LOG_DEBUG << "Could not parse linux version"; |
341 |
| -#endif |
342 |
| - |
343 |
| - return ""; |
344 |
| - } |
345 |
| - |
346 |
| -#ifdef _WIN32 |
347 | 221 | DWORD getppid()
|
348 | 222 | {
|
349 | 223 | HANDLE hSnapshot;
|
@@ -538,12 +412,14 @@ namespace mamba
|
538 | 412 | && console_mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
539 | 413 | features.true_colors = false;
|
540 | 414 |
|
541 |
| - std::string win_ver = windows_version(); |
542 |
| - auto splitted = util::split(win_ver, "."); |
543 |
| - if (splitted.size() >= 3 && std::stoull(splitted[0]) >= 10 |
544 |
| - && std::stoull(splitted[2]) >= 15063) |
| 415 | + if (auto version = util::windows_version()) |
545 | 416 | {
|
546 |
| - features.true_colors = true; |
| 417 | + auto splitted = util::split(version.value(), '.'); |
| 418 | + if (splitted.size() >= 3 && std::stoull(splitted[0]) >= 10 |
| 419 | + && std::stoull(splitted[2]) >= 15063) |
| 420 | + { |
| 421 | + features.true_colors = true; |
| 422 | + } |
547 | 423 | }
|
548 | 424 | #endif
|
549 | 425 | return features;
|
|
0 commit comments