aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2020-01-04 17:47:52 +0100
committerDaiderd Jordan <daiderd@gmail.com>2020-01-04 20:24:27 +0100
commitb33fefcb92e02725fc77b6adfabab1c1f43e9aa1 (patch)
tree07625e607438f3395390d72e27e9e42e9a820152 /src
parent0de33cc81b9c33041b7db12a89d4480b9be3347e (diff)
build: recover store path when replacing fails
This shouldn't happen in normal circumstances, but just in case attempt to move the temporary path back if possible.
Diffstat (limited to 'src')
-rw-r--r--src/libstore/build.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 78f39fed1..257d70ca9 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -1513,8 +1513,10 @@ void replaceValidPath(const Path & storePath, const Path tmpPath)
Path oldPath = (format("%1%.old-%2%-%3%") % storePath % getpid() % random()).str();
if (pathExists(storePath))
rename(storePath.c_str(), oldPath.c_str());
- if (rename(tmpPath.c_str(), storePath.c_str()) == -1)
+ if (rename(tmpPath.c_str(), storePath.c_str()) == -1) {
+ rename(oldPath.c_str(), storePath.c_str()); // attempt to recover
throw SysError("moving '%s' to '%s'", tmpPath, storePath);
+ }
deletePath(oldPath);
}