Method: Bixby::Repository.download_files

Defined in:
lib/bixby-client/modules/repository.rb

.download_files(cmd, files) ⇒ Object

Deprecated.

Use #list_files and #fetch_file respectively

Download the given list of files

Parameters:

  • cmd (CommandSpec)

    CommandSpec representing the Bundle to which the files belong

  • files (Hash)

    Hash, returned from #list_files



41
42
43
44
45
46
47
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
74
75
76
77
78
79
80
81
82
83
# File 'lib/bixby-client/modules/repository.rb', line 41

def self.download_files(cmd, files)
  return if files.nil? or files.empty?

  local_path = cmd.bundle_dir
  digest = cmd.load_digest
  files.each do |f|

    fetch = true
    if not digest then
      fetch = true
    elsif df = digest["files"].find{ |h| h["file"] == f["file"] } then
      # compare digest w/ stored one if we have it
      fetch = (df["digest"] != f["digest"])
    else
      fetch = true
    end

    if not fetch then
      debug { "skipping: #{f}" }
      next
    end

    debug { "fetching: #{f}"}

    params = cmd.to_hash
    params.delete(:digest)

    filename = File.join(local_path, f['file'])
    path = File.dirname(filename)
    if not File.exist? path then
      FileUtils.mkdir_p(path)
    end

    req = JsonRequest.new("provisioning:fetch_file", [ params, f['file'] ])
    Bixby.client.exec_api_download(req, filename)
    if f['file'] =~ /^bin/ then
      # correct permissions for executables
      FileUtils.chmod(0755, filename)
    end
  end # files.each

  cmd.update_digest
end