Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Revert "Use cp -c when copying files" #17526

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Library/Homebrew/cask/artifact/moved.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

require "cask/artifact/relocated"
require "cask/quarantine"
require "utils/copy"

module Cask
module Artifact
Expand Down Expand Up @@ -109,8 +108,8 @@ def move(adopt: false, force: false, verbose: false, predecessor: nil, reinstall
if target.writable?
source.children.each { |child| FileUtils.move(child, target/child.basename) }
else
::Utils::Copy.recursive_with_attributes(source.children, target,
force_command: true, sudo: true, command:)
command.run!("/bin/cp", args: ["-pR", *source.children, target],
sudo: true)
end
Quarantine.copy_xattrs(source, target, command:)
source.rmtree
Expand All @@ -119,7 +118,7 @@ def move(adopt: false, force: false, verbose: false, predecessor: nil, reinstall
else
# default sudo user isn't necessarily able to write to Homebrew's locations
# e.g. with runas_default set in the sudoers (5) file.
::Utils::Copy.recursive_with_attributes(source, target, force_command: true, sudo: true, command:)
command.run!("/bin/cp", args: ["-pR", source, target], sudo: true)
source.rmtree
end

Expand Down Expand Up @@ -162,9 +161,8 @@ def move_back(skip: false, force: false, adopt: false, command: nil, **options)
ohai "Backing #{self.class.english_name} '#{target.basename}' up to '#{source}'"
source.dirname.mkpath

::Utils::Copy.recursive_with_attributes(target, source, sudo: !source.parent.writable?, command:,
# This is required to preserve extended attributes between copies.
force_command: true)
# We need to preserve extended attributes between copies.
command.run!("/bin/cp", args: ["-pR", target, source], sudo: !source.parent.writable?)

delete(target, force:, command:, **options)
end
Expand Down
4 changes: 0 additions & 4 deletions Library/Homebrew/extend/os/copy.rb

This file was deleted.

28 changes: 0 additions & 28 deletions Library/Homebrew/extend/os/mac/utils/copy.rb

This file was deleted.

3 changes: 1 addition & 2 deletions Library/Homebrew/extend/pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
require "metafiles"
require "extend/file/atomic"
require "system_command"
require "utils/copy"

module DiskUsageExtension
sig { returns(Integer) }
Expand Down Expand Up @@ -227,7 +226,7 @@ def cp_path_sub(pattern, replacement)
else
dst.dirname.mkpath
dst = yield(self, dst) if block_given?
Utils::Copy.with_attributes(self, dst)
FileUtils.cp(self, dst)
end
end

Expand Down
20 changes: 0 additions & 20 deletions Library/Homebrew/sorbet/rbi/upstream.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,3 @@

# 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
5 changes: 2 additions & 3 deletions Library/Homebrew/test/cask/artifact/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,8 @@
allow(command).to receive(:run!).with(any_args).and_call_original

expect(command).to receive(:run!)
.with(a_string_ending_with("cp"),
hash_including(args: include(source_contents_path, target_path),
sudo: true))
.with("/bin/cp", args: ["-pR", source_contents_path, target_path],
sudo: true)
.and_call_original
expect(FileUtils).not_to receive(:move).with(source_contents_path, an_instance_of(Pathname))

Expand Down
1 change: 0 additions & 1 deletion Library/Homebrew/test/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@

RSpec::Matchers.define_negated_matcher :not_to_output, :output
RSpec::Matchers.alias_matcher :have_failed, :be_failed
RSpec::Matchers.define_negated_matcher :exclude, :include

# Match consecutive elements in an array.
RSpec::Matchers.define :array_including_cons do |*cons|
Expand Down
146 changes: 0 additions & 146 deletions Library/Homebrew/test/utils/copy_spec.rb

This file was deleted.

4 changes: 1 addition & 3 deletions Library/Homebrew/unpack_strategy/bzip2.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# typed: true
# frozen_string_literal: true

require "utils/copy"

module UnpackStrategy
# Strategy for unpacking bzip2 archives.
class Bzip2
Expand All @@ -21,7 +19,7 @@ def self.can_extract?(path)

sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose:)
Utils::Copy.with_attributes path, unpack_dir/basename
FileUtils.cp path, unpack_dir/basename, preserve: true
quiet_flags = verbose ? [] : ["-q"]
system_command! "bunzip2",
args: [*quiet_flags, unpack_dir/basename],
Expand Down
10 changes: 4 additions & 6 deletions Library/Homebrew/unpack_strategy/directory.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# typed: true
# frozen_string_literal: true

require "utils/copy"

module UnpackStrategy
# Strategy for unpacking directories.
class Directory
Expand All @@ -22,10 +20,10 @@ def self.can_extract?(path)
sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose:)
path.children.each do |child|
Utils::Copy.recursive_with_attributes (child.directory? && !child.symlink?) ? "#{child}/." : child,
unpack_dir/child.basename,
force_command: true,
verbose:
system_command! "cp",
args: ["-pR", (child.directory? && !child.symlink?) ? "#{child}/." : child,
unpack_dir/child.basename],
verbose:
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions Library/Homebrew/unpack_strategy/gzip.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# typed: true
# frozen_string_literal: true

