From b615f50d6f2e6b2b0ed087d0b8f214aa3a2452b0 Mon Sep 17 00:00:00 2001 From: "Darren L. Weber, Ph.D" Date: Mon, 22 May 2017 13:20:32 -0700 Subject: [PATCH] Instance#clean! - option to remove downloads using purge command --- exe/fcrepo_wrapper | 15 +++++++++++++-- lib/fcrepo_wrapper/instance.rb | 16 +++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/exe/fcrepo_wrapper b/exe/fcrepo_wrapper index 7d71f59..a8beb27 100755 --- a/exe/fcrepo_wrapper +++ b/exe/fcrepo_wrapper @@ -7,7 +7,8 @@ options = {} subtext = < OptionParser.new do |opts| opts.banner = "Usage: clean" end, + 'purge' => OptionParser.new do |opts| + opts.banner = "Usage: purge" + end, } begin @@ -77,10 +81,17 @@ end instance = FcrepoWrapper.default_instance(options) -if command == 'clean' +case command +when 'clean' $stderr.puts "cleaning #{instance.instance_dir}..." instance.clean! exit 0 +when 'purge' + $stderr.puts "cleaning #{instance.instance_dir} and download files..." + instance.clean!(true) + exit 0 +else + exit 1 end $stderr.print "Starting Fedora #{instance.version} on port #{instance.port} ... " diff --git a/lib/fcrepo_wrapper/instance.rb b/lib/fcrepo_wrapper/instance.rb index 86f0d1d..87fef19 100644 --- a/lib/fcrepo_wrapper/instance.rb +++ b/lib/fcrepo_wrapper/instance.rb @@ -150,20 +150,22 @@ def options end ## - # Clean up any files fcrepo_wrapper may have downloaded - def clean! + # Clean up any files fcrepo_wrapper manages + def clean!(clean_downloads = false) stop remove_instance_dir! - FileUtils.remove_entry(config.download_path) if File.exists?(config.download_path) - FileUtils.remove_entry(config.tmp_save_dir, true) if File.exists? config.tmp_save_dir - md5.clean! - FileUtils.remove_entry(config.version_file) if File.exists? config.version_file + FileUtils.remove_entry(config.tmp_save_dir, true) + FileUtils.remove_file(config.version_file, true) + if clean_downloads + md5.clean! + FileUtils.remove_file(config.download_path, true) + end end ## # Clean up any files in the fcrepo instance dir def remove_instance_dir! - FileUtils.remove_entry(config.instance_dir, true) if File.exists? config.instance_dir + FileUtils.remove_entry(config.instance_dir, true) end def configure