diff --git a/Library/Homebrew/cask/artifact/moved.rb b/Library/Homebrew/cask/artifact/moved.rb index 252e54ad52..26128fba75 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(source.children, target, sudo: true, command:) + ::Utils::Cp.copy_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(source, target, sudo: true, command:) + ::Utils::Cp.copy_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(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) end diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 761d2f71b4..d0bf47a6b0 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -768,7 +768,7 @@ module Homebrew all_bottle_hash = { formula_name => all_bottle_formula_hash } 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? all_local_json_path = Pathname(all_filename.json) diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index ee44019703..6fd2e1ae6a 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(self, dst) + Utils::Cp.copy_with_attributes(self, dst) end end diff --git a/Library/Homebrew/unpack_strategy/bzip2.rb b/Library/Homebrew/unpack_strategy/bzip2.rb index aac5347f7a..c37214a837 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 path, unpack_dir/basename + Utils::Cp.copy_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 5f049d3822..c95b31d379 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 (child.directory? && !child.symlink?) ? "#{child}/." : child, - unpack_dir/child.basename, - verbose: + Utils::Cp.copy_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 41798e4b97..8652123560 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 path, unpack_dir/basename + Utils::Cp.copy_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 132ec72439..5b92068750 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 path, unpack_dir/basename + Utils::Cp.copy_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 2e9d711376..6ebdec1e69 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 path, unpack_dir/basename + Utils::Cp.copy_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 2fccd6ddc2..69fa900cec 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 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 diff --git a/Library/Homebrew/unpack_strategy/xz.rb b/Library/Homebrew/unpack_strategy/xz.rb index 726438231e..06c9e18828 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 path, unpack_dir/basename + Utils::Cp.copy_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 b49615e5f4..853e448a7e 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 path, unpack_dir/basename + Utils::Cp.copy_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 12d6482dfa..f49036c002 100644 --- a/Library/Homebrew/utils/cp.rb +++ b/Library/Homebrew/utils/cp.rb @@ -16,7 +16,7 @@ module Utils command: T.class_of(SystemCommand), ).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 # 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 @@ -33,7 +33,7 @@ module Utils command: T.class_of(SystemCommand), ).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: end