2024-05-21 20:18:58 +09:00
|
|
|
# typed: true
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-06-07 18:16:15 +09:00
|
|
|
require "extend/os/cp"
|
2024-05-21 20:18:58 +09:00
|
|
|
require "system_command"
|
|
|
|
|
|
|
|
module Utils
|
|
|
|
# Helper functions for interacting with the `cp` command.
|
|
|
|
module Cp
|
|
|
|
class << self
|
|
|
|
sig {
|
|
|
|
params(
|
|
|
|
source: T.any(String, Pathname, T::Array[T.any(String, Pathname)]),
|
|
|
|
target: T.any(String, Pathname),
|
|
|
|
sudo: T::Boolean,
|
|
|
|
verbose: T::Boolean,
|
|
|
|
command: T.class_of(SystemCommand),
|
|
|
|
).returns(SystemCommand::Result)
|
|
|
|
}
|
2024-06-08 06:21:13 +09:00
|
|
|
def with_attributes(source, target, sudo: false, verbose: false, command: SystemCommand)
|
2024-05-27 18:01:57 +09:00
|
|
|
# On macOS, `cp -p` guarantees to preserve extended attributes (including quarantine
|
|
|
|
# information) in addition to file mode. Other implementations like coreutils does not
|
|
|
|
# necessarily guarantee the same behavior, but that is fine because we don't really need to
|
|
|
|
# preserve extended attributes except when copying Cask artifacts.
|
|
|
|
command.run! "cp", args: ["-p", *extra_flags, *source, target], sudo:, verbose:
|
2024-05-21 20:18:58 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
sig {
|
|
|
|
params(
|
|
|
|
source: T.any(String, Pathname, T::Array[T.any(String, Pathname)]),
|
|
|
|
target: T.any(String, Pathname),
|
|
|
|
sudo: T::Boolean,
|
|
|
|
verbose: T::Boolean,
|
|
|
|
command: T.class_of(SystemCommand),
|
|
|
|
).returns(SystemCommand::Result)
|
|
|
|
}
|
2024-06-08 06:21:13 +09:00
|
|
|
def recursive_with_attributes(source, target, sudo: false, verbose: false, command: SystemCommand)
|
2024-05-27 18:01:57 +09:00
|
|
|
command.run! "cp", args: ["-pR", *extra_flags, *source, target], sudo:, verbose:
|
2024-05-21 20:18:58 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
GENERIC_FLAGS = [].freeze
|
|
|
|
|
|
|
|
def extra_flags
|
2024-06-07 18:16:15 +09:00
|
|
|
GENERIC_FLAGS
|
2024-05-21 20:18:58 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|