aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc/container/xz.rb
blob: cd9f9aee2f11bca7dd19bec004819aa3d56a7f78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require "tmpdir"

require "hbc/container/base"

module Hbc
  class Container
    class Xz < Base
      def self.me?(criteria)
        criteria.magic_number(/^\xFD7zXZ\x00/n)
      end

      def extract
        if (unxz = which("unxz")).nil?
          raise CaskError, "Expected to find unxz executable. Cask '#{@cask}' must add: depends_on formula: 'xz'"
        end

        Dir.mktmpdir do |unpack_dir|
          @command.run!("/usr/bin/ditto", args: ["--", @path, unpack_dir])
          @command.run!(unxz, args: ["-q", "--", Pathname(unpack_dir).join(@path.basename)])
          @command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path])
        end
      end
    end
  end
end