|
8 | 8 | #include "mamba/core/invoke.hpp" |
9 | 9 | #include "mamba/core/thread_utils.hpp" |
10 | 10 | #include "mamba/core/util.hpp" |
| 11 | +#include "mamba/core/util_os.hpp" |
11 | 12 | #include "mamba/core/util_scope.hpp" |
12 | 13 | #include "mamba/download/downloader.hpp" |
13 | 14 | #include "mamba/util/build.hpp" |
@@ -84,19 +85,43 @@ namespace mamba::download |
84 | 85 | // from `conda-forge::ca-certificates` and the system CA certificates. |
85 | 86 | else if (remote_fetch_params.ssl_verify == "<system>") |
86 | 87 | { |
87 | | - // Use the CA certificates from `conda-forge::ca-certificates` installed in the |
88 | | - // root prefix or the system CA certificates if the certificate is not present. |
89 | | - fs::u8path root_prefix = detail::get_root_prefix(); |
90 | | - fs::u8path env_prefix_conda_cert = root_prefix / "ssl" / "cacert.pem"; |
91 | | - |
92 | | - LOG_INFO << "Checking for CA certificates at the root prefix: " |
| 88 | + fs::u8path executable_path = get_self_exe_path(); |
| 89 | + // Find the supposed environment prefix. |
| 90 | + // `mamba` or `micromamba` is installed at: |
| 91 | + // - `${PREFIX}/bin/{mamba,micromamba}` on Unix |
| 92 | + // - `${PREFIX}/Library/bin/{mamba,micromamba}.exe` on Windows |
| 93 | + fs::u8path env_prefix = util::on_win |
| 94 | + ? (executable_path.parent_path() |
| 95 | + .parent_path() |
| 96 | + .parent_path() : executable_path.parent_path() |
| 97 | + .parent_path()); |
| 98 | + |
| 99 | + fs::u8path env_prefix_conda_cert = env_prefix / "ssl" / "cacert.pem"; |
| 100 | + |
| 101 | + LOG_INFO << "Checking for CA certificates in the same environment as the executable installation: " |
93 | 102 | << env_prefix_conda_cert; |
94 | 103 |
|
95 | 104 | if (fs::exists(env_prefix_conda_cert)) |
96 | 105 | { |
97 | | - LOG_INFO << "Using CA certificates from `conda-forge::ca-certificates` installed in the root prefix " |
| 106 | + LOG_INFO << "Using CA certificates from the same prefix as the executable installation " |
98 | 107 | << "(i.e " << env_prefix_conda_cert << ")"; |
99 | 108 | remote_fetch_params.ssl_verify = env_prefix_conda_cert; |
| 109 | + return; |
| 110 | + } |
| 111 | + |
| 112 | + // Try to use the CA certificates from `conda-forge::ca-certificates` installed |
| 113 | + // in the root prefix. |
| 114 | + fs::u8path root_prefix = detail::get_root_prefix(); |
| 115 | + fs::u8path root_prefix_conda_cert = root_prefix / "ssl" / "cacert.pem"; |
| 116 | + |
| 117 | + LOG_INFO << "Checking for CA certificates at the root prefix: " |
| 118 | + << root_prefix_conda_cert; |
| 119 | + |
| 120 | + if (fs::exists(root_prefix_conda_cert)) |
| 121 | + { |
| 122 | + LOG_INFO << "Using CA certificates from `conda-forge::ca-certificates` installed in the root prefix " |
| 123 | + << "(i.e " << root_prefix_conda_cert << ")"; |
| 124 | + remote_fetch_params.ssl_verify = root_prefix_conda_cert; |
100 | 125 | remote_fetch_params.curl_initialized = true; |
101 | 126 | return; |
102 | 127 | } |
|
0 commit comments