From 7e35ae25d5d16c73281ea6d040d8bb6caaa19bf5 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 1 Apr 2024 16:22:42 +0100 Subject: [PATCH] cask/utils: quieten down when fixing permissions fails. When fixing permissions fails, we should not print the error messages from e.g. `chmod` unless we are in debug or verbose mode (because we immediately retry taking ownership `sudo`). --- Library/Homebrew/cask/utils.rb | 4 ++++ Library/Homebrew/test/cask/artifact/app_spec.rb | 7 +------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cask/utils.rb b/Library/Homebrew/cask/utils.rb index f32f99b5963ef..4f8f2afffaec9 100644 --- a/Library/Homebrew/cask/utils.rb +++ b/Library/Homebrew/cask/utils.rb @@ -68,15 +68,19 @@ def self.gain_permissions(path, command_args, command) rescue # in case of permissions problems unless tried_permissions + print_stderr = Context.current.debug? || Context.current.verbose? # TODO: Better handling for the case where path is a symlink. # The -h and -R flags cannot be combined, and behavior is # dependent on whether the file argument has a trailing # slash. This should do the right thing, but is fragile. command.run("/usr/bin/chflags", + print_stderr:, args: command_args + ["--", "000", path]) command.run("/bin/chmod", + print_stderr:, args: command_args + ["--", "u+rwx", path]) command.run("/bin/chmod", + print_stderr:, args: command_args + ["-N", path]) tried_permissions = true retry # rmtree diff --git a/Library/Homebrew/test/cask/artifact/app_spec.rb b/Library/Homebrew/test/cask/artifact/app_spec.rb index 667cbbc8c762c..95cc8d9a8b446 100644 --- a/Library/Homebrew/test/cask/artifact/app_spec.rb +++ b/Library/Homebrew/test/cask/artifact/app_spec.rb @@ -171,12 +171,7 @@ end it "overwrites the existing app" do - expect(command).to receive(:run).with("/usr/bin/chflags", - args: ["-R", "--", "000", target_path]).and_call_original - expect(command).to receive(:run).with("/bin/chmod", - args: ["-R", "--", "u+rwx", target_path]).and_call_original - expect(command).to receive(:run).with("/bin/chmod", - args: ["-R", "-N", target_path]).and_call_original + expect(command).to receive(:run).and_call_original.at_least(:once) stdout = <<~EOS ==> Removing App '#{target_path}'