Class: Archaeo::PathConflictResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/archaeo/path_sanitizer.rb

Overview

Resolves file/directory path conflicts in download targets.

Detects when a file path would block creation of a needed directory (or vice versa) and resolves by relocating the file.

Instance Method Summary collapse

Constructor Details

#initialize(base_dir) ⇒ PathConflictResolver

Returns a new instance of PathConflictResolver.



98
99
100
# File 'lib/archaeo/path_sanitizer.rb', line 98

def initialize(base_dir)
  @base_dir = base_dir
end

Instance Method Details

#conflict?(file_path) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
111
112
113
# File 'lib/archaeo/path_sanitizer.rb', line 108

def conflict?(file_path)
  return false if File.directory?(file_path)
  return false unless File.file?(file_path)

  File.exist?(file_path) && needs_directory_under?(file_path)
end

#resolve(paths) ⇒ Object



102
103
104
105
106
# File 'lib/archaeo/path_sanitizer.rb', line 102

def resolve(paths)
  conflicts = detect_conflicts(paths)
  relocate_conflicts(conflicts)
  paths
end