Utils::Cp: Add force_system keyword argument
This fixes the test for `UnpackStrategy::Directory`, which needs the `cp` command.
This commit is contained in:
parent
9156891c99
commit
67f280eb53
@ -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.recursive_with_attributes(source.children, target, sudo: true, command:)
|
::Utils::Cp.recursive_with_attributes(source.children, target, force_command: true, 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.recursive_with_attributes(source, target, sudo: true, command:)
|
::Utils::Cp.recursive_with_attributes(source, target, force_command: true, sudo: true, command:)
|
||||||
source.rmtree
|
source.rmtree
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -161,8 +161,9 @@ module Cask
|
|||||||
ohai "Backing #{self.class.english_name} '#{target.basename}' up to '#{source}'"
|
ohai "Backing #{self.class.english_name} '#{target.basename}' up to '#{source}'"
|
||||||
source.dirname.mkpath
|
source.dirname.mkpath
|
||||||
|
|
||||||
# `Utils::Cp` preserves extended attributes between copies.
|
::Utils::Cp.recursive_with_attributes(target, source, sudo: !source.parent.writable?, command:,
|
||||||
::Utils::Cp.recursive_with_attributes(target, source, sudo: !source.parent.writable?, command:)
|
# This is required to preserve extended attributes between copies.
|
||||||
|
force_command: true)
|
||||||
|
|
||||||
delete(target, force:, command:, **options)
|
delete(target, force:, command:, **options)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,30 +7,41 @@ module Utils
|
|||||||
module MacOSOverride
|
module MacOSOverride
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
source: T.any(String, Pathname, T::Array[T.any(String, Pathname)]),
|
source: T.any(String, Pathname, T::Array[T.any(String, Pathname)]),
|
||||||
target: T.any(String, Pathname),
|
target: T.any(String, Pathname),
|
||||||
sudo: T::Boolean,
|
force_command: T::Boolean,
|
||||||
verbose: T::Boolean,
|
sudo: T::Boolean,
|
||||||
command: T.class_of(SystemCommand),
|
verbose: T::Boolean,
|
||||||
).returns(SystemCommand::Result)
|
command: T.class_of(SystemCommand),
|
||||||
|
).void
|
||||||
}
|
}
|
||||||
def with_attributes(source, target, sudo: false, verbose: false, command: SystemCommand)
|
def with_attributes(source, target, force_command: false, sudo: false, verbose: false, command: SystemCommand)
|
||||||
# `cp -p` on macOS guarantees to preserve extended attributes (including quarantine
|
if (flags = extra_flags)
|
||||||
# information) in addition to file mode, which is requered when copying cask artifacts.
|
command.run! "cp", args: ["-p", *flags, *source, target], sudo:, verbose:
|
||||||
command.run! "cp", args: ["-p", *extra_flags, *source, target], sudo:, verbose:
|
nil
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
source: T.any(String, Pathname, T::Array[T.any(String, Pathname)]),
|
source: T.any(String, Pathname, T::Array[T.any(String, Pathname)]),
|
||||||
target: T.any(String, Pathname),
|
target: T.any(String, Pathname),
|
||||||
sudo: T::Boolean,
|
force_command: T::Boolean,
|
||||||
verbose: T::Boolean,
|
sudo: T::Boolean,
|
||||||
command: T.class_of(SystemCommand),
|
verbose: T::Boolean,
|
||||||
).returns(SystemCommand::Result)
|
command: T.class_of(SystemCommand),
|
||||||
|
).void
|
||||||
}
|
}
|
||||||
def recursive_with_attributes(source, target, sudo: false, verbose: false, command: SystemCommand)
|
def recursive_with_attributes(source, target, force_command: false, sudo: false, verbose: false,
|
||||||
command.run! "cp", args: ["-pR", *extra_flags, *source, target], sudo:, verbose:
|
command: SystemCommand)
|
||||||
|
if (flags = extra_flags)
|
||||||
|
command.run! "cp", args: ["-pR", *flags, *source, target], sudo:, verbose:
|
||||||
|
nil
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -38,17 +49,15 @@ module Utils
|
|||||||
# Use the lightweight `clonefile(2)` syscall if applicable.
|
# Use the lightweight `clonefile(2)` syscall if applicable.
|
||||||
SONOMA_FLAGS = ["-c"].freeze
|
SONOMA_FLAGS = ["-c"].freeze
|
||||||
|
|
||||||
sig { returns(T::Array[String]) }
|
sig { returns(T.nilable(T::Array[String])) }
|
||||||
def extra_flags
|
def extra_flags
|
||||||
# The `cp` command on older macOS versions also had the `-c` option, but before Sonoma,
|
# The `cp` command on older macOS versions also had the `-c` option, but before Sonoma,
|
||||||
# the command would fail if the `clonefile` syscall isn't applicable (the underlying
|
# 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
|
# filesystem doesn't support the feature or the source and the target are on different
|
||||||
# filesystems).
|
# filesystems).
|
||||||
if MacOS.version >= :sonoma
|
return if MacOS.version < :sonoma
|
||||||
SONOMA_FLAGS
|
|
||||||
else
|
SONOMA_FLAGS
|
||||||
[].freeze
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -24,6 +24,7 @@ module UnpackStrategy
|
|||||||
path.children.each do |child|
|
path.children.each do |child|
|
||||||
Utils::Cp.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,
|
||||||
|
force_command: true,
|
||||||
verbose:
|
verbose:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -9,14 +9,25 @@ module Utils
|
|||||||
# Helper functions for copying files.
|
# Helper functions for copying files.
|
||||||
module Cp
|
module Cp
|
||||||
class << self
|
class << self
|
||||||
def with_attributes(source, target, sudo: false, verbose: false, command: SystemCommand)
|
def with_attributes(source, target, force_command: false, sudo: false, verbose: false, command: SystemCommand)
|
||||||
odisabled "`Utils::Cp.with_attributes` with `sudo: true` on Linux" if sudo
|
if force_command || sudo
|
||||||
FileUtils.cp source, target, preserve: true, verbose:
|
command.run! "cp", args: ["-p", *source, target], sudo:, verbose:
|
||||||
|
else
|
||||||
|
FileUtils.cp source, target, preserve: true, verbose:
|
||||||
|
end
|
||||||
|
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def recursive_with_attributes(source, target, sudo: false, verbose: false, command: SystemCommand)
|
def recursive_with_attributes(source, target, force_command: false, sudo: false, verbose: false,
|
||||||
odisabled "`Utils::Cp.recursive_with_attributes` with `sudo: true` on Linux" if sudo
|
command: SystemCommand)
|
||||||
FileUtils.cp_r source, target, preserve: true, verbose:
|
if force_command || sudo
|
||||||
|
command.run! "cp", args: ["-pR", *source, target], sudo:, verbose:
|
||||||
|
else
|
||||||
|
FileUtils.cp_r source, target, preserve: true, verbose:
|
||||||
|
end
|
||||||
|
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user