Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instance#clean! - do not remove downloads #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions exe/fcrepo_wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ options = {}

subtext = <<HELP
Commonly used command are:
clean : cleans all data from fedora based on configuration options
clean : stop and clean all data from fedora based on configuration options
purge : as in 'clean', but also includes download files
See 'fcrepo_wrapper COMMAND --help' for more information on a specific command.
HELP

Expand Down Expand Up @@ -59,6 +60,9 @@ subcommands = {
'clean' => OptionParser.new do |opts|
opts.banner = "Usage: clean"
end,
'purge' => OptionParser.new do |opts|
opts.banner = "Usage: purge"
end,
}

begin
Expand All @@ -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} ... "
Expand Down
16 changes: 9 additions & 7 deletions lib/fcrepo_wrapper/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, when FileUtils.remove_* is called with the force: true, it ignores any StdErr on failures. Hence, the File.exists? checks are removed here.


def configure
Expand Down