lib/eco-rake/shell/files.rb in eco-rake-0.2.4 vs lib/eco-rake/shell/files.rb in eco-rake-0.2.5
- old
+ new
@@ -7,28 +7,32 @@
# It creates directory `path` constructively.
# @note if any parent directory does not exist, it creates it as well.
def upsert_local_dir(path)
return if path.to_s.strip.empty?
return if File.directory?(path)
+
require 'fileutils'
puts "Creating directory '#{path}'"
FileUtils.mkdir_p(path)
end
# TODO: check delete status
def delete_file(*files, message: 'Deleting files:')
files = files.select {|file| File.exist?(file)}
return if files.empty?
+
puts message if message
+
files.each do |file|
File.delete(file)
puts " • #{file}" if message
end
end
def move_file(*files, folder:, message: 'Moving files:')
puts message if message
+
files.each do |file|
new_name = File.join(folder, File.basename(file))
File.name(file, new_name)
puts " • #{File.basename(file)}" if message
end
@@ -60,10 +64,11 @@
# Preserves the folder and the base name of `gpg_file` name
# and changes its extension to `csv`.
# @return [String]
def gpg_to_csv_filename(gpg_file)
return nil unless gpg_file
+
ext = gpg_file.split('.')[1..-1].join('.')
base = File.basename(gpg_file, ".#{ext}")
folder = File.dirname(gpg_file)
File.join(folder, "#{base}.csv")
end
@@ -74,9 +79,10 @@
File.mtime(file) < Time.now - days_to_seconds(days)
end
def days_to_seconds(days)
return nil unless days
+
days * DAY_SECONDS
end
end
end
end