mirror of
https://github.com/NixOS/nix
synced 2025-07-07 10:11:47 +02:00
Implement test for store path deduplication.
This commit is contained in:
parent
614efc1240
commit
a9510f9502
2 changed files with 39 additions and 10 deletions
|
@ -22,11 +22,12 @@ storeDirs () {
|
||||||
|
|
||||||
# Mounting Overlay Store
|
# Mounting Overlay Store
|
||||||
mountOverlayfs () {
|
mountOverlayfs () {
|
||||||
|
mergedStorePath="$TEST_ROOT/merged-store/nix/store"
|
||||||
mount -t overlay overlay \
|
mount -t overlay overlay \
|
||||||
-o lowerdir="$storeA/nix/store" \
|
-o lowerdir="$storeA/nix/store" \
|
||||||
-o upperdir="$storeBTop" \
|
-o upperdir="$storeBTop" \
|
||||||
-o workdir="$TEST_ROOT/workdir" \
|
-o workdir="$TEST_ROOT/workdir" \
|
||||||
"$TEST_ROOT/merged-store/nix/store" \
|
"$mergedStorePath" \
|
||||||
|| skipTest "overlayfs is not supported"
|
|| skipTest "overlayfs is not supported"
|
||||||
|
|
||||||
cleanupOverlay () {
|
cleanupOverlay () {
|
||||||
|
@ -36,6 +37,10 @@ mountOverlayfs () {
|
||||||
trap cleanupOverlay EXIT
|
trap cleanupOverlay EXIT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remountOverlayfs () {
|
||||||
|
mount -o remount "$mergedStorePath"
|
||||||
|
}
|
||||||
|
|
||||||
toRealPath () {
|
toRealPath () {
|
||||||
storeDir=$1; shift
|
storeDir=$1; shift
|
||||||
storePath=$1; shift
|
storePath=$1; shift
|
||||||
|
@ -54,12 +59,3 @@ initLowerStore () {
|
||||||
execUnshare () {
|
execUnshare () {
|
||||||
exec unshare --mount --map-root-user "$@"
|
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"
|
|
||||||
}
|
|
||||||
|
|
|
@ -16,4 +16,37 @@ initLowerStore
|
||||||
|
|
||||||
mountOverlayfs
|
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
|
nix-store --store "$storeB" --optimise
|
||||||
|
remountOverlayfs
|
||||||
|
|
||||||
|
stat "$lowerPath"
|
||||||
|
stat "$overlayPath"
|
||||||
|
expect 1 stat "$upperPath"
|
||||||
|
|
||||||
|
#expect 1 stat $(toRealPath "$storeA/nix/store" "$path")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue