diff --git a/Library/Homebrew/extend/os/mac/utils/cp.rb b/Library/Homebrew/extend/os/mac/utils/cp.rb index 4822025502..ec430b7dc5 100644 --- a/Library/Homebrew/extend/os/mac/utils/cp.rb +++ b/Library/Homebrew/extend/os/mac/utils/cp.rb @@ -5,45 +5,6 @@ module Utils module Cp class << self 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 # Use the lightweight `clonefile(2)` syscall if applicable. diff --git a/Library/Homebrew/sorbet/rbi/upstream.rbi b/Library/Homebrew/sorbet/rbi/upstream.rbi index a00487f95a..25724349e3 100644 --- a/Library/Homebrew/sorbet/rbi/upstream.rbi +++ b/Library/Homebrew/sorbet/rbi/upstream.rbi @@ -2,3 +2,23 @@ # This file contains temporary definitions for fixes that have # 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 diff --git a/Library/Homebrew/utils/cp.rb b/Library/Homebrew/utils/cp.rb index 6ecdf5df00..e29d2cecce 100644 --- a/Library/Homebrew/utils/cp.rb +++ b/Library/Homebrew/utils/cp.rb @@ -9,9 +9,19 @@ module Utils # Helper functions for copying files. module Cp 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) - if force_command || sudo - command.run! "cp", args: ["-p", *source, target], sudo:, verbose: + if force_command || sudo || (flags = extra_flags) + command.run! "cp", args: ["-p", *flags, *source, target], sudo:, verbose: else FileUtils.cp source, target, preserve: true, verbose: end @@ -19,16 +29,30 @@ module Utils nil 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 force_command || sudo - command.run! "cp", args: ["-pR", *source, target], sudo:, verbose: + if force_command || sudo || (flags = extra_flags) + command.run! "cp", args: ["-pR", *flags, *source, target], sudo:, verbose: else FileUtils.cp_r source, target, preserve: true, verbose: end nil end + + private + + def extra_flags; end end end end