From 46030181d4725f5bf3fe46f1ebfd032f99906c92 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 28 Apr 2025 11:19:36 -0400 Subject: [PATCH] Delete dead code We had multiple copies of some static functions after splitting out `DerivationBuilder` by mistake. --- src/libstore/build/derivation-goal.cc | 58 ------------------- src/libstore/unix/build/derivation-builder.cc | 27 ++++++++- 2 files changed, 26 insertions(+), 59 deletions(-) diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc index a08a3ea74..344d1c7ea 100644 --- a/src/libstore/build/derivation-goal.cc +++ b/src/libstore/build/derivation-goal.cc @@ -971,64 +971,6 @@ Goal::Co DerivationGoal::repairClosure() } -static void chmod_(const Path & path, mode_t mode) -{ - if (chmod(path.c_str(), mode) == -1) - throw SysError("setting permissions on '%s'", path); -} - - -/* Move/rename path 'src' to 'dst'. Temporarily make 'src' writable if - it's a directory and we're not root (to be able to update the - directory's parent link ".."). */ -static void movePath(const Path & src, const Path & dst) -{ - auto st = lstat(src); - - bool changePerm = ( -#ifndef _WIN32 - geteuid() -#else - !isRootUser() -#endif - && S_ISDIR(st.st_mode) && !(st.st_mode & S_IWUSR)); - - if (changePerm) - chmod_(src, st.st_mode | S_IWUSR); - - std::filesystem::rename(src, dst); - - if (changePerm) - chmod_(dst, st.st_mode); -} - - -void replaceValidPath(const Path & storePath, const Path & tmpPath) -{ - /* We can't atomically replace storePath (the original) with - tmpPath (the replacement), so we have to move it out of the - way first. We'd better not be interrupted here, because if - we're repairing (say) Glibc, we end up with a broken system. */ - Path oldPath = fmt("%1%.old-%2%-%3%", storePath, getpid(), rand()); - if (pathExists(storePath)) - movePath(storePath, oldPath); - - try { - movePath(tmpPath, storePath); - } catch (...) { - try { - // attempt to recover - movePath(oldPath, storePath); - } catch (...) { - ignoreExceptionExceptInterrupt(); - } - throw; - } - - deletePath(oldPath); -} - - void runPostBuildHook( Store & store, Logger & logger, diff --git a/src/libstore/unix/build/derivation-builder.cc b/src/libstore/unix/build/derivation-builder.cc index 2131b4e88..76f69671c 100644 --- a/src/libstore/unix/build/derivation-builder.cc +++ b/src/libstore/unix/build/derivation-builder.cc @@ -661,7 +661,32 @@ static void movePath(const Path & src, const Path & dst) } -extern void replaceValidPath(const Path & storePath, const Path & tmpPath); +static void replaceValidPath(const Path & storePath, const Path & tmpPath) +{ + /* We can't atomically replace storePath (the original) with + tmpPath (the replacement), so we have to move it out of the + way first. We'd better not be interrupted here, because if + we're repairing (say) Glibc, we end up with a broken system. */ + Path oldPath = fmt("%1%.old-%2%-%3%", storePath, getpid(), rand()); + if (pathExists(storePath)) + movePath(storePath, oldPath); + + try { + movePath(tmpPath, storePath); + } catch (...) { + try { + // attempt to recover + movePath(oldPath, storePath); + } catch (...) { + ignoreExceptionExceptInterrupt(); + } + throw; + } + + deletePath(oldPath); +} + + bool DerivationBuilderImpl::cleanupDecideWhetherDiskFull()