45 lines
1.2 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: true
# frozen_string_literal: true
require "system_command"
module UnpackStrategy
2020-08-09 06:09:05 +02:00
# Strategy for unpacking Fossil repositories.
class Fossil
2020-10-20 12:03:48 +02:00
extend T::Sig
include UnpackStrategy
extend SystemCommand::Mixin
2020-10-20 12:03:48 +02:00
sig { returns(T::Array[String]) }
def self.extensions
[]
end
def self.can_extract?(path)
return false unless path.magic_number.match?(/\ASQLite format 3\000/n)
# Fossil database is made up of artifacts, so the `artifact` table must exist.
query = "select count(*) from sqlite_master where type = 'view' and name = 'artifact'"
system_command("sqlite3", args: [path, query]).stdout.to_i == 1
end
private
2020-10-20 12:03:48 +02:00
sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose:)
args = if @ref_type && @ref
[@ref]
else
[]
end
system_command! "fossil",
2018-11-02 17:18:07 +00:00
args: ["open", path, *args],
chdir: unpack_dir,
env: { "PATH" => PATH.new(Formula["fossil"].opt_bin, ENV.fetch("PATH")) },
2018-07-24 18:43:20 +02:00
verbose: verbose
end
end
end