Utils::Cp: Move macOS-specific code to extend/os/mac
This commit is contained in:
parent
58852106c1
commit
7cfcc596b9
4
Library/Homebrew/extend/os/cp.rb
Normal file
4
Library/Homebrew/extend/os/cp.rb
Normal file
@ -0,0 +1,4 @@
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "extend/os/mac/utils/cp" if OS.mac?
|
||||
30
Library/Homebrew/extend/os/mac/utils/cp.rb
Normal file
30
Library/Homebrew/extend/os/mac/utils/cp.rb
Normal file
@ -0,0 +1,30 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Utils
|
||||
module Cp
|
||||
class << self
|
||||
module MacOSOverride
|
||||
private
|
||||
|
||||
# Use the lightweight `clonefile(2)` syscall if applicable.
|
||||
SONOMA_FLAGS = ["-c"].freeze
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
def extra_flags
|
||||
# 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
|
||||
# filesystem doesn't support the feature or the source and the target are on different
|
||||
# filesystems).
|
||||
if MacOS.version >= :sonoma
|
||||
SONOMA_FLAGS
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
prepend MacOSOverride
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,6 +1,7 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "extend/os/cp"
|
||||
require "system_command"
|
||||
|
||||
module Utils
|
||||
@ -39,20 +40,10 @@ module Utils
|
||||
|
||||
private
|
||||
|
||||
# Use the lightweight `clonefile(2)` syscall if applicable.
|
||||
MACOS_FLAGS = ["-c"].freeze
|
||||
GENERIC_FLAGS = [].freeze
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
def extra_flags
|
||||
# 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 filesystem
|
||||
# doesn't support the feature or the source and the target are on different filesystems).
|
||||
if OS.mac? && MacOS.version >= :sonoma
|
||||
MACOS_FLAGS
|
||||
else
|
||||
GENERIC_FLAGS
|
||||
end
|
||||
GENERIC_FLAGS
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user