diff options
author | elijah <elijah@riseup.net> | 2012-11-15 01:54:31 -0800 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2012-11-15 01:54:31 -0800 |
commit | 088b4f047f3d4b8e075e10277bfe5f94cb0b9af1 (patch) | |
tree | ab5debbef5c47c6ec615bb5719bc62f020889e3e /lib/leap_cli/util.rb | |
parent | 359c0b757f1dd52b63e08f8b67fa7fe7f1c0ba00 (diff) |
auto remove files/nodes/x when nodes/x.json doesn't exist anymore.
Diffstat (limited to 'lib/leap_cli/util.rb')
-rw-r--r-- | lib/leap_cli/util.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/leap_cli/util.rb b/lib/leap_cli/util.rb index 6b62be5..9b04894 100644 --- a/lib/leap_cli/util.rb +++ b/lib/leap_cli/util.rb @@ -1,5 +1,6 @@ require 'digest/md5' require 'paint' +require 'fileutils' module LeapCli @@ -197,6 +198,17 @@ module LeapCli end end + def remove_directory!(filepath) + filepath = Path.named_path(filepath) + if filepath !~ /^#{Regexp.escape(Path.provider)}/ || filepath =~ /\.\./ + raise "sanity check on rm -r did not pass for #{filepath}" + end + if File.directory?(filepath) + FileUtils.rm_r(filepath) + log :removed, filepath + end + end + def write_file!(filepath, contents) filepath = Path.named_path(filepath) ensure_dir File.dirname(filepath) |