require "utils/copy"

module UnpackStrategy
# Strategy for unpacking gzip archives.
class Gzip
Expand All @@ -21,7 +19,7 @@ def self.can_extract?(path)

sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose:)
Utils::Copy.with_attributes path, unpack_dir/basename
FileUtils.cp path, unpack_dir/basename, preserve: true
quiet_flags = verbose ? [] : ["-q"]
system_command! "gunzip",
args: [*quiet_flags, "-N", "--", unpack_dir/basename],
Expand Down
4 changes: 1 addition & 3 deletions Library/Homebrew/unpack_strategy/lzip.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# typed: true
# frozen_string_literal: true

require "utils/copy"

module UnpackStrategy
# Strategy for unpacking lzip archives.
class Lzip
Expand All @@ -25,7 +23,7 @@

sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose:)
Utils::Copy.with_attributes path, unpack_dir/basename
FileUtils.cp path, unpack_dir/basename, preserve: true

Check warning on line 26 in Library/Homebrew/unpack_strategy/lzip.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/unpack_strategy/lzip.rb#L26

Added line #L26 was not covered by tests
quiet_flags = verbose ? [] : ["-q"]
system_command! "lzip",
args: ["-d", *quiet_flags, unpack_dir/basename],
Expand Down
4 changes: 1 addition & 3 deletions Library/Homebrew/unpack_strategy/lzma.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# typed: true
# frozen_string_literal: true

require "utils/copy"

module UnpackStrategy
# Strategy for unpacking LZMA archives.
class Lzma
Expand All @@ -25,7 +23,7 @@

sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose:)
Utils::Copy.with_attributes path, unpack_dir/basename
FileUtils.cp path, unpack_dir/basename, preserve: true

Check warning on line 26 in Library/Homebrew/unpack_strategy/lzma.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/unpack_strategy/lzma.rb#L26

Added line #L26 was not covered by tests
quiet_flags = verbose ? [] : ["-q"]
system_command! "unlzma",
args: [*quiet_flags, "--", unpack_dir/basename],
Expand Down
4 changes: 1 addition & 3 deletions Library/Homebrew/unpack_strategy/uncompressed.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# typed: strict
# frozen_string_literal: true

require "utils/copy"

module UnpackStrategy
# Strategy for unpacking uncompressed files.
class Uncompressed
Expand All @@ -24,7 +22,7 @@ def extract_nestedly(to: nil, basename: nil, verbose: false, prioritize_extensio

sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose: false)
Utils::Copy.with_attributes path, unpack_dir/basename.sub(/^[\da-f]{64}--/, ""), verbose:
FileUtils.cp path, unpack_dir/basename.sub(/^[\da-f]{64}--/, ""), preserve: true, verbose:
end
end
end
Loading