From 432e0c6b5bda70ad54610236d7e85f55f5f83bff Mon Sep 17 00:00:00 2001 From: JBYoshi <12983479+JBYoshi@users.noreply.github.com> Date: Mon, 24 Apr 2023 10:59:01 -0500 Subject: [PATCH] Extract artifact checks to matching_artifact? function. --- Library/Homebrew/cask/artifact/moved.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cask/artifact/moved.rb b/Library/Homebrew/cask/artifact/moved.rb index 5976146726..cefa8a029f 100644 --- a/Library/Homebrew/cask/artifact/moved.rb +++ b/Library/Homebrew/cask/artifact/moved.rb @@ -42,9 +42,7 @@ module Cask end if Utils.path_occupied?(target) - if !predecessor.nil? && target.directory? && target.children.empty? && predecessor.artifacts.any? do |a| - a.instance_of?(self.class) && instance_of?(a.class) && a.target == target - end + if target.directory? && target.children.empty? && matching_artifact?(predecessor) # An upgrade removed the directory contents but left the directory itself (see below). unless source.directory? if target.parent.writable? && !force @@ -124,6 +122,14 @@ module Cask add_altname_metadata(target, source.basename, command: command) end + def matching_artifact?(cask) + return false unless cask + + cask.artifacts.any? do |a| + a.instance_of?(self.class) && instance_of?(a.class) && a.target == target + end + end + def move_back(skip: false, force: false, command: nil, **options) FileUtils.rm source if source.symlink? && source.dirname.join(source.readlink) == target @@ -157,9 +163,7 @@ module Cask return unless Utils.path_occupied?(target) - if !successor.nil? && target.directory? && successor.artifacts.any? do |a| - a.instance_of?(self.class) && instance_of?(a.class) && a.target == self.target - end + if target.directory? && matching_artifact?(successor) # If an app folder is deleted, macOS considers the app uninstalled and removes some data. # Remove only the contents to handle this case. target.children.each do |child|