File tree Expand file tree Collapse file tree 5 files changed +26
-14
lines changed Expand file tree Collapse file tree 5 files changed +26
-14
lines changed Original file line number Diff line number Diff line change @@ -2620,17 +2620,12 @@ Strings EvalSettings::getDefaultNixPath()
26202620{
26212621 Strings res;
26222622 auto add = [&](const Path & p, const std::string & s = std::string ()) {
2623- try {
2624- if (pathExists (p)) {
2625- if (s.empty ()) {
2626- res.push_back (p);
2627- } else {
2628- res.push_back (s + " =" + p);
2629- }
2623+ if (pathAccessible (p)) {
2624+ if (s.empty ()) {
2625+ res.push_back (p);
2626+ } else {
2627+ res.push_back (s + " =" + p);
26302628 }
2631- } catch (SysError & e) {
2632- // swallow EPERM
2633- if (e.errNo != EPERM) throw ;
26342629 }
26352630 };
26362631
Original file line number Diff line number Diff line change @@ -57,8 +57,6 @@ Settings::Settings()
5757 auto sslOverride = getEnv (" NIX_SSL_CERT_FILE" ).value_or (getEnv (" SSL_CERT_FILE" ).value_or (" " ));
5858 if (sslOverride != " " )
5959 caFile = sslOverride;
60- else if (caFile == " " )
61- caFile = getDefaultSSLCertFile ();
6260
6361 /* Backwards compatibility. */
6462 auto s = getEnv (" NIX_REMOTE_SYSTEMS" );
@@ -185,7 +183,7 @@ bool Settings::isWSL1()
185183Path Settings::getDefaultSSLCertFile ()
186184{
187185 for (auto & fn : {" /etc/ssl/certs/ca-certificates.crt" , " /nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt" })
188- if (pathExists (fn)) return fn;
186+ if (pathAccessible (fn)) return fn;
189187 return " " ;
190188}
191189
Original file line number Diff line number Diff line change @@ -842,7 +842,7 @@ public:
842842 )" };
843843
844844 Setting<Path> caFile{
845- this , " " , " ssl-cert-file" ,
845+ this , getDefaultSSLCertFile () , " ssl-cert-file" ,
846846 R"(
847847 The path of a file containing CA certificates used to
848848 authenticate `https://` downloads. Nix by default will use
Original file line number Diff line number Diff line change @@ -266,6 +266,17 @@ bool pathExists(const Path & path)
266266 return false ;
267267}
268268
269+ bool pathAccessible (const Path & path)
270+ {
271+ try {
272+ return pathExists (path);
273+ } catch (SysError & e) {
274+ // swallow EPERM
275+ if (e.errNo == EPERM) return false ;
276+ throw ;
277+ }
278+ }
279+
269280
270281Path readLink (const Path & path)
271282{
Original file line number Diff line number Diff line change @@ -120,6 +120,14 @@ struct stat lstat(const Path & path);
120120 */
121121bool pathExists (const Path & path);
122122
123+ /* *
124+ * A version of pathExists that returns false on a permission error.
125+ * Useful for inferring default paths across directories that might not
126+ * be readable.
127+ * @return true iff the given path can be accessed and exists
128+ */
129+ bool pathAccessible (const Path & path);
130+
123131/* *
124132 * Read the contents (target) of a symbolic link. The result is not
125133 * in any way canonicalised.
You can’t perform that action at this time.
0 commit comments