From 7033c7692ccbbbad8f7b9952015de071a5588e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sat, 11 Jan 2020 18:46:23 +0100 Subject: daemon: Account for deleted store files when deduplication is on. Previously, a store item that is a regular file would not be accounted for in the 'bytesFreed' value computed by 'deletePath' because its 'st_nlink' count would always be >= 2. This commit fixes that. * nix/libutil/util.hh (deletePath): Add optional 'linkThreshold' argument. * nix/libutil/util.cc (_deletePath): Add 'linkThreshold' argument and honor it. Pass it down in recursive call. (deletePath): Add 'linkThreshold' and honor it. * nix/libstore/gc.cc (LocalStore::deleteGarbage): Pass 'linkThreshold' argument to 'deletePath', with a value of 2 when PATH is a store item and deduplication is on. --- nix/libstore/gc.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'nix/libstore') diff --git a/nix/libstore/gc.cc b/nix/libstore/gc.cc index 29b75aa875..5043963fa2 100644 --- a/nix/libstore/gc.cc +++ b/nix/libstore/gc.cc @@ -392,7 +392,14 @@ bool LocalStore::isActiveTempFile(const GCState & state, void LocalStore::deleteGarbage(GCState & state, const Path & path) { unsigned long long bytesFreed; - deletePath(path, bytesFreed); + + /* When deduplication is on, store items always have at least two links: + the one at PATH, and one in /gnu/store/.links. In that case, increase + bytesFreed when PATH has two or fewer links. */ + size_t linkThreshold = + (settings.autoOptimiseStore && isStorePath(path)) ? 2 : 1; + + deletePath(path, bytesFreed, linkThreshold); state.results.bytesFreed += bytesFreed; } -- cgit v1.2.3