1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

Merge pull request #14108 from fzakaria/fzakaria/shellcheck-multiple-3

shellcheck fixes for tests/functional/local-overlay-store
This commit is contained in:
Jörg Thalheim 2025-09-29 09:58:07 +02:00 committed by GitHub
commit 738d141dd9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 69 additions and 72 deletions

View file

@ -122,29 +122,6 @@
''^tests/functional/install-darwin\.sh$'' ''^tests/functional/install-darwin\.sh$''
''^tests/functional/legacy-ssh-store\.sh$'' ''^tests/functional/legacy-ssh-store\.sh$''
''^tests/functional/linux-sandbox\.sh$'' ''^tests/functional/linux-sandbox\.sh$''
''^tests/functional/local-overlay-store/add-lower-inner\.sh$''
''^tests/functional/local-overlay-store/add-lower\.sh$''
''^tests/functional/local-overlay-store/bad-uris\.sh$''
''^tests/functional/local-overlay-store/build-inner\.sh$''
''^tests/functional/local-overlay-store/build\.sh$''
''^tests/functional/local-overlay-store/check-post-init-inner\.sh$''
''^tests/functional/local-overlay-store/check-post-init\.sh$''
''^tests/functional/local-overlay-store/common\.sh$''
''^tests/functional/local-overlay-store/delete-duplicate-inner\.sh$''
''^tests/functional/local-overlay-store/delete-duplicate\.sh$''
''^tests/functional/local-overlay-store/delete-refs-inner\.sh$''
''^tests/functional/local-overlay-store/delete-refs\.sh$''
''^tests/functional/local-overlay-store/gc-inner\.sh$''
''^tests/functional/local-overlay-store/gc\.sh$''
''^tests/functional/local-overlay-store/optimise-inner\.sh$''
''^tests/functional/local-overlay-store/optimise\.sh$''
''^tests/functional/local-overlay-store/redundant-add-inner\.sh$''
''^tests/functional/local-overlay-store/redundant-add\.sh$''
''^tests/functional/local-overlay-store/remount\.sh$''
''^tests/functional/local-overlay-store/stale-file-handle-inner\.sh$''
''^tests/functional/local-overlay-store/stale-file-handle\.sh$''
''^tests/functional/local-overlay-store/verify-inner\.sh$''
''^tests/functional/local-overlay-store/verify\.sh$''
''^tests/functional/logging\.sh$'' ''^tests/functional/logging\.sh$''
''^tests/functional/misc\.sh$'' ''^tests/functional/misc\.sh$''
''^tests/functional/multiple-outputs\.sh$'' ''^tests/functional/multiple-outputs\.sh$''

View file

@ -1,3 +1,4 @@
# shellcheck shell=bash
source common.sh source common.sh
source ../common/init.sh source ../common/init.sh

View file

