Class: Fig::Protocol::File

Inherits:
Object
  • Object
show all
Includes:
Fig::Protocol
Defined in:
lib/fig/protocol/file.rb

Overview

File transfers for the local filesystem.

Instance Method Summary collapse

Instance Method Details

#download(uri, path, prompt_for_login) ⇒ Object

Returns whether the file was not downloaded because the file already exists and is already up-to-date.



61
62
63
64
65
66
67
68
69
70
# File 'lib/fig/protocol/file.rb', line 61

def download(uri, path, )
  begin
    unescaped_path = CGI.unescape uri.path
    FileUtils.cp(unescaped_path, path)

    return true
  rescue Errno::ENOENT => error
    raise Fig::FileNotFoundError.new error.message, uri
  end
end

#download_list(uri) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fig/protocol/file.rb', line 18

def download_list(uri)
  packages = []
  unescaped_path = CGI.unescape uri.path
  return packages if ! ::File.exist?(unescaped_path)

  ls = ''

  unescaped_path = FileTest.symlink?(unescaped_path) ? ::File.realpath(unescaped_path) : unescaped_path
  Find.find(unescaped_path) {
    |file|

    if FileTest.directory?(file)
      ls << file.to_s
      ls << "\n"
    end
  }

  strip_paths_for_list(ls, packages, unescaped_path)

  return packages
end

#path_up_to_date?(uri, path, prompt_for_login) ⇒ Boolean

Determine whether we need to update something. Returns nil to indicate “don’t know”.

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fig/protocol/file.rb', line 42

def path_up_to_date?(uri, path, )
  begin
    unescaped_path = CGI.unescape uri.path
    if ::File.size(unescaped_path) != ::File.size(path)
      return false
    end

    if ::File.mtime(unescaped_path) <= ::File.mtime(path)
      return true
    end

    return false
  rescue Errno::ENOENT => error
    raise Fig::FileNotFoundError.new error.message, uri
  end
end

#upload(local_file, uri) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/fig/protocol/file.rb', line 72

def upload(local_file, uri)
  unescaped_path = CGI.unescape uri.path
  FileUtils.mkdir_p(::File.dirname(unescaped_path))
  FileUtils.cp(local_file, unescaped_path)

  return
end