Utils::Cp: Deduplicate SystemCommand
invocations
This commit is contained in:
parent
67f280eb53
commit
eab1e87726
@ -5,45 +5,6 @@ module Utils
|
|||||||
module Cp
|
module Cp
|
||||||
class << self
|
class << self
|
||||||
module MacOSOverride
|
module MacOSOverride
|
||||||
sig {
|
|
||||||
params(
|
|
||||||
source: T.any(String, Pathname, T::Array[T.any(String, Pathname)]),
|
|
||||||
target: T.any(String, Pathname),
|
|
||||||
force_command: T::Boolean,
|
|
||||||
sudo: T::Boolean,
|
|
||||||
verbose: T::Boolean,
|
|
||||||
command: T.class_of(SystemCommand),
|
|
||||||
).void
|
|
||||||
}
|
|
||||||
def with_attributes(source, target, force_command: false, sudo: false, verbose: false, command: SystemCommand)
|
|
||||||
if (flags = extra_flags)
|
|
||||||
command.run! "cp", args: ["-p", *flags, *source, target], sudo:, verbose:
|
|
||||||
nil
|
|
||||||
else
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
sig {
|
|
||||||
params(
|
|
||||||
source: T.any(String, Pathname, T::Array[T.any(String, Pathname)]),
|
|
||||||
target: T.any(String, Pathname),
|
|
||||||
force_command: T::Boolean,
|
|
||||||
sudo: T::Boolean,
|
|
||||||
verbose: T::Boolean,
|
|
||||||
command: T.class_of(SystemCommand),
|
|
||||||
).void
|
|
||||||
}
|
|
||||||
def recursive_with_attributes(source, target, force_command: false, sudo: false, verbose: false,
|
|
||||||
command: SystemCommand)
|
|
||||||
if (flags = extra_flags)
|
|
||||||
command.run! "cp", args: ["-pR", *flags, *source, target], sudo:, verbose:
|
|
||||||
nil
|
|
||||||
else
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Use the lightweight `clonefile(2)` syscall if applicable.
|
# Use the lightweight `clonefile(2)` syscall if applicable.
|
||||||
|
@ -2,3 +2,23 @@
|
|||||||
|
|
||||||
# This file contains temporary definitions for fixes that have
|
# This file contains temporary definitions for fixes that have
|
||||||
# been submitted upstream to https://github.com/sorbet/sorbet.
|
# been submitted upstream to https://github.com/sorbet/sorbet.
|
||||||
|
|
||||||
|
# https://github.com/sorbet/sorbet/pull/7959
|
||||||
|
module FileUtils
|
||||||
|
sig {
|
||||||
|
params(
|
||||||
|
src: T.any(File, String, Pathname, T::Array[T.any(File, String, Pathname)]),
|
||||||
|
dest: T.any(String, Pathname),
|
||||||
|
preserve: T.nilable(T::Boolean),
|
||||||
|
noop: T.nilable(T::Boolean),
|
||||||
|
verbose: T.nilable(T::Boolean),
|
||||||
|
dereference_root: T::Boolean,
|
||||||
|
remove_destination: T.nilable(T::Boolean),
|
||||||
|
).returns(T.nilable(T::Array[String]))
|
||||||
|
}
|
||||||
|
def self.cp_r(src, dest, preserve: nil, noop: nil, verbose: nil, dereference_root: true, remove_destination: nil)
|
||||||
|
# XXX: This comment is a placeholder to suppress `Style/EmptyMethod` lint.
|
||||||
|
# Simply compacting the method definition in a single line would in turn trigger
|
||||||
|
# `Layout/LineLength`, driving `brew style --fix` to an infinite loop.
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -9,9 +9,19 @@ module Utils
|
|||||||
# Helper functions for copying files.
|
# Helper functions for copying files.
|
||||||
module Cp
|
module Cp
|
||||||
class << self
|
class << self
|
||||||
|
sig {
|
||||||
|
params(
|
||||||
|
source: T.any(String, Pathname, T::Array[T.any(String, Pathname)]),
|
||||||
|
target: T.any(String, Pathname),
|
||||||
|
force_command: T::Boolean,
|
||||||
|
sudo: T::Boolean,
|
||||||
|
verbose: T::Boolean,
|
||||||
|
command: T.class_of(SystemCommand),
|
||||||
|
).void
|
||||||
|
}
|
||||||
def with_attributes(source, target, force_command: false, sudo: false, verbose: false, command: SystemCommand)
|
def with_attributes(source, target, force_command: false, sudo: false, verbose: false, command: SystemCommand)
|
||||||
if force_command || sudo
|
if force_command || sudo || (flags = extra_flags)
|
||||||
command.run! "cp", args: ["-p", *source, target], sudo:, verbose:
|
command.run! "cp", args: ["-p", *flags, *source, target], sudo:, verbose:
|
||||||
else
|
else
|
||||||
FileUtils.cp source, target, preserve: true, verbose:
|
FileUtils.cp source, target, preserve: true, verbose:
|
||||||
end
|
end
|
||||||
@ -19,16 +29,30 @@ module Utils
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig {
|
||||||
|
params(
|
||||||
|
source: T.any(String, Pathname, T::Array[T.any(String, Pathname)]),
|
||||||
|
target: T.any(String, Pathname),
|
||||||
|
force_command: T::Boolean,
|
||||||
|
sudo: T::Boolean,
|
||||||
|
verbose: T::Boolean,
|
||||||
|
command: T.class_of(SystemCommand),
|
||||||
|
).void
|
||||||
|
}
|
||||||
def recursive_with_attributes(source, target, force_command: false, sudo: false, verbose: false,
|
def recursive_with_attributes(source, target, force_command: false, sudo: false, verbose: false,
|
||||||
command: SystemCommand)
|
command: SystemCommand)
|
||||||
if force_command || sudo
|
if force_command || sudo || (flags = extra_flags)
|
||||||
command.run! "cp", args: ["-pR", *source, target], sudo:, verbose:
|
command.run! "cp", args: ["-pR", *flags, *source, target], sudo:, verbose:
|
||||||
else
|
else
|
||||||
FileUtils.cp_r source, target, preserve: true, verbose:
|
FileUtils.cp_r source, target, preserve: true, verbose:
|
||||||
end
|
end
|
||||||
|
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def extra_flags; end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user