@ -1,3 +1,4 @@
# shellcheck shell=bash
source common.sh source common.sh
source ../common/init.sh source ../common/init.sh
@ -5,7 +6,7 @@ requireEnvironment
setupConfig setupConfig
setupStoreDirs setupStoreDirs
mkdir -p $TEST_ROOT/bad_test mkdir -p "$TEST_ROOT"/bad_test
badTestRoot=$TEST_ROOT/bad_test badTestRoot=$TEST_ROOT/bad_test
storeBadRoot="local-overlay://?root=$badTestRoot&lower-store=$storeA&upper-layer=$storeBTop" storeBadRoot="local-overlay://?root=$badTestRoot&lower-store=$storeA&upper-layer=$storeBTop"
storeBadLower="local-overlay://?root=$storeBRoot&lower-store=$badTestRoot&upper-layer=$storeBTop" storeBadLower="local-overlay://?root=$storeBRoot&lower-store=$badTestRoot&upper-layer=$storeBTop"
@ -18,7 +19,8 @@ declare -a storesBad=(
TODO_NixOS TODO_NixOS
for i in "${storesBad[@]}"; do for i in "${storesBad[@]}"; do
echo $i echo "$i"
# shellcheck disable=SC2119
execUnshare <<EOF execUnshare <<EOF
source common.sh source common.sh
setupStoreDirs setupStoreDirs

View file

@ -18,13 +18,13 @@ mountOverlayfs
### Do a build in overlay store ### Do a build in overlay store
path=$(nix-build ../hermetic.nix --arg busybox $busybox --arg seed 2 --store "$storeB" --no-out-link) path=$(nix-build ../hermetic.nix --arg busybox "$busybox" --arg seed 2 --store "$storeB" --no-out-link)
# Checking for path in lower layer (should fail) # Checking for path in lower layer (should fail)
expect 1 stat $(toRealPath "$storeA/nix/store" "$path") expect 1 stat "$(toRealPath "$storeA/nix/store" "$path")"
# Checking for path in upper layer # Checking for path in upper layer
stat $(toRealPath "$storeBTop" "$path") stat "$(toRealPath "$storeBTop" "$path")"
# Verifying path in overlay store # Verifying path in overlay store
nix-store --verify-path --store "$storeB" "$path" nix-store --verify-path --store "$storeB" "$path"

View file

@ -1,3 +1,4 @@
# shellcheck shell=bash
source common.sh source common.sh
source ../common/init.sh source ../common/init.sh

View file

@ -19,41 +19,41 @@ mountOverlayfs
### Check status ### Check status
# Checking for path in lower layer # Checking for path in lower layer
stat $(toRealPath "$storeA/nix/store" "$pathInLowerStore") stat "$(toRealPath "$storeA/nix/store" "$pathInLowerStore")"
# Checking for path in upper layer (should fail) # Checking for path in upper layer (should fail)
expect 1 stat $(toRealPath "$storeBTop" "$pathInLowerStore") expect 1 stat "$(toRealPath "$storeBTop" "$pathInLowerStore")"
# Checking for path in overlay store matching lower layer # Checking for path in overlay store matching lower layer
diff $(toRealPath "$storeA/nix/store" "$pathInLowerStore") $(toRealPath "$storeBRoot/nix/store" "$pathInLowerStore") diff "$(toRealPath "$storeA/nix/store" "$pathInLowerStore")" "$(toRealPath "$storeBRoot/nix/store" "$pathInLowerStore")"
# Checking requisites query agreement # Checking requisites query agreement
[[ \ [[ \
$(nix-store --store $storeA --query --requisites $drvPath) \ $(nix-store --store "$storeA" --query --requisites "$drvPath") \
== \ == \
$(nix-store --store $storeB --query --requisites $drvPath) \ $(nix-store --store "$storeB" --query --requisites "$drvPath") \
]] ]]
# Checking referrers query agreement # Checking referrers query agreement
busyboxStore=$(nix store --store $storeA add-path $busybox) busyboxStore=$(nix store --store "$storeA" add-path "$busybox")
[[ \ [[ \
$(nix-store --store $storeA --query --referrers $busyboxStore) \ $(nix-store --store "$storeA" --query --referrers "$busyboxStore") \
== \ == \
$(nix-store --store $storeB --query --referrers $busyboxStore) \ $(nix-store --store "$storeB" --query --referrers "$busyboxStore") \
]] ]]
# Checking derivers query agreement # Checking derivers query agreement
[[ \ [[ \
$(nix-store --store $storeA --query --deriver $pathInLowerStore) \ $(nix-store --store "$storeA" --query --deriver "$pathInLowerStore") \
== \ == \
$(nix-store --store $storeB --query --deriver $pathInLowerStore) \ $(nix-store --store "$storeB" --query --deriver "$pathInLowerStore") \
]] ]]
# Checking outputs query agreement # Checking outputs query agreement
[[ \ [[ \
$(nix-store --store $storeA --query --outputs $drvPath) \ $(nix-store --store "$storeA" --query --outputs "$drvPath") \
== \ == \
$(nix-store --store $storeB --query --outputs $drvPath) \ $(nix-store --store "$storeB" --query --outputs "$drvPath") \
]] ]]
# Verifying path in lower layer # Verifying path in lower layer
@ -62,10 +62,10 @@ nix-store --verify-path --store "$storeA" "$pathInLowerStore"
# Verifying path in merged-store # Verifying path in merged-store
nix-store --verify-path --store "$storeB" "$pathInLowerStore" nix-store --verify-path --store "$storeB" "$pathInLowerStore"
hashPart=$(echo $pathInLowerStore | sed "s^${NIX_STORE_DIR:-/nix/store}/^^" | sed 's/-.*//') hashPart=$(echo "$pathInLowerStore" | sed "s^${NIX_STORE_DIR:-/nix/store}/^^" | sed 's/-.*//')
# Lower store can find from hash part # Lower store can find from hash part
[[ $(nix store --store $storeA path-from-hash-part $hashPart) == $pathInLowerStore ]] [[ $(nix store --store "$storeA" path-from-hash-part "$hashPart") == "$pathInLowerStore" ]]
# merged store can find from hash part # merged store can find from hash part
[[ $(nix store --store $storeB path-from-hash-part $hashPart) == $pathInLowerStore ]] [[ $(nix store --store "$storeB" path-from-hash-part "$hashPart") == "$pathInLowerStore" ]]

View file

@ -1,3 +1,4 @@
# shellcheck shell=bash
source common.sh source common.sh
source ../common/init.sh source ../common/init.sh

View file

@ -1,3 +1,4 @@
# shellcheck shell=bash
source ../common/vars.sh source ../common/vars.sh
source ../common/functions.sh source ../common/functions.sh
@ -54,6 +55,7 @@ setupStoreDirs () {
storeA="$storeVolume/store-a" storeA="$storeVolume/store-a"
storeBTop="$storeVolume/store-b" storeBTop="$storeVolume/store-b"
storeBRoot="$storeVolume/merged-store" storeBRoot="$storeVolume/merged-store"
# shellcheck disable=SC2034
storeB="local-overlay://?root=$storeBRoot&lower-store=$storeA&upper-layer=$storeBTop" storeB="local-overlay://?root=$storeBRoot&lower-store=$storeA&upper-layer=$storeBTop"
# Creating testing directories # Creating testing directories
mkdir -p "$storeVolume"/{store-a/nix/store,store-b,merged-store/nix/store,workdir} mkdir -p "$storeVolume"/{store-a/nix/store,store-b,merged-store/nix/store,workdir}
@ -69,8 +71,10 @@ mountOverlayfs () {
|| skipTest "overlayfs is not supported" || skipTest "overlayfs is not supported"
cleanupOverlay () { cleanupOverlay () {
# shellcheck disable=2317
umount -n "$storeBRoot/nix/store" umount -n "$storeBRoot/nix/store"
rm -r $storeVolume/workdir # shellcheck disable=2317
rm -r "$storeVolume"/workdir
} }
trap cleanupOverlay EXIT trap cleanupOverlay EXIT
} }
@ -82,7 +86,8 @@ remountOverlayfs () {
toRealPath () { toRealPath () {
storeDir=$1; shift storeDir=$1; shift
storePath=$1; shift storePath=$1; shift
echo $storeDir$(echo $storePath | sed "s^${NIX_STORE_DIR:-/nix/store}^^") # shellcheck disable=SC2001
echo "$storeDir""$(echo "$storePath" | sed "s^${NIX_STORE_DIR:-/nix/store}^^")"
} }
initLowerStore () { initLowerStore () {
@ -90,8 +95,9 @@ initLowerStore () {
nix-store --store "$storeA" --add ../dummy nix-store --store "$storeA" --add ../dummy
# Build something in lower store # Build something in lower store
drvPath=$(nix-instantiate --store $storeA ../hermetic.nix --arg withFinalRefs true --arg busybox "$busybox" --arg seed 1) drvPath=$(nix-instantiate --store "$storeA" ../hermetic.nix --arg withFinalRefs true --arg busybox "$busybox" --arg seed 1)
pathInLowerStore=$(nix-store --store "$storeA" --realise $drvPath) # shellcheck disable=SC2034
pathInLowerStore=$(nix-store --store "$storeA" --realise "$drvPath")
} }
addTextToStore() { addTextToStore() {

View file

@ -1,3 +1,4 @@
# shellcheck shell=bash
source common.sh source common.sh
source ../common/init.sh source ../common/init.sh

View file

@ -15,6 +15,7 @@ initLowerStore
mountOverlayfs mountOverlayfs
export NIX_REMOTE="$storeB" export NIX_REMOTE="$storeB"
# shellcheck disable=SC2034
stateB="$storeBRoot/nix/var/nix" stateB="$storeBRoot/nix/var/nix"
hermetic=$(nix-build ../hermetic.nix --no-out-link --arg busybox "$busybox" --arg withFinalRefs true --arg seed 2) hermetic=$(nix-build ../hermetic.nix --no-out-link --arg busybox "$busybox" --arg withFinalRefs true --arg seed 2)
input1=$(nix-build ../hermetic.nix --no-out-link --arg busybox "$busybox" --arg withFinalRefs true --arg seed 2 -A passthru.input1 -j0) input1=$(nix-build ../hermetic.nix --no-out-link --arg busybox "$busybox" --arg withFinalRefs true --arg seed 2 -A passthru.input1 -j0)
@ -22,18 +23,18 @@ input2=$(nix-build ../hermetic.nix --no-out-link --arg busybox "$busybox" --arg
input3=$(nix-build ../hermetic.nix --no-out-link --arg busybox "$busybox" --arg withFinalRefs true --arg seed 2 -A passthru.input3 -j0) input3=$(nix-build ../hermetic.nix --no-out-link --arg busybox "$busybox" --arg withFinalRefs true --arg seed 2 -A passthru.input3 -j0)
# Can't delete because referenced # Can't delete because referenced
expectStderr 1 nix-store --delete $input1 | grepQuiet "Cannot delete path" expectStderr 1 nix-store --delete "$input1" | grepQuiet "Cannot delete path"
expectStderr 1 nix-store --delete $input2 | grepQuiet "Cannot delete path" expectStderr 1 nix-store --delete "$input2" | grepQuiet "Cannot delete path"
expectStderr 1 nix-store --delete $input3 | grepQuiet "Cannot delete path" expectStderr 1 nix-store --delete "$input3" | grepQuiet "Cannot delete path"
# These same paths are referenced in the lower layer (by the seed 1 # These same paths are referenced in the lower layer (by the seed 1
# build done in `initLowerStore`). # build done in `initLowerStore`).
expectStderr 1 nix-store --store "$storeA" --delete $input2 | grepQuiet "Cannot delete path" expectStderr 1 nix-store --store "$storeA" --delete "$input2" | grepQuiet "Cannot delete path"
expectStderr 1 nix-store --store "$storeA" --delete $input3 | grepQuiet "Cannot delete path" expectStderr 1 nix-store --store "$storeA" --delete "$input3" | grepQuiet "Cannot delete path"
# Can delete # Can delete
nix-store --delete $hermetic nix-store --delete "$hermetic"
# Now unreferenced in upper layer, can delete # Now unreferenced in upper layer, can delete
nix-store --delete $input3 nix-store --delete "$input3"
nix-store --delete $input2 nix-store --delete "$input2"

View file

@ -1,3 +1,4 @@
# shellcheck shell=bash
source common.sh source common.sh
source ../common/init.sh source ../common/init.sh

View file

@ -21,24 +21,24 @@ outPath=$(nix-build ../hermetic.nix --no-out-link --arg busybox "$busybox" --arg
# Set a GC root. # Set a GC root.
mkdir -p "$stateB" mkdir -p "$stateB"
rm -f "$stateB/gcroots/foo" rm -f "$stateB/gcroots/foo"
ln -sf $outPath "$stateB/gcroots/foo" ln -sf "$outPath" "$stateB/gcroots/foo"
[ "$(nix-store -q --roots $outPath)" = "$stateB/gcroots/foo -> $outPath" ] [ "$(nix-store -q --roots "$outPath")" = "$stateB/gcroots/foo -> $outPath" ]
nix-store --gc --print-roots | grep $outPath nix-store --gc --print-roots | grep "$outPath"
nix-store --gc --print-live | grep $outPath nix-store --gc --print-live | grep "$outPath"
if nix-store --gc --print-dead | grep -E $outPath$; then false; fi if nix-store --gc --print-dead | grep -E "$outPath"$; then false; fi
nix-store --gc --print-dead nix-store --gc --print-dead
expect 1 nix-store --delete $outPath expect 1 nix-store --delete "$outPath"
test -e "$storeBRoot/$outPath" test -e "$storeBRoot/$outPath"
shopt -s nullglob shopt -s nullglob
for i in $storeBRoot/*; do for i in "$storeBRoot"/*; do
if [[ $i =~ /trash ]]; then continue; fi # compat with old daemon if [[ $i =~ /trash ]]; then continue; fi # compat with old daemon
touch $i.lock touch "$i".lock
touch $i.chroot touch "$i".chroot
done done
nix-collect-garbage nix-collect-garbage
@ -51,7 +51,8 @@ rm "$stateB/gcroots/foo"
nix-collect-garbage nix-collect-garbage
# Check that the output has been GC'd. # Check that the output has been GC'd.
test ! -e $outPath test ! -e "$outPath"
# Check that the store is empty. # Check that the store is empty.
# shellcheck disable=SC2012
[ "$(ls -1 "$storeBTop" | wc -l)" = "0" ] [ "$(ls -1 "$storeBTop" | wc -l)" = "0" ]

View file

@ -1,3 +1,4 @@
# shellcheck shell=bash
source common.sh source common.sh
source ../common/init.sh source ../common/init.sh

View file

@ -38,8 +38,8 @@ overlayPath="$storeBRoot/nix/store/$dupFilename"
lowerInode=$(stat -c %i "$lowerPath") lowerInode=$(stat -c %i "$lowerPath")
upperInode=$(stat -c %i "$upperPath") upperInode=$(stat -c %i "$upperPath")
overlayInode=$(stat -c %i "$overlayPath") overlayInode=$(stat -c %i "$overlayPath")
[[ $upperInode == $overlayInode ]] [[ $upperInode == "$overlayInode" ]]
[[ $upperInode != $lowerInode ]] [[ $upperInode != "$lowerInode" ]]
# Run optimise to deduplicate store paths # Run optimise to deduplicate store paths
nix-store --store "$storeB" --optimise nix-store --store "$storeB" --optimise

View file

@ -1,3 +1,4 @@
# shellcheck shell=bash
source common.sh source common.sh
source ../common/init.sh source ../common/init.sh

View file

@ -22,14 +22,14 @@ mountOverlayfs
pathInLowerStore=$(nix-store --store "$storeA" --add ../dummy) pathInLowerStore=$(nix-store --store "$storeA" --add ../dummy)
# upper layer should not have it # upper layer should not have it
expect 1 stat $(toRealPath "$storeBTop/nix/store" "$pathInLowerStore") expect 1 stat "$(toRealPath "$storeBTop/nix/store" "$pathInLowerStore")"
pathFromB=$(nix-store --store "$storeB" --add ../dummy) pathFromB=$(nix-store --store "$storeB" --add ../dummy)
[[ $pathInLowerStore == $pathFromB ]] [[ $pathInLowerStore == "$pathFromB" ]]
# lower store should have it from before # lower store should have it from before
stat $(toRealPath "$storeA/nix/store" "$pathInLowerStore") stat "$(toRealPath "$storeA/nix/store" "$pathInLowerStore")"
# upper layer should still not have it (no redundant copy) # upper layer should still not have it (no redundant copy)
expect 1 stat $(toRealPath "$storeBTop" "$pathInLowerStore") expect 1 stat "$(toRealPath "$storeBTop" "$pathInLowerStore")"

View file

@ -1,3 +1,4 @@
# shellcheck shell=bash
source common.sh source common.sh
source ../common/init.sh source ../common/init.sh

View file

@ -1,3 +1,4 @@
# shellcheck shell=bash
source common.sh source common.sh
source ../common/init.sh source ../common/init.sh

View file

@ -20,7 +20,7 @@ mountOverlayfs
## Initialise stores for test ## Initialise stores for test
# Realise a derivation from the lower store to propagate paths to overlay DB # Realise a derivation from the lower store to propagate paths to overlay DB
nix-store --store "$storeB" --realise $drvPath nix-store --store "$storeB" --realise "$drvPath"
# Also ensure dummy file exists in overlay DB # Also ensure dummy file exists in overlay DB
dummyPath=$(nix-store --store "$storeB" --add ../dummy) dummyPath=$(nix-store --store "$storeB" --add ../dummy)

View file

@ -1,3 +1,4 @@
# shellcheck shell=bash
source common.sh source common.sh
source ../common/init.sh source ../common/init.sh