diff --git a/src/libfetchers/git-utils.cc b/src/libfetchers/git-utils.cc index 4ad90a63689..ed606dad531 100644 --- a/src/libfetchers/git-utils.cc +++ b/src/libfetchers/git-utils.cc @@ -1425,7 +1425,7 @@ std::vector> GitRepoImpl::getSubmodules auto [fdTemp, pathTemp] = createTempFile("nix-git-submodules"); try { writeFull(fdTemp.get(), configS); - } catch (SysError & e) { + } catch (SystemError & e) { e.addTrace({}, "while writing .gitmodules file to temporary file"); throw; } diff --git a/src/libmain/plugin.cc b/src/libmain/plugin.cc index 4755ba24bfa..713d7bc426a 100644 --- a/src/libmain/plugin.cc +++ b/src/libmain/plugin.cc @@ -83,8 +83,8 @@ void initPlugins() checkInterrupt(); pluginFiles.emplace_back(ent.path()); } - } catch (SysError & e) { - if (e.errNo != ENOTDIR) + } catch (SystemError & e) { + if (!e.is(std::errc::not_a_directory)) throw; pluginFiles.emplace_back(pluginFile); } diff --git a/src/libstore/build/derivation-building-goal.cc b/src/libstore/build/derivation-building-goal.cc index 8fbe5435322..7af793809b9 100644 --- a/src/libstore/build/derivation-building-goal.cc +++ b/src/libstore/build/derivation-building-goal.cc @@ -1028,8 +1028,8 @@ HookReply DerivationBuildingGoal::tryBuildHook(const DerivationOptionsfromHook.readSide.get()))); worker.hook = 0; return rpDecline; diff --git a/src/libstore/builtins/buildenv.cc b/src/libstore/builtins/buildenv.cc index 4db37d43a79..96f62a5fd38 100644 --- a/src/libstore/builtins/buildenv.cc +++ b/src/libstore/builtins/buildenv.cc @@ -33,8 +33,8 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir, try { srcFiles = DirectoryIterator{srcDir}; - } catch (SysError & e) { - if (e.errNo == ENOTDIR) { + } catch (SystemError & e) { + if (e.is(std::errc::not_a_directory)) { warn("not including '%s' in the user environment because it's not a directory", srcDir); return; } @@ -54,8 +54,8 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir, try { if (stat(srcFile.c_str(), &srcSt) == -1) throw SysError("getting status of '%1%'", srcFile); - } catch (SysError & e) { - if (e.errNo == ENOENT || e.errNo == ENOTDIR) { + } catch (SystemError & e) { + if (e.is(std::errc::no_such_file_or_directory) || e.is(std::errc::not_a_directory)) { warn("skipping dangling symlink '%s'", dstFile); continue; } @@ -141,8 +141,8 @@ void buildProfile(const Path & out, Packages && pkgs) readFile(pkgDir + "/nix-support/propagated-user-env-packages"), " \n")) if (!done.count(p)) postponed.insert(p); - } catch (SysError & e) { - if (e.errNo != ENOENT && e.errNo != ENOTDIR) + } catch (SystemError & e) { + if (!e.is(std::errc::no_such_file_or_directory) && !e.is(std::errc::not_a_directory)) throw; } }; diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 0561ab9f67d..669977f5230 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -115,10 +115,10 @@ void LocalStore::addTempRoot(const StorePath & path) *fdRootsSocket = createUnixDomainSocket(); try { nix::connect(toSocket(fdRootsSocket->get()), socketPath); - } catch (SysError & e) { + } catch (SystemError & e) { /* The garbage collector may have exited or not created the socket yet, so we need to restart. */ - if (e.errNo == ECONNREFUSED || e.errNo == ENOENT) { + if (e.is(std::errc::connection_refused) || e.is(std::errc::no_such_file_or_directory)) { debug("GC socket connection refused: %s", e.msg()); fdRootsSocket->close(); std::this_thread::sleep_for(std::chrono::milliseconds(100)); @@ -135,10 +135,10 @@ void LocalStore::addTempRoot(const StorePath & path) readFull(fdRootsSocket->get(), &c, 1); assert(c == '1'); debug("got ack for GC root '%s'", printStorePath(path)); - } catch (SysError & e) { + } catch (SystemError & e) { /* The garbage collector may have exited, so we need to restart. */ - if (e.errNo == EPIPE || e.errNo == ECONNRESET) { + if (e.is(std::errc::broken_pipe) || e.is(std::errc::connection_reset)) { debug("GC socket disconnected"); fdRootsSocket->close(); goto restart; @@ -280,9 +280,10 @@ void LocalStore::findRoots(const Path & path, std::filesystem::file_type type, R throw; } - catch (SysError & e) { + catch (SystemError & e) { /* We only ignore permanent failures. */ - if (e.errNo == EACCES || e.errNo == ENOENT || e.errNo == ENOTDIR) + if (e.is(std::errc::permission_denied) || e.is(std::errc::no_such_file_or_directory) + || e.is(std::errc::not_a_directory)) printInfo("cannot read potential root '%1%'", path); else throw; @@ -347,8 +348,8 @@ static void readFileRoots(const std::filesystem::path & path, UncheckedRoots & r { try { roots[readFile(path)].emplace(path.string()); - } catch (SysError & e) { - if (e.errNo != ENOENT && e.errNo != EACCES) + } catch (SystemError & e) { + if (!e.is(std::errc::no_such_file_or_directory) && !e.is(std::errc::permission_denied)) throw; } } diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 4b92d752291..87914c4c840 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -234,8 +234,8 @@ LocalStore::LocalStore(ref config) Path globalLockPath = dbDir + "/big-lock"; try { globalLock = openLockFile(globalLockPath.c_str(), true); - } catch (SysError & e) { - if (e.errNo == EACCES || e.errNo == EPERM) { + } catch (SystemError & e) { + if (e.is(std::errc::permission_denied) || e.is(std::errc::operation_not_permitted)) { e.addTrace( {}, "This command may have been run as non-root in a single-user Nix installation,\n" diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 22af53ae882..305da446647 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -377,10 +377,10 @@ ref RemoteStore::addCAToStore( } } conn.processStderr(); - } catch (SysError & e) { + } catch (SystemError & e) { /* Daemon closed while we were sending the path. Probably OOM or I/O error. */ - if (e.errNo == EPIPE) + if (e.is(std::errc::broken_pipe)) try { conn.processStderr(); } catch (EndOfFile & e) { diff --git a/src/libutil/file-system.cc b/src/libutil/file-system.cc index 1a003964d30..df7b2fbab78 100644 --- a/src/libutil/file-system.cc +++ b/src/libutil/file-system.cc @@ -236,9 +236,9 @@ bool pathAccessible(const std::filesystem::path & path) { try { return pathExists(path.string()); - } catch (SysError & e) { + } catch (SystemError & e) { // swallow EPERM - if (e.errNo == EPERM) + if (e.is(std::errc::operation_not_permitted)) return false; throw; } diff --git a/src/nix/build-remote/build-remote.cc b/src/nix/build-remote/build-remote.cc index f62712d30ea..40502d19313 100644 --- a/src/nix/build-remote/build-remote.cc +++ b/src/nix/build-remote/build-remote.cc @@ -264,8 +264,8 @@ static int main_build_remote(int argc, char ** argv) }; try { setUpdateLock(storeUri); - } catch (SysError & e) { - if (e.errNo != ENAMETOOLONG) + } catch (SystemError & e) { + if (!e.is(std::errc::filename_too_long)) throw; // Try again hashing the store URL so we have a shorter path auto h = hashString(HashAlgorithm::MD5, storeUri);