Class: XcodeArchiveCache::ArtifactCache::Archiver

Inherits:
Object
  • Object
show all
Includes:
Logs
Defined in:
lib/artifact_cache/archiver.rb

Instance Method Summary collapse

Methods included from Logs

#debug, #error, #info, #set_log_level

Instance Method Details

#archive(path, destination) ⇒ Object

Parameters:

  • path (String)
  • destination (String)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/artifact_cache/archiver.rb', line 10

def archive(path, destination)
  if File.exists?(destination)
    warn "Replacing artifact archive at path #{destination}"
    FileUtils.rm_rf(destination)
  end

  if File.file?(path)
    archive_single_file(path, destination)
  elsif File.directory?(path)
    archive_directory(path, destination)
  else
    raise ArgumentError.new, "No artifact found at path #{path}"
  end
end

#unarchive(path, destination) ⇒ Object

Parameters:

  • path (String)
  • destination (String)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/artifact_cache/archiver.rb', line 28

def unarchive(path, destination)
  unless File.file?(path)
    raise ArgumentError.new, "Artifact archive not found: #{path}"
  end

  unless File.directory?(destination)
    FileUtils.mkdir_p(destination)
  end

  Zip::File.open(path) do |archive|
    archive.each do |archive_entry|
      destination_file_path = File.join(destination, archive_entry.name)
      destination_dir_path = File.dirname(destination_file_path)
      unless File.exists?(destination_dir_path) && File.directory?(destination_dir_path)
        FileUtils.mkdir_p(destination_dir_path)
      end

      archive_entry.extract(destination_file_path)
    end
  end
end