Method: Crackup::FileObject#restore

Defined in:
lib/crackup/file_object.rb

#restore(path) ⇒ Object

Restores the remote copy of this file to the local path specified by path.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/crackup/file_object.rb', line 48

def restore(path)
  path     = path.chomp('/') + '/' + File.dirname(@name).delete(':')
  filename = path + '/' + File.basename(@name)

  Crackup.debug "--> #{filename}"
  
  # Create the path if it doesn't exist.

  unless File.directory?(path)
    begin
      FileUtils.mkdir_p(path)
    rescue => e
      raise Crackup::Error, "Unable to create local directory: #{path}"
    end
  end
  
  # Download the remote file.

  tempfile = Crackup.get_tempfile()
  Crackup.driver.get(@url, tempfile)
  
  # Decompress/decrypt the file.

  if Crackup.options[:passphrase].nil?
    Crackup.decompress_file(tempfile, filename)
  else
    Crackup.decrypt_file(tempfile, filename)
  end
end