class Vera::Safe

Public Class Methods

candidates_by_file_size(media_files, backup_media_files) click to toggle source
# File lib/vera/safe.rb, line 48
def self.candidates_by_file_size(media_files, backup_media_files)
  media_files.map do |media|
    {
      media: media,
      candidates: backup_media_files.select { |c| c.size == media.size }
    }
  end
end
candidates_by_partial_hash(media_files) click to toggle source
# File lib/vera/safe.rb, line 57
def self.candidates_by_partial_hash(media_files)
  media_files.map do |hash|
    media = hash[:media]
    file_found = hash[:candidates].find do |m|
      media.partial_hash == m.partial_hash
    end

    {
      media: media,
      file_found: file_found,
      found: !file_found.nil?
    }
  end
end
execute(options) click to toggle source
# File lib/vera/safe.rb, line 6
def self.execute(options)
  unless Exiftool.installed?
    puts "
      You need to install exiftool to use vera. You can run the following command to do it:
      bash <(curl -Ls https://git.io/JtbuH)
    "
    return
  end
  path = options.path
  path = Dir.pwd if options.path.nil?
  path = File.expand_path(path)
  backup_path = File.expand_path(options.backup)

  unless File.directory?(path)
    puts "#{path} is not a valid directory.".red
    return
  end

  unless File.directory?(backup_path)
    puts "#{backup_path} is not a valid directory.".red
    return
  end

  safe_to_delete_path? path, backup_path
end
filter_real_hash(hash) click to toggle source
# File lib/vera/safe.rb, line 114
def self.filter_real_hash(hash)
  {
    media: hash[:media],
    candidates: hash[:candidates].find do |m|
      media.real_hash == m.real_hash
    end
  }
end
print_folders(path, backup_path) click to toggle source
print_list_of_files(files, backup_dir) click to toggle source
print_number_of_files(media_files, backup_files) click to toggle source
print_separator(length) click to toggle source
safe_to_delete_path?(path, backup_path) click to toggle source
# File lib/vera/safe.rb, line 32
def self.safe_to_delete_path?(path, backup_path)
  backup_media_files = Lister.all_media_files_recursive(backup_path)
                             .map { |f| Media.new(f) }

  media_files = Lister.all_media_files_recursive(path)
                             .map { |f| Media.new(f) }

  print_folders(path, backup_path)
  print_number_of_files(media_files, backup_media_files)

  select_candidates = candidates_by_file_size(media_files, backup_media_files)
  found_files       = candidates_by_partial_hash(select_candidates)

  print_list_of_files(found_files, backup_path)
end