diff options
author | Théophane Hufschmitt <theophane@hufschmitt.net> | 2022-03-17 15:28:46 +0100 |
---|---|---|
committer | Théophane Hufschmitt <theophane.hufschmitt@tweag.io> | 2022-08-03 10:27:25 +0200 |
commit | c2de0a232c1cfddb1f1385ffd23dd43a2099458e (patch) | |
tree | 1e174413830f7951f995fcbe417bb132a2dbb081 /src/libstore/optimise-store.cc | |
parent | 8119390abcbb25e849acc50d0af0b37d85adfb04 (diff) |
Create a wrapper around stdlib’s `rename`
Directly takes some c++ strings, and gently throws an exception on error
(rather than having to inline this logic everywhere)
Diffstat (limited to 'src/libstore/optimise-store.cc')
-rw-r--r-- | src/libstore/optimise-store.cc | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/libstore/optimise-store.cc b/src/libstore/optimise-store.cc index 8af9b1dde..20b9c7611 100644 --- a/src/libstore/optimise-store.cc +++ b/src/libstore/optimise-store.cc @@ -229,7 +229,9 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats, } /* Atomically replace the old file with the new hard link. */ - if (rename(tempLink.c_str(), path.c_str()) == -1) { + try { + moveFile(tempLink, path); + } catch (SysError & e) { if (unlink(tempLink.c_str()) == -1) printError("unable to unlink '%1%'", tempLink); if (errno == EMLINK) { @@ -240,7 +242,7 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats, debug("'%s' has reached maximum number of links", linkPath); return; } - throw SysError("cannot rename '%1%' to '%2%'", tempLink, path); + throw; } stats.filesLinked++; |