mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Utils::Cp: Drop special case for coreutils cp
As per review feedback: https://github.com/Homebrew/brew/pull/17373#issuecomment-2132673915
This commit is contained in:
parent
942906b74a
commit
b4dcb94ad6
@ -21,8 +21,6 @@ RSpec.describe FormulaInstaller do
|
|||||||
expect(formula).to be_bottled
|
expect(formula).to be_bottled
|
||||||
expect(formula).to pour_bottle
|
expect(formula).to pour_bottle
|
||||||
|
|
||||||
stub_formula_loader formula("coreutils") { url "coreutils-1.0" }
|
|
||||||
stub_formula_loader formula("uutils-coreutils") { url "uutils-coreutils-1.0" }
|
|
||||||
stub_formula_loader formula("gcc") { url "gcc-1.0" }
|
stub_formula_loader formula("gcc") { url "gcc-1.0" }
|
||||||
stub_formula_loader formula("glibc") { url "glibc-1.0" }
|
stub_formula_loader formula("glibc") { url "glibc-1.0" }
|
||||||
stub_formula_loader formula
|
stub_formula_loader formula
|
||||||
|
@ -17,7 +17,11 @@ module Utils
|
|||||||
).returns(SystemCommand::Result)
|
).returns(SystemCommand::Result)
|
||||||
}
|
}
|
||||||
def copy(source, target, sudo: false, verbose: false, command: SystemCommand)
|
def copy(source, target, sudo: false, verbose: false, command: SystemCommand)
|
||||||
command.run! executable, args: ["-p", *extra_flags, *source, target], sudo:, verbose:
|
# 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:
|
||||||
end
|
end
|
||||||
|
|
||||||
sig {
|
sig {
|
||||||
@ -30,78 +34,26 @@ module Utils
|
|||||||
).returns(SystemCommand::Result)
|
).returns(SystemCommand::Result)
|
||||||
}
|
}
|
||||||
def copy_recursive(source, target, sudo: false, verbose: false, command: SystemCommand)
|
def copy_recursive(source, target, sudo: false, verbose: false, command: SystemCommand)
|
||||||
command.run! executable, args: ["-pR", *extra_flags, *source, target], sudo:, verbose:
|
command.run! "cp", args: ["-pR", *extra_flags, *source, target], sudo:, verbose:
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
GCP = (HOMEBREW_PREFIX/"opt/coreutils/libexec/gnubin/cp").freeze
|
# Use the lightweight `clonefile(2)` syscall if applicable.
|
||||||
UCP = (HOMEBREW_PREFIX/"opt/uutils-coreutils/libexec/uubin/cp").freeze
|
MACOS_FLAGS = ["-c"].freeze
|
||||||
|
|
||||||
sig { returns(T.any(String, Pathname)) }
|
|
||||||
def executable
|
|
||||||
case type
|
|
||||||
when :macos
|
|
||||||
Pathname("/bin/cp")
|
|
||||||
when :coreutils
|
|
||||||
GCP
|
|
||||||
when :uutils
|
|
||||||
UCP
|
|
||||||
else
|
|
||||||
"cp"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
MACOS_FLAGS = [
|
|
||||||
# Perform a lightweight copy-on-write clone if applicable.
|
|
||||||
"-c",
|
|
||||||
].freeze
|
|
||||||
GNU_FLAGS = [
|
|
||||||
# Unlike BSD cp, `gcp -p` doesn't guarantee to preserve extended attributes, including
|
|
||||||
# quarantine information on macOS.
|
|
||||||
"--preserve=all",
|
|
||||||
"--no-preserve=links",
|
|
||||||
# Equivalent to `-c` on macOS.
|
|
||||||
"--reflink=auto",
|
|
||||||
].freeze
|
|
||||||
GENERIC_FLAGS = [].freeze
|
GENERIC_FLAGS = [].freeze
|
||||||
|
|
||||||
sig { returns(T::Array[String]) }
|
sig { returns(T::Array[String]) }
|
||||||
def extra_flags
|
def extra_flags
|
||||||
case type
|
# The `cp` command on older macOS versions also had the `-c` option, but before Sonoma, the
|
||||||
when :macos
|
# command would fail if the `clonefile` syscall isn't applicable (the underlying filesystem
|
||||||
|
# doesn't support the feature or the source and the target are on different filesystems).
|
||||||
|
if MacOS.version >= :sonoma
|
||||||
MACOS_FLAGS
|
MACOS_FLAGS
|
||||||
when :coreutils, :uutils
|
|
||||||
GNU_FLAGS
|
|
||||||
else
|
else
|
||||||
GENERIC_FLAGS
|
GENERIC_FLAGS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T.nilable(Symbol)) }
|
|
||||||
def type
|
|
||||||
return @type if defined?(@type)
|
|
||||||
|
|
||||||
# The `cp` command on some older macOS versions also had the `-c` option, but before Sonoma,
|
|
||||||
# the command would fail if the `clonefile` syscall isn't applicable (the underlying
|
|
||||||
# filesystem doesn't support the feature or the source and the target are on different
|
|
||||||
# filesystems).
|
|
||||||
return @type = :macos if MacOS.version >= :sonoma
|
|
||||||
|
|
||||||
{
|
|
||||||
coreutils: "coreutils",
|
|
||||||
uutils: "uutils-coreutils",
|
|
||||||
}.each do |type, formula|
|
|
||||||
begin
|
|
||||||
formula = Formula[formula]
|
|
||||||
rescue FormulaUnavailableError
|
|
||||||
next
|
|
||||||
end
|
|
||||||
return @type = type if formula.optlinked?
|
|
||||||
end
|
|
||||||
|
|
||||||
@type = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user