Method: Cir::Repository#restore

Defined in:
lib/cir/repository.rb

#restore(requested_files = nil, force = false) ⇒ Object

Restore persistent variant of the files



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/cir/repository.rb', line 128

def restore(requested_files = nil, force = false)
  generate_file_list(requested_files).each do |file|
    # If the destination file doesn't exist, we will simply copy it over
    if not File.exists?(file.file_path)
      FileUtils.cp(file.repository_location, file.file_path)
      puts "Restoring #{file.file_path}"
      next
    end

    # Skipping files that did not changed
    next unless file.diff.changed?

    # If we're run with force or in case of specific files, remove existing file and replace it
    if force or not requested_files.nil?
      FileUtils.remove_entry(file.file_path)
      FileUtils.cp(file.repository_location, file.file_path)
      puts "Restoring #{file.file_path}"
    else
      puts "Skipped mass change to #{key}."
    end
  end
end