From 97b2a10ff10f20fdae2cdae6a01b51f1fdbb2a79 Mon Sep 17 00:00:00 2001 From: Marco Vermeulen Date: Fri, 12 Jul 2013 13:58:42 +0100 Subject: [PATCH] Improve flush by making it more resilient. --- src/main/bash/gvm-flush.sh | 18 ++++++++++++------ src/test/cucumber/gvm/flush.feature | 26 ++++++++++++++------------ src/test/steps/gvm/flush_steps.groovy | 2 +- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/main/bash/gvm-flush.sh b/src/main/bash/gvm-flush.sh index 42b7c039..2b9b357e 100644 --- a/src/main/bash/gvm-flush.sh +++ b/src/main/bash/gvm-flush.sh @@ -31,17 +31,24 @@ function __gvmtool_cleanup_folder { unset GVM_CLEANUP_COUNT } - function __gvmtool_flush { QUALIFIER="$1" case "$QUALIFIER" in candidates) - rm "$GVM_DIR/var/candidates" - echo "Candidates have been flushed." + if [[ -f "${GVM_DIR}/var/candidates" ]]; then + rm "${GVM_DIR}/var/candidates" + echo "Candidates have been flushed." + else + echo "No candidate list found so not flushed." + fi ;; broadcast) - rm "$GVM_DIR/var/broadcast" - echo "Broadcast has been flushed." + if [[ -f "${GVM_DIR}/var/broadcast" ]]; then + rm "${GVM_DIR}/var/broadcast" + echo "Broadcast has been flushed." + else + echo "No prior broadcast found so not flushed." + fi ;; archives) __gvmtool_cleanup_folder "archives" @@ -56,5 +63,4 @@ function __gvmtool_flush { echo "Stop! Please specify what you want to flush." ;; esac - } \ No newline at end of file diff --git a/src/test/cucumber/gvm/flush.feature b/src/test/cucumber/gvm/flush.feature index 80010326..558e5eb5 100644 --- a/src/test/cucumber/gvm/flush.feature +++ b/src/test/cucumber/gvm/flush.feature @@ -7,34 +7,36 @@ Feature: Flush When I enter "gvm flush" Then I see "Stop! Please specify what you want to flush." - Scenario: Clear out my Candidate List + Scenario: Clear out the Candidate List Given the candidate "grails" is known locally When I enter "gvm flush candidates" Then no candidates are know locally And I see "Candidates have been flushed." - Scenario: Clean up my current broadcast + Scenario: Clear out an uninitialised Candidate List + Given I enter "gvm flush candidates" + When I enter "gvm flush candidates" + Then I see "No candidate list found so not flushed." + + Scenario: Clean up the current Broadcast Given a prior Broadcast "This is an old broadcast" was issued When I enter "gvm flush broadcast" Then no broadcast message can be found And I see "Broadcast has been flushed." - Scenario: Clear out my cached Archives + Scenario: Clean up an uninitialised Broadcast + Given I enter "gvm flush broadcast" + When I enter "gvm flush broadcast" + Then I see "No prior broadcast found so not flushed." + + Scenario: Clear out the cached Archives Given the archive "grails-1.3.9.zip" has been cached When I enter "gvm flush archives" Then no archives are cached And I see "1 archive(s) flushed, freeing 4.0K" - Scenario: Clear out my temporary space + Scenario: Clear out the temporary space Given the file "res-1.2.0.zip" in temporary storage When I enter "gvm flush temp" Then no "res-1.2.0.zip" file is present in temporary storage And I see "1 archive(s) flushed, freeing 4.0K" - - Scenario: Clear out my temporary space - Given the file "res-1.2.0.zip" in temporary storage - When I enter "gvm flush tmp" - Then no "res-1.2.0.zip" file is present in temporary storage - And I see "1 archive(s) flushed, freeing 4.0K" - - diff --git a/src/test/steps/gvm/flush_steps.groovy b/src/test/steps/gvm/flush_steps.groovy index bc1ddb36..9bc9e7ce 100644 --- a/src/test/steps/gvm/flush_steps.groovy +++ b/src/test/steps/gvm/flush_steps.groovy @@ -23,4 +23,4 @@ Given(~'^the file "([^"]*)" in temporary storage$') { String fileName -> } Then(~'^no "([^"]*)" file is present in temporary storage$') { String fileName -> assert ! new File(tmpDir, fileName).exists() -} \ No newline at end of file +}