Utils::Cp: Remove copy
prefix from method name
As per review feedback: https://github.com/Homebrew/brew/pull/17373#pullrequestreview-2104523770 Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
parent
d9239faad3
commit
b2ddeecdd9
@ -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_with_attributes(source.children, target, sudo: true, command:)
|
::Utils::Cp.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_with_attributes(source, target, sudo: true, command:)
|
::Utils::Cp.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_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)
|
delete(target, force:, command:, **options)
|
||||||
end
|
end
|
||||||
|
@ -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_with_attributes(self, dst)
|
Utils::Cp.with_attributes(self, dst)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -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_with_attributes path, unpack_dir/basename
|
Utils::Cp.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],
|
||||||
|
@ -22,9 +22,9 @@ 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_with_attributes (child.directory? && !child.symlink?) ? "#{child}/." : child,
|
Utils::Cp.recursive_with_attributes (child.directory? && !child.symlink?) ? "#{child}/." : child,
|
||||||
unpack_dir/child.basename,
|
unpack_dir/child.basename,
|
||||||
verbose:
|
verbose:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -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_with_attributes path, unpack_dir/basename
|
Utils::Cp.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],
|
||||||
|
@ -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_with_attributes path, unpack_dir/basename
|
Utils::Cp.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],
|
||||||
|
@ -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_with_attributes path, unpack_dir/basename
|
Utils::Cp.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],
|
||||||
|
@ -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_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
|
end
|
||||||
end
|
end
|
||||||
|
@ -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_with_attributes path, unpack_dir/basename
|
Utils::Cp.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],
|
||||||
|
@ -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_with_attributes path, unpack_dir/basename
|
Utils::Cp.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],
|
||||||
|
@ -17,7 +17,7 @@ module Utils
|
|||||||
command: T.class_of(SystemCommand),
|
command: T.class_of(SystemCommand),
|
||||||
).returns(SystemCommand::Result)
|
).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
|
# 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
|
||||||
@ -34,7 +34,7 @@ module Utils
|
|||||||
command: T.class_of(SystemCommand),
|
command: T.class_of(SystemCommand),
|
||||||
).returns(SystemCommand::Result)
|
).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:
|
command.run! "cp", args: ["-pR", *extra_flags, *source, target], sudo:, verbose:
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user