2023-07-26 14:33:26 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
|
|
|
source common.sh
|
|
|
|
|
|
|
|
# Avoid store dir being inside sandbox build-dir
|
|
|
|
unset NIX_STORE_DIR
|
|
|
|
unset NIX_STATE_DIR
|
|
|
|
|
2023-12-11 20:30:40 +02:00
|
|
|
setupStoreDirs
|
2023-07-26 14:33:26 +03:00
|
|
|
|
|
|
|
initLowerStore
|
|
|
|
|
|
|
|
mountOverlayfs
|
|
|
|
|
|
|
|
# Add to overlay before lower to ensure file is duplicated
|
2023-07-26 16:29:36 +03:00
|
|
|
upperPath=$(nix-store --store "$storeB" --add delete-duplicate.sh)
|
|
|
|
lowerPath=$(nix-store --store "$storeA" --add delete-duplicate.sh)
|
2023-07-26 14:33:26 +03:00
|
|
|
[[ "$upperPath" = "$lowerPath" ]]
|
|
|
|
|
|
|
|
# Check there really are two files with different inodes
|
|
|
|
upperInode=$(stat -c %i "$storeBRoot/$upperPath")
|
|
|
|
lowerInode=$(stat -c %i "$storeA/$lowerPath")
|
|
|
|
[[ "$upperInode" != "$lowerInode" ]]
|
|
|
|
|
|
|
|
# Now delete file via the overlay store
|
2023-07-26 16:05:54 +03:00
|
|
|
nix-store --store "$storeB&remount-hook=$PWD/remount.sh" --delete "$upperPath"
|
2023-07-26 14:33:26 +03:00
|
|
|
|
|
|
|
# Check there is no longer a file in upper layer
|
|
|
|
expect 1 stat "$storeBTop/${upperPath##/nix/store/}"
|
|
|
|
|
|
|
|
# Check that overlay file is now the one in lower layer
|
|
|
|
upperInode=$(stat -c %i "$storeBRoot/$upperPath")
|
|
|
|
lowerInode=$(stat -c %i "$storeA/$lowerPath")
|
|
|
|
[[ "$upperInode" = "$lowerInode" ]]
|