Skip to content

Commit e5d084d

Browse files
authored
Merge pull request #23608 from aholland/quarantine-skip-unavailable
cask/upgrade: don't read quarantine metadata when quarantine is unavailable
2 parents e554f97 + e81d4ab commit e5d084d

2 files changed

Lines changed: 34 additions & 14 deletions

File tree

Library/Homebrew/cask/upgrade.rb

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -427,21 +427,27 @@ def self.upgrade_cask(
427427

428428
new_cask_installer.fetch
429429

430-
old_cask.artifacts.grep(Artifact::App).each do |artifact|
431-
user_approved = if artifact.target.exist?
432-
Quarantine.user_approved?(artifact.target)
433-
else
434-
false
435-
end
436-
old_user_approved[artifact.target.to_s] = user_approved
437-
# Only an already approved app has approvals to pass on, so skip the scan otherwise.
438-
old_approved_paths[artifact.target.to_s] = Quarantine.user_approved_paths(artifact.target) if user_approved
439-
old_unquarantined[artifact.target.to_s] = if artifact.target.exist?
440-
Quarantine.detect(artifact.target).blank?
441-
else
442-
false
430+
# This snapshot reads quarantine metadata, so it needs the same guard as the code below that uses it.
431+
if Quarantine.available?
432+
old_cask.artifacts.grep(Artifact::App).each do |artifact|
433+
user_approved = if artifact.target.exist?
434+
Quarantine.user_approved?(artifact.target)
435+
else
436+
false
437+
end
438+
old_user_approved[artifact.target.to_s] = user_approved
439+
# Only an already approved app has approvals to pass on, so skip the scan otherwise.
440+
if user_approved
441+
old_approved_paths[artifact.target.to_s] =
442+
Quarantine.user_approved_paths(artifact.target)
443+
end
444+
old_unquarantined[artifact.target.to_s] = if artifact.target.exist?
445+
Quarantine.detect(artifact.target).blank?
446+
else
447+
false
448+
end
449+
old_signing_identities[artifact.target.to_s] = Quarantine.signing_identity(artifact.target)
443450
end
444-
old_signing_identities[artifact.target.to_s] = Quarantine.signing_identity(artifact.target)
445451
end
446452

447453
# Move the old cask's artifacts back to staging

Library/Homebrew/test/cask/upgrade_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,20 @@ def write_info_plist(path, short_version:, bundle_version:)
768768
end
769769
end
770770

771+
context "when quarantine support is unavailable" do
772+
before do
773+
Cask::Installer.new(Cask::CaskLoader.load(cask_path("outdated/local-caffeine"))).install
774+
end
775+
776+
it "upgrades without reading quarantine metadata" do
777+
allow(Cask::Quarantine).to receive(:available?).and_return(false)
778+
expect(Cask::Quarantine).not_to receive(:detect)
779+
780+
expect { described_class.upgrade_casks!(local_caffeine, args:) }
781+
.to change(local_caffeine, :installed_version).from("1.2.2").to("1.2.3")
782+
end
783+
end
784+
771785
context "when upgrading after a forced upgrade without a cask receipt" do
772786
before do
773787
InstallHelper.stub_cask_installation(Cask::CaskLoader.load(cask_path("outdated/local-caffeine")))

0 commit comments

Comments
 (0)