From 68c06d80f3fb0cdfb3775491dfdd11e1b1abf312 Mon Sep 17 00:00:00 2001 From: Angelica Date: Tue, 24 Sep 2024 15:36:46 -0400 Subject: [PATCH 1/3] Created a 'remove part_ file' test --- test/build/40_pull.bats | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/build/40_pull.bats b/test/build/40_pull.bats index 14c034d84..230a40fd2 100644 --- a/test/build/40_pull.bats +++ b/test/build/40_pull.bats @@ -555,3 +555,28 @@ EOF [[ $status -eq 1 ]] [[ $output = *'registry-1.docker.io:443/charliecloud/metadata:doesnotexist'* ]] } + +@test 'remove part_ files' { + export CH_IMAGE_STORAGE=/var/tmp/albug + + # create a part_ file + touch /var/tmp/albug/dlcache/part_PROBLEM + + # list images to invoke error + set +e + out=$(ch-image list 2>&1) + retcode=$? + set -e + + echo "--- return code: ${retcode}" + echo '--- output:' + echo "$out" + + # check if output errors + if [[ $retcode -ne 0 ]]; then + echo "fail: part_ file wasn't cleaned properly." + # Clean up the file if the test fails + rm /var/tmp/albug/dlcache/part_PROBLEM + exit 1 + fi +} From 1ffa087f7ea8dba9a2297e90a24495e48a17099d Mon Sep 17 00:00:00 2001 From: Angelica Date: Tue, 24 Sep 2024 16:54:53 -0400 Subject: [PATCH 2/3] Fixed cleanup function to use full path to part_ files --- lib/filesystem.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/filesystem.py b/lib/filesystem.py index 21c26aa79..88dccdeb6 100644 --- a/lib/filesystem.py +++ b/lib/filesystem.py @@ -1144,6 +1144,7 @@ def cleanup(self): part_ct = 0 for path in self.download_cache.glob("part_*"): path = Path(path) + path = self.download_cache // path.name ch.VERBOSE("deleting: %s" % path) path.unlink() part_ct += 1 From 2bd71864bd5655853c48f4259fc883c2467d9f2e Mon Sep 17 00:00:00 2001 From: Angelica Date: Wed, 25 Sep 2024 14:50:15 -0400 Subject: [PATCH 3/3] Made corrections to test --- test/build/40_pull.bats | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/test/build/40_pull.bats b/test/build/40_pull.bats index 230a40fd2..6acf18f4b 100644 --- a/test/build/40_pull.bats +++ b/test/build/40_pull.bats @@ -557,11 +557,15 @@ EOF } @test 'remove part_ files' { - export CH_IMAGE_STORAGE=/var/tmp/albug + export CH_IMAGE_STORAGE=/var/tmp/tmpdir + ch-image pull alpine + + # create directory + mkdir -p /var/tmp/tmpdir/dlcache + + # create a part_ file + touch /var/tmp/tmpdir/dlcache/part_PROBLEM - # create a part_ file - touch /var/tmp/albug/dlcache/part_PROBLEM - # list images to invoke error set +e out=$(ch-image list 2>&1) @@ -571,12 +575,13 @@ EOF echo "--- return code: ${retcode}" echo '--- output:' echo "$out" - + + # clean up the directory + rm -rf /var/tmp/tmpdir + # check if output errors if [[ $retcode -ne 0 ]]; then echo "fail: part_ file wasn't cleaned properly." - # Clean up the file if the test fails - rm /var/tmp/albug/dlcache/part_PROBLEM exit 1 fi }