diff --git a/Library/Homebrew/cask/artifact/moved.rb b/Library/Homebrew/cask/artifact/moved.rb index 26128fba75..77043497b0 100644 --- a/Library/Homebrew/cask/artifact/moved.rb +++ b/Library/Homebrew/cask/artifact/moved.rb @@ -109,7 +109,7 @@ module Cask if target.writable? source.children.each { |child| FileUtils.move(child, target/child.basename) } else - ::Utils::Cp.copy_recursive_with_attributes(source.children, target, sudo: true, command:) + ::Utils::Cp.recursive_with_attributes(source.children, target, sudo: true, command:) end Quarantine.copy_xattrs(source, target, command:) source.rmtree @@ -118,7 +118,7 @@ module Cask else # default sudo user isn't necessarily able to write to Homebrew's locations # e.g. with runas_default set in the sudoers (5) file. - ::Utils::Cp.copy_recursive_with_attributes(source, target, sudo: true, command:) + ::Utils::Cp.recursive_with_attributes(source, target, sudo: true, command:) source.rmtree end @@ -162,7 +162,7 @@ module Cask source.dirname.mkpath # `Utils::Cp` preserves extended attributes between copies. - ::Utils::Cp.copy_recursive_with_attributes(target, source, sudo: !source.parent.writable?, command:) + ::Utils::Cp.recursive_with_attributes(target, source, sudo: !source.parent.writable?, command:) delete(target, force:, command:, **options) end diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 6fd2e1ae6a..529665123e 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -227,7 +227,7 @@ class Pathname else dst.dirname.mkpath dst = yield(self, dst) if block_given? - Utils::Cp.copy_with_attributes(self, dst) + Utils::Cp.with_attributes(self, dst) end end diff --git a/Library/Homebrew/unpack_strategy/bzip2.rb b/Library/Homebrew/unpack_strategy/bzip2.rb index c37214a837..2ca92686b9 100644 --- a/Library/Homebrew/unpack_strategy/bzip2.rb +++ b/Library/Homebrew/unpack_strategy/bzip2.rb @@ -21,7 +21,7 @@ module UnpackStrategy sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } def extract_to_dir(unpack_dir, basename:, verbose:) - Utils::Cp.copy_with_attributes path, unpack_dir/basename + Utils::Cp.with_attributes path, unpack_dir/basename quiet_flags = verbose ? [] : ["-q"] system_command! "bunzip2", args: [*quiet_flags, unpack_dir/basename], diff --git a/Library/Homebrew/unpack_strategy/directory.rb b/Library/Homebrew/unpack_strategy/directory.rb index c95b31d379..717e7782b7 100644 --- a/Library/Homebrew/unpack_strategy/directory.rb +++ b/Library/Homebrew/unpack_strategy/directory.rb @@ -22,9 +22,9 @@ module UnpackStrategy sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } def extract_to_dir(unpack_dir, basename:, verbose:) path.children.each do |child| - Utils::Cp.copy_recursive_with_attributes (child.directory? && !child.symlink?) ? "#{child}/." : child, - unpack_dir/child.basename, - verbose: + Utils::Cp.recursive_with_attributes (child.directory? && !child.symlink?) ? "#{child}/." : child, + unpack_dir/child.basename, + verbose: end end end diff --git a/Library/Homebrew/unpack_strategy/gzip.rb b/Library/Homebrew/unpack_strategy/gzip.rb index 8652123560..8e2b869eeb 100644 --- a/Library/Homebrew/unpack_strategy/gzip.rb +++ b/Library/Homebrew/unpack_strategy/gzip.rb @@ -21,7 +21,7 @@ module UnpackStrategy sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } def extract_to_dir(unpack_dir, basename:, verbose:) - Utils::Cp.copy_with_attributes path, unpack_dir/basename + Utils::Cp.with_attributes path, unpack_dir/basename quiet_flags = verbose ? [] : ["-q"] system_command! "gunzip", args: [*quiet_flags, "-N", "--", unpack_dir/basename], diff --git a/Library/Homebrew/unpack_strategy/lzip.rb b/Library/Homebrew/unpack_strategy/lzip.rb index 5b92068750..8da8640088 100644 --- a/Library/Homebrew/unpack_strategy/lzip.rb +++ b/Library/Homebrew/unpack_strategy/lzip.rb @@ -25,7 +25,7 @@ module UnpackStrategy sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } def extract_to_dir(unpack_dir, basename:, verbose:) - Utils::Cp.copy_with_attributes path, unpack_dir/basename + Utils::Cp.with_attributes path, unpack_dir/basename quiet_flags = verbose ? [] : ["-q"] system_command! "lzip", args: ["-d", *quiet_flags, unpack_dir/basename], diff --git a/Library/Homebrew/unpack_strategy/lzma.rb b/Library/Homebrew/unpack_strategy/lzma.rb index 6ebdec1e69..b9a8f4e2d4 100644 --- a/Library/Homebrew/unpack_strategy/lzma.rb +++ b/Library/Homebrew/unpack_strategy/lzma.rb @@ -25,7 +25,7 @@ module UnpackStrategy sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } def extract_to_dir(unpack_dir, basename:, verbose:) - Utils::Cp.copy_with_attributes path, unpack_dir/basename + Utils::Cp.with_attributes path, unpack_dir/basename quiet_flags = verbose ? [] : ["-q"] system_command! "unlzma", args: [*quiet_flags, "--", unpack_dir/basename], diff --git a/Library/Homebrew/unpack_strategy/uncompressed.rb b/Library/Homebrew/unpack_strategy/uncompressed.rb index 69fa900cec..ae36bd17f5 100644 --- a/Library/Homebrew/unpack_strategy/uncompressed.rb +++ b/Library/Homebrew/unpack_strategy/uncompressed.rb @@ -24,7 +24,7 @@ module UnpackStrategy sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } def extract_to_dir(unpack_dir, basename:, verbose: false) - Utils::Cp.copy_with_attributes path, unpack_dir/basename.sub(/^[\da-f]{64}--/, ""), verbose: + Utils::Cp.with_attributes path, unpack_dir/basename.sub(/^[\da-f]{64}--/, ""), verbose: end end end diff --git a/Library/Homebrew/unpack_strategy/xz.rb b/Library/Homebrew/unpack_strategy/xz.rb index 06c9e18828..94177c804f 100644 --- a/Library/Homebrew/unpack_strategy/xz.rb +++ b/Library/Homebrew/unpack_strategy/xz.rb @@ -25,7 +25,7 @@ module UnpackStrategy sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } def extract_to_dir(unpack_dir, basename:, verbose:) - Utils::Cp.copy_with_attributes path, unpack_dir/basename + Utils::Cp.with_attributes path, unpack_dir/basename quiet_flags = verbose ? [] : ["-q"] system_command! "unxz", args: [*quiet_flags, "-T0", "--", unpack_dir/basename], diff --git a/Library/Homebrew/unpack_strategy/zstd.rb b/Library/Homebrew/unpack_strategy/zstd.rb index 853e448a7e..f1a89a4519 100644 --- a/Library/Homebrew/unpack_strategy/zstd.rb +++ b/Library/Homebrew/unpack_strategy/zstd.rb @@ -25,7 +25,7 @@ module UnpackStrategy sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } def extract_to_dir(unpack_dir, basename:, verbose:) - Utils::Cp.copy_with_attributes path, unpack_dir/basename + Utils::Cp.with_attributes path, unpack_dir/basename quiet_flags = verbose ? [] : ["-q"] system_command! "unzstd", args: [*quiet_flags, "-T0", "--rm", "--", unpack_dir/basename], diff --git a/Library/Homebrew/utils/cp.rb b/Library/Homebrew/utils/cp.rb index a08aadcc13..e091103f51 100644 --- a/Library/Homebrew/utils/cp.rb +++ b/Library/Homebrew/utils/cp.rb @@ -17,7 +17,7 @@ module Utils command: T.class_of(SystemCommand), ).returns(SystemCommand::Result) } - def copy_with_attributes(source, target, sudo: false, verbose: false, command: SystemCommand) + def with_attributes(source, target, sudo: false, verbose: false, command: SystemCommand) # 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 @@ -34,7 +34,7 @@ module Utils command: T.class_of(SystemCommand), ).returns(SystemCommand::Result) } - def copy_recursive_with_attributes(source, target, sudo: false, verbose: false, command: SystemCommand) + def recursive_with_attributes(source, target, sudo: false, verbose: false, command: SystemCommand) command.run! "cp", args: ["-pR", *extra_flags, *source, target], sudo:, verbose: end