[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
06/07: daemon: optimizePath: Detect some .links corruptions.
From: |
Ludovic Courtès |
Subject: |
06/07: daemon: optimizePath: Detect some .links corruptions. |
Date: |
Wed, 02 Dec 2015 17:39:11 +0000 |
civodul pushed a commit to branch master
in repository guix.
commit e134baae774eaa78e7ae8c3d87db50170f023536
Author: Eelco Dolstra <address@hidden>
Date: Mon Nov 9 20:48:09 2015 +0100
daemon: optimizePath: Detect some .links corruptions.
If automatic store optimisation is enabled, and a hard-linked file in
the store gets corrupted, then the corresponding .links entry will
also be corrupted. In that case, trying to repair with --repair or
--repair-path won't work, because the new "good" file will be replaced
by a hard link to the corrupted file. We can catch most of these cases
by doing a sanity-check on the file sizes.
---
nix/libstore/optimise-store.cc | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/nix/libstore/optimise-store.cc b/nix/libstore/optimise-store.cc
index c62b8e4..d7508b0 100644
--- a/nix/libstore/optimise-store.cc
+++ b/nix/libstore/optimise-store.cc
@@ -120,7 +120,7 @@ void LocalStore::optimisePath_(OptimiseStats & stats, const
Path & path, InodeHa
return;
}
- /* This can still happen on top-level files */
+ /* This can still happen on top-level files. */
if (st.st_nlink > 1 && inodeHash.count(st.st_ino)) {
printMsg(lvlDebug, format("`%1%' is already linked, with %2% other
file(s).") % path % (st.st_nlink - 2));
return;
@@ -141,6 +141,7 @@ void LocalStore::optimisePath_(OptimiseStats & stats, const
Path & path, InodeHa
/* Check if this is a known hash. */
Path linkPath = linksDir + "/" + printHash32(hash);
+ retry:
if (!pathExists(linkPath)) {
/* Nope, create a hard link in the links directory. */
if (link(path.c_str(), linkPath.c_str()) == 0) {
@@ -164,7 +165,13 @@ void LocalStore::optimisePath_(OptimiseStats & stats,
const Path & path, InodeHa
return;
}
- printMsg(lvlTalkative, format("linking `%1%' to `%2%'") % path % linkPath);
+ if (st.st_size != stLink.st_size) {
+ printMsg(lvlError, format("removing corrupted link ‘%1%’") % linkPath);
+ unlink(linkPath.c_str());
+ goto retry;
+ }
+
+ printMsg(lvlTalkative, format("linking ‘%1%’ to ‘%2%’") % path % linkPath);
/* Make the containing directory writable, but only if it's not
the store itself (we don't want or need to mess with its
- branch master updated (18b3151 -> 708d907), Ludovic Courtès, 2015/12/02
- 04/07: daemon: Support SHA-512 hashes., Ludovic Courtès, 2015/12/02
- 03/07: daemon: int2String -> std::to_string., Ludovic Courtès, 2015/12/02
- 07/07: daemon: Add 'buildMode' parameter to 'buildPaths' RPC., Ludovic Courtès, 2015/12/02
- 06/07: daemon: optimizePath: Detect some .links corruptions.,
Ludovic Courtès <=
- 05/07: daemon: Fix namespace issue., Ludovic Courtès, 2015/12/02
- 02/07: daemon: Filter build-chroot-dirs entries that conflict with derivation outputs., Ludovic Courtès, 2015/12/02
- 01/07: daemon: Prevent .chroot from being GC'ed when using LocalStore::buildDerivation(), Ludovic Courtès, 2015/12/02