Module: Bixby::Repository

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

Class Method Summary collapse

Class Method Details

.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

.fetch_file(cmd, file, dest) ⇒ Object

Download the given command file

Parameters:

  • cmd (CommandSpec)

    CommandSpec representing the Bundle to which the files belong

  • files (Hash)

    Hash, returned from #list_files



27
28
29
30
31
32
# File 'lib/bixby-client/modules/repository.rb', line 27

def self.fetch_file(cmd, file, dest)
  params = cmd.to_hash
  params.delete(:digest)
  req = JsonRequest.new("provisioning:fetch_file", [params, file])
  Bixby.client.exec_api_download(req, dest)
end

.list_files(cmd) ⇒ Array<Hash>

Retrieve a file listing for the given Bundle

Parameters:

  • cmd (CommandSpec)

    CommandSpec representing the Bundle to list

Returns:

  • (Array<Hash>)
    • file [String] Relative path of file

    • digest [String] SHA256 digest of file



16
17
18
19
20
21
# File 'lib/bixby-client/modules/repository.rb', line 16

def self.list_files(cmd)
  debug { "listing files for bundle: #{cmd.bundle}"}
  req = JsonRequest.new("provisioning:list_files", cmd.to_hash)
  res = Bixby.client.exec_api(req)
  return res.data
end