Shortcut already-hardlinked files
If an inode in the Nix store has more than 1 link, it probably means that it was linked into .links/ by us. If so, skip. There's a possibility that something else hardlinked the file, so it would be nice to be able to override this. Also, by looking at the number of hardlinks for each of the files in .links/, you can get deduplication numbers and space savings.
This commit is contained in:
parent
aa9b1cf48e
commit
a84f503d86
|
@ -71,6 +71,16 @@ void LocalStore::optimisePath_(OptimiseStats & stats, const Path & path)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stats.totalFiles++;
|
||||||
|
|
||||||
|
/* If a store inode has 2 or more links we presume that it was
|
||||||
|
already linked by us */
|
||||||
|
/* TODO: allow overriding this behavior */
|
||||||
|
if (st.st_nlink > 1) {
|
||||||
|
printMsg(lvlDebug, format("`%1%' is already linked, with %2% other file(s).") % path % (st.st_nlink - 2));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Hash the file. Note that hashPath() returns the hash over the
|
/* Hash the file. Note that hashPath() returns the hash over the
|
||||||
NAR serialisation, which includes the execute bit on the file.
|
NAR serialisation, which includes the execute bit on the file.
|
||||||
Thus, executable and non-executable files with the same
|
Thus, executable and non-executable files with the same
|
||||||
|
@ -81,7 +91,6 @@ void LocalStore::optimisePath_(OptimiseStats & stats, const Path & path)
|
||||||
contents of the symlink (i.e. the result of readlink()), not
|
contents of the symlink (i.e. the result of readlink()), not
|
||||||
the contents of the target (which may not even exist). */
|
the contents of the target (which may not even exist). */
|
||||||
Hash hash = hashPath(htSHA256, path).first;
|
Hash hash = hashPath(htSHA256, path).first;
|
||||||
stats.totalFiles++;
|
|
||||||
printMsg(lvlDebug, format("`%1%' has hash `%2%'") % path % printHash(hash));
|
printMsg(lvlDebug, format("`%1%' has hash `%2%'") % path % printHash(hash));
|
||||||
|
|
||||||
/* Check if this is a known hash. */
|
/* Check if this is a known hash. */
|
||||||
|
|
Loading…
Reference in a new issue