1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 23:03:53 -04:00

Implement test for store path deduplication.

This commit is contained in:
Ben Radford 2023-07-19 11:23:54 +01:00
parent 614efc1240
commit a9510f9502
No known key found for this signature in database
GPG key ID: 9DF5D4640AB888D5
2 changed files with 39 additions and 10 deletions

View file

@ -22,11 +22,12 @@ storeDirs () {
# Mounting Overlay Store
mountOverlayfs () {
mergedStorePath="$TEST_ROOT/merged-store/nix/store"
mount -t overlay overlay \
-o lowerdir="$storeA/nix/store" \
-o upperdir="$storeBTop" \
-o workdir="$TEST_ROOT/workdir" \
"$TEST_ROOT/merged-store/nix/store" \
"$mergedStorePath" \
|| skipTest "overlayfs is not supported"
cleanupOverlay () {
@ -36,6 +37,10 @@ mountOverlayfs () {
trap cleanupOverlay EXIT
}
remountOverlayfs () {
mount -o remount "$mergedStorePath"
}
toRealPath () {
storeDir=$1; shift
storePath=$1; shift
@ -54,12 +59,3 @@ initLowerStore () {
execUnshare () {
exec unshare --mount --map-root-user "$@"
}
addTextToStore() {
storeDir=$1; shift
filename=$1; shift
content=$1; shift
filePath="$TEST_HOME/$filename"
echo "$content" > "$filePath"
nix-store --store "$storeDir" --add "$filePath"
}

View file

@ -16,4 +16,37 @@ initLowerStore
mountOverlayfs
# Create a file to add to store
dupFilePath="$TEST_ROOT/dup-file"
echo Duplicate > "$dupFilePath"
# Add it to the overlay store (it will be written to the upper layer)
dupFileStorePath=$(nix-store --store "$storeB" --add "$dupFilePath")
# Now add it to the lower store so the store path is duplicated
nix-store --store "$storeA" --add "$dupFilePath"
# Ensure overlayfs and layers and synchronised
remountOverlayfs
dupFilename="${dupFileStorePath#/nix/store}"
lowerPath="$storeA/$dupFileStorePath"
upperPath="$storeBTop/$dupFilename"
overlayPath="$mergedStorePath/$dupFilename"
# Check store path exists in both layers and overlay
lowerInode=$(stat -c %i "$lowerPath")
upperInode=$(stat -c %i "$upperPath")
overlayInode=$(stat -c %i "$overlayPath")
[[ $upperInode == $overlayInode ]]
[[ $upperInode != $lowerInode ]]
# Run optimise to deduplicate store paths
nix-store --store "$storeB" --optimise
remountOverlayfs
stat "$lowerPath"
stat "$overlayPath"
expect 1 stat "$upperPath"
#expect 1 stat $(toRealPath "$storeA/nix/store" "$path")