Utils::Cp: Rename copy* methods to copy*_with_attributes

As per review feedback:

https://github.com/Homebrew/brew/pull/17373#pullrequestreview-2103870774
This commit is contained in:
Daiki Mizukami 2024-06-07 18:02:52 +09:00
parent a5500aa7f2
commit 58852106c1
No known key found for this signature in database
GPG Key ID: 10478E598B944AA2
12 changed files with 17 additions and 17 deletions

View File

@ -109,7 +109,7 @@ module Cask
if target.writable? if target.writable?
source.children.each { |child| FileUtils.move(child, target/child.basename) } source.children.each { |child| FileUtils.move(child, target/child.basename) }
else else
::Utils::Cp.copy_recursive(source.children, target, sudo: true, command:) ::Utils::Cp.copy_recursive_with_attributes(source.children, target, sudo: true, command:)
end end
Quarantine.copy_xattrs(source, target, command:) Quarantine.copy_xattrs(source, target, command:)
source.rmtree source.rmtree
@ -118,7 +118,7 @@ module Cask
else else
# default sudo user isn't necessarily able to write to Homebrew's locations # default sudo user isn't necessarily able to write to Homebrew's locations
# e.g. with runas_default set in the sudoers (5) file. # e.g. with runas_default set in the sudoers (5) file.
::Utils::Cp.copy_recursive(source, target, sudo: true, command:) ::Utils::Cp.copy_recursive_with_attributes(source, target, sudo: true, command:)
source.rmtree source.rmtree
end end
@ -162,7 +162,7 @@ module Cask
source.dirname.mkpath source.dirname.mkpath
# `Utils::Cp` preserves extended attributes between copies. # `Utils::Cp` preserves extended attributes between copies.
::Utils::Cp.copy_recursive(target, source, sudo: !source.parent.writable?, command:) ::Utils::Cp.copy_recursive_with_attributes(target, source, sudo: !source.parent.writable?, command:)
delete(target, force:, command:, **options) delete(target, force:, command:, **options)
end end

View File

@ -768,7 +768,7 @@ module Homebrew
all_bottle_hash = { formula_name => all_bottle_formula_hash } all_bottle_hash = { formula_name => all_bottle_formula_hash }
puts "Copying #{filename} to #{all_filename}" if args.verbose? puts "Copying #{filename} to #{all_filename}" if args.verbose?
Utils::Cp.copy filename.to_s, all_filename.to_s Utils::Cp.copy_with_attributes filename.to_s, all_filename.to_s
puts "Writing #{all_filename.json}" if args.verbose? puts "Writing #{all_filename.json}" if args.verbose?
all_local_json_path = Pathname(all_filename.json) all_local_json_path = Pathname(all_filename.json)

View File

@ -227,7 +227,7 @@ class Pathname
else else
dst.dirname.mkpath dst.dirname.mkpath
dst = yield(self, dst) if block_given? dst = yield(self, dst) if block_given?
Utils::Cp.copy(self, dst) Utils::Cp.copy_with_attributes(self, dst)
end end
end end

View File

@ -21,7 +21,7 @@ module UnpackStrategy
sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose:) def extract_to_dir(unpack_dir, basename:, verbose:)
Utils::Cp.copy path, unpack_dir/basename Utils::Cp.copy_with_attributes path, unpack_dir/basename
quiet_flags = verbose ? [] : ["-q"] quiet_flags = verbose ? [] : ["-q"]
system_command! "bunzip2", system_command! "bunzip2",
args: [*quiet_flags, unpack_dir/basename], args: [*quiet_flags, unpack_dir/basename],

View File

@ -22,7 +22,7 @@ module UnpackStrategy
sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose:) def extract_to_dir(unpack_dir, basename:, verbose:)
path.children.each do |child| path.children.each do |child|
Utils::Cp.copy_recursive (child.directory? && !child.symlink?) ? "#{child}/." : child, Utils::Cp.copy_recursive_with_attributes (child.directory? && !child.symlink?) ? "#{child}/." : child,
unpack_dir/child.basename, unpack_dir/child.basename,
verbose: verbose:
end end

View File

