summaryrefslogtreecommitdiff
path: root/nix
diff options
context:
space:
mode:
Diffstat (limited to 'nix')
-rw-r--r--nix/libstore/build.cc3
-rw-r--r--nix/libstore/gc.cc4
-rw-r--r--nix/libstore/globals.cc4
-rw-r--r--nix/libstore/local-store.cc7
-rw-r--r--nix/libstore/local-store.hh3
-rw-r--r--nix/libstore/optimise-store.cc15
-rw-r--r--nix/libutil/util.cc9
7 files changed, 27 insertions, 18 deletions
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index 5697ae5a43..f6431bb726 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -3102,7 +3102,8 @@ void SubstitutionGoal::finished()
throw Error(format("unknown hash algorithm in `%1%'") % hashStr);
case htSHA256:
hash.first = parseHash16or32(hashType, string(hashStr, n + 1));
- hash.second = std::atoi(statusList[2].c_str());
+ if (!string2Int(statusList[2], hash.second))
+ throw Error(format("invalid nar size for '%1%' substitute") % storePath);
break;
default:
/* The database only stores SHA256 hashes, so compute it. */
diff --git a/nix/libstore/gc.cc b/nix/libstore/gc.cc
index e1d0765154..16519116e4 100644
--- a/nix/libstore/gc.cc
+++ b/nix/libstore/gc.cc
@@ -606,7 +606,9 @@ void LocalStore::removeUnusedLinks(const GCState & state)
throw SysError(format("statting `%1%'") % path);
#endif
- if (st.st_nlink != 1) {
+ /* Drop links for files smaller than 'deduplicationMinSize', even if
+ they have more than one hard link. */
+ if (st.st_nlink != 1 && st.st_size >= deduplicationMinSize) {
actualSize += st.st_size;
unsharedSize += (st.st_nlink - 1) * st.st_size;
continue;
diff --git a/nix/libstore/globals.cc b/nix/libstore/globals.cc
index 0cc001fbe4..d4f9a46a74 100644
--- a/nix/libstore/globals.cc
+++ b/nix/libstore/globals.cc
@@ -45,11 +45,7 @@ Settings::Settings()
useChroot = false;
impersonateLinux26 = false;
keepLog = true;
-#if HAVE_BZLIB_H
- logCompression = COMPRESSION_BZIP2;
-#else
logCompression = COMPRESSION_GZIP;
-#endif
maxLogSize = 0;
cacheFailure = false;
pollInterval = 5;
diff --git a/nix/libstore/local-store.cc b/nix/libstore/local-store.cc
index 675d1ba66f..0883a4bbce 100644
--- a/nix/libstore/local-store.cc
+++ b/nix/libstore/local-store.cc
@@ -839,7 +839,8 @@ template<class T> T LocalStore::getIntLineFromSubstituter(Agent & run)
{
string s = getLineFromSubstituter(run);
T res;
- if (!string2Int(s, res)) throw Error("integer expected from stream");
+ if (!string2Int(s, res))
+ throw Error(format("integer expected from stream: %1%") % s);
return res;
}
@@ -907,8 +908,8 @@ void LocalStore::querySubstitutablePathInfos(PathSet & paths, SubstitutablePathI
assertStorePath(p);
info.references.insert(p);
}
- info.downloadSize = getIntLineFromSubstituter<long long>(run);
- info.narSize = getIntLineFromSubstituter<long long>(run);
+ info.downloadSize = getIntLineFromSubstituter<unsigned long long>(run);
+ info.narSize = getIntLineFromSubstituter<unsigned long long>(run);
}
}
diff --git a/nix/libstore/local-store.hh b/nix/libstore/local-store.hh
index 9ba37219da..20d3c3c893 100644
--- a/nix/libstore/local-store.hh
+++ b/nix/libstore/local-store.hh
@@ -292,4 +292,7 @@ void canonicaliseTimestampAndPermissions(const Path & path);
MakeError(PathInUse, Error);
+/* Size below which a file is not considered for deduplication. */
+extern const size_t deduplicationMinSize;
+
}
diff --git a/nix/libstore/optimise-store.cc b/nix/libstore/optimise-store.cc
index eb303ab4c3..9fd6f3cb35 100644
--- a/nix/libstore/optimise-store.cc
+++ b/nix/libstore/optimise-store.cc
@@ -15,6 +15,9 @@
namespace nix {
+/* Any file smaller than this is not considered for deduplication.
+ Keep in sync with (guix store deduplication). */
+const size_t deduplicationMinSize = 8192;
static void makeWritable(const Path & path)
{
@@ -105,12 +108,12 @@ void LocalStore::optimisePath_(OptimiseStats & stats, const Path & path, InodeHa
return;
}
- /* We can hard link regular files and maybe symlinks. */
- if (!S_ISREG(st.st_mode)
-#if CAN_LINK_SYMLINK
- && !S_ISLNK(st.st_mode)
-#endif
- ) return;
+ /* We can hard link regular files (and maybe symlinks), but do that only
+ for files larger than some threshold. This avoids adding too many
+ entries to '.links', which would slow down 'removeUnusedLinks' while
+ saving little space. */
+ if (!S_ISREG(st.st_mode) || ((size_t) st.st_size) < deduplicationMinSize)
+ return;
/* Sometimes SNAFUs can cause files in the store to be
modified, in particular when running programs as root under
diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc
index 69f1c634a9..4d3780e3c2 100644
--- a/nix/libutil/util.cc
+++ b/nix/libutil/util.cc
@@ -337,12 +337,15 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed, size
for (auto & i : readDirectory(path))
_deletePath(path + "/" + i.name, bytesFreed, linkThreshold);
}
+
+ int ret;
+ ret = S_ISDIR(st.st_mode) ? rmdir(path.c_str()) : unlink(path.c_str());
+ if (ret == -1)
+ throw SysError(format("cannot unlink `%1%'") % path);
+
#undef st_mode
#undef st_size
#undef st_nlink
-
- if (remove(path.c_str()) == -1)
- throw SysError(format("cannot unlink `%1%'") % path);
}