@ -21,7 +21,7 @@ module UnpackStrategy
sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose:) def extract_to_dir(unpack_dir, basename:, verbose:)
Utils::Cp.copy path, unpack_dir/basename Utils::Cp.copy_with_attributes path, unpack_dir/basename
quiet_flags = verbose ? [] : ["-q"] quiet_flags = verbose ? [] : ["-q"]
system_command! "gunzip", system_command! "gunzip",
args: [*quiet_flags, "-N", "--", unpack_dir/basename], args: [*quiet_flags, "-N", "--", unpack_dir/basename],

View File

@ -25,7 +25,7 @@ module UnpackStrategy
sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose:) def extract_to_dir(unpack_dir, basename:, verbose:)
Utils::Cp.copy path, unpack_dir/basename Utils::Cp.copy_with_attributes path, unpack_dir/basename
quiet_flags = verbose ? [] : ["-q"] quiet_flags = verbose ? [] : ["-q"]
system_command! "lzip", system_command! "lzip",
args: ["-d", *quiet_flags, unpack_dir/basename], args: ["-d", *quiet_flags, unpack_dir/basename],

View File

@ -25,7 +25,7 @@ module UnpackStrategy
sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose:) def extract_to_dir(unpack_dir, basename:, verbose:)
Utils::Cp.copy path, unpack_dir/basename Utils::Cp.copy_with_attributes path, unpack_dir/basename
quiet_flags = verbose ? [] : ["-q"] quiet_flags = verbose ? [] : ["-q"]
system_command! "unlzma", system_command! "unlzma",
args: [*quiet_flags, "--", unpack_dir/basename], args: [*quiet_flags, "--", unpack_dir/basename],

View File

@ -24,7 +24,7 @@ module UnpackStrategy
sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose: false) def extract_to_dir(unpack_dir, basename:, verbose: false)
Utils::Cp.copy path, unpack_dir/basename.sub(/^[\da-f]{64}--/, ""), verbose: Utils::Cp.copy_with_attributes path, unpack_dir/basename.sub(/^[\da-f]{64}--/, ""), verbose:
end end
end end
end end

View File

@ -25,7 +25,7 @@ module UnpackStrategy
sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose:) def extract_to_dir(unpack_dir, basename:, verbose:)
Utils::Cp.copy path, unpack_dir/basename Utils::Cp.copy_with_attributes path, unpack_dir/basename
quiet_flags = verbose ? [] : ["-q"] quiet_flags = verbose ? [] : ["-q"]
system_command! "unxz", system_command! "unxz",
args: [*quiet_flags, "-T0", "--", unpack_dir/basename], args: [*quiet_flags, "-T0", "--", unpack_dir/basename],

View File

@ -25,7 +25,7 @@ module UnpackStrategy
sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose:) def extract_to_dir(unpack_dir, basename:, verbose:)
Utils::Cp.copy path, unpack_dir/basename Utils::Cp.copy_with_attributes path, unpack_dir/basename
quiet_flags = verbose ? [] : ["-q"] quiet_flags = verbose ? [] : ["-q"]
system_command! "unzstd", system_command! "unzstd",
args: [*quiet_flags, "-T0", "--rm", "--", unpack_dir/basename], args: [*quiet_flags, "-T0", "--rm", "--", unpack_dir/basename],

View File

@ -16,7 +16,7 @@ module Utils
command: T.class_of(SystemCommand), command: T.class_of(SystemCommand),
).returns(SystemCommand::Result) ).returns(SystemCommand::Result)
} }
def copy(source, target, sudo: false, verbose: false, command: SystemCommand) def copy_with_attributes(source, target, sudo: false, verbose: false, command: SystemCommand)
# On macOS, `cp -p` guarantees to preserve extended attributes (including quarantine # On macOS, `cp -p` guarantees to preserve extended attributes (including quarantine
# information) in addition to file mode. Other implementations like coreutils does not # 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 # necessarily guarantee the same behavior, but that is fine because we don't really need to
@ -33,7 +33,7 @@ module Utils
command: T.class_of(SystemCommand), command: T.class_of(SystemCommand),
).returns(SystemCommand::Result) ).returns(SystemCommand::Result)
} }
def copy_recursive(source, target, sudo: false, verbose: false, command: SystemCommand) def copy_recursive_with_attributes(source, target, sudo: false, verbose: false, command: SystemCommand)
command.run! "cp", args: ["-pR", *extra_flags, *source, target], sudo:, verbose: command.run! "cp", args: ["-pR", *extra_flags, *source, target], sudo:, verbose:
end end