From 10a0662dc013d7fd6949dce0a1bb75a1ec2bf91a Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Tue, 28 Nov 2017 00:29:45 +0000 Subject: [PATCH 01/11] Test upgrade for Casks with version :latest --- Library/Homebrew/test/cask/cli/upgrade_spec.rb | 14 ++++++++++++++ .../fixtures/cask/Casks/outdated/version-latest.rb | 10 ++++++++++ .../support/fixtures/cask/Casks/version-latest.rb | 10 ++++++++++ 3 files changed, 34 insertions(+) create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/outdated/version-latest.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/version-latest.rb diff --git a/Library/Homebrew/test/cask/cli/upgrade_spec.rb b/Library/Homebrew/test/cask/cli/upgrade_spec.rb index 5f389d6950..49775156e6 100644 --- a/Library/Homebrew/test/cask/cli/upgrade_spec.rb +++ b/Library/Homebrew/test/cask/cli/upgrade_spec.rb @@ -9,6 +9,7 @@ describe Hbc::CLI::Upgrade, :cask do "outdated/local-caffeine", "outdated/local-transmission", "outdated/auto-updates", + "outdated/version-latest", ] } @@ -103,6 +104,9 @@ describe Hbc::CLI::Upgrade, :cask do auto_updates_path = Hbc.appdir.join("MyFancyApp.app") local_transmission = Hbc::CaskLoader.load("local-transmission") local_transmission_path = Hbc.appdir.join("Transmission.app") + version_latest = Hbc::CaskLoader.load("version-latest") + version_latest_path_1 = Hbc.appdir.join("Caffeine Mini.app") + version_latest_path_2 = Hbc.appdir.join("Caffeine Pro.app") expect(local_caffeine).to be_installed expect(local_caffeine_path).to be_a_directory @@ -116,6 +120,11 @@ describe Hbc::CLI::Upgrade, :cask do expect(local_transmission_path).to be_a_directory expect(local_transmission.versions).to include("2.60") + expect(version_latest).to be_installed + expect(version_latest_path_1).to be_a_directory + expect(version_latest_path_2).to be_a_directory + expect(version_latest.versions).to include("latest") + described_class.run("--greedy") expect(local_caffeine).to be_installed @@ -129,6 +138,11 @@ describe Hbc::CLI::Upgrade, :cask do expect(local_transmission).to be_installed expect(local_transmission_path).to be_a_directory expect(local_transmission.versions).to include("2.61") + + expect(version_latest).to be_installed + expect(version_latest_path_1).to be_a_directory + expect(version_latest_path_2).to be_a_directory + expect(version_latest.versions).to include("latest") end it 'does not include the Casks with "auto_updates true" when the version did not change' do diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/outdated/version-latest.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/outdated/version-latest.rb new file mode 100644 index 0000000000..2ac869f896 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/outdated/version-latest.rb @@ -0,0 +1,10 @@ +cask 'version-latest' do + version :latest + sha256 :no_check + + url "file://#{TEST_FIXTURE_DIR}/cask/caffeines.zip" + homepage 'http://example.com/local-caffeine' + + app 'Caffeine Mini.app' + app 'Caffeine Pro.app' +end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/version-latest.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/version-latest.rb new file mode 100644 index 0000000000..2ac869f896 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/version-latest.rb @@ -0,0 +1,10 @@ +cask 'version-latest' do + version :latest + sha256 :no_check + + url "file://#{TEST_FIXTURE_DIR}/cask/caffeines.zip" + homepage 'http://example.com/local-caffeine' + + app 'Caffeine Mini.app' + app 'Caffeine Pro.app' +end From f3355b2a2c4a2128427af425efac1df5a336ba5e Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Tue, 28 Nov 2017 13:00:08 +0000 Subject: [PATCH 02/11] Stage to a different directory if upgrading Casks w/version :latest --- Library/Homebrew/cask/lib/hbc/cli/upgrade.rb | 4 +-- Library/Homebrew/cask/lib/hbc/installer.rb | 32 ++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb b/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb index bd80ad6905..808b64c4b7 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb @@ -55,14 +55,14 @@ module Hbc new_cask_installer.fetch - new_cask_installer.stage - # Move the old Cask's artifacts back to staging old_cask_installer.start_upgrade # And flag it so in case of error started_upgrade = true # Install the new Cask + new_cask_installer.stage + new_cask_installer.install_artifacts new_artifacts_installed = true diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 6056250fc0..84a8ac9b74 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -378,10 +378,26 @@ module Hbc disable_accessibility_access uninstall_artifacts + backup if version_is_latest? + end + + def backup + @cask.staged_path.rename backup_path(@cask.staged_path) + end + + def restore_backup + path = backup_path(@cask.staged_path) + + return unless path.directory? + + Pathname.new(@cask.staged_path).rmtree if @cask.staged_path.exist? + + path.rename @cask.staged_path end def revert_upgrade opoo "Reverting upgrade for Cask #{@cask}" + restore_backup if version_is_latest? install_artifacts enable_accessibility_access end @@ -420,6 +436,14 @@ module Hbc purge_caskroom_path end + def backup_path(path) + Pathname.new "#{path}.upgrading" unless path.nil? + end + + def version_is_latest? + @cask.versions.include?("latest") + end + def gain_permissions_remove(path) Utils.gain_permissions_remove(path, command: @command) end @@ -428,11 +452,15 @@ module Hbc ohai "Purging files for version #{@cask.version} of Cask #{@cask}" # versioned staged distribution - gain_permissions_remove(@cask.staged_path) if !@cask.staged_path.nil? && @cask.staged_path.exist? + staged_path = version_is_latest? ? + backup_path(@cask.staged_path) : @cask.staged_path + + gain_permissions_remove(staged_path) if !staged_path.nil? && staged_path.exist? # Homebrew-Cask metadata if @cask.metadata_versioned_path.respond_to?(:children) && - @cask.metadata_versioned_path.exist? + @cask.metadata_versioned_path.exist? && + !version_is_latest? @cask.metadata_versioned_path.children.each do |subdir| unless PERSISTENT_METADATA_SUBDIRS.include?(subdir.basename) gain_permissions_remove(subdir) From 8386b9384c30be142d76da3ae2e24da1bb166bde Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Tue, 28 Nov 2017 13:34:50 +0000 Subject: [PATCH 03/11] Solve styling and metadata issues --- Library/Homebrew/cask/lib/hbc/artifact/moved.rb | 2 +- Library/Homebrew/cask/lib/hbc/installer.rb | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb index 11e019af2c..dfd6008cf0 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb @@ -71,7 +71,7 @@ module Hbc command.run("/bin/mv", args: [target, source], sudo: true) end - add_altname_metadata(target, source.basename, command: command) + add_altname_metadata(source, target.basename, command: command) end def delete(target, force: false, command: nil, **_) diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 84a8ac9b74..3dd2a79907 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -452,8 +452,11 @@ module Hbc ohai "Purging files for version #{@cask.version} of Cask #{@cask}" # versioned staged distribution - staged_path = version_is_latest? ? - backup_path(@cask.staged_path) : @cask.staged_path + if version_is_latest? + staged_path = backup_path(@cask.staged_path) + else + staged_path = @cask.staged_path + end gain_permissions_remove(staged_path) if !staged_path.nil? && staged_path.exist? From 2ff114bc32ce677ed133ea805e4686214aaf8153 Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Tue, 28 Nov 2017 14:29:53 +0000 Subject: [PATCH 04/11] Use the proper path when purging metadata --- Library/Homebrew/cask/lib/hbc/installer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 3dd2a79907..30d5f30be8 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -452,7 +452,7 @@ module Hbc ohai "Purging files for version #{@cask.version} of Cask #{@cask}" # versioned staged distribution - if version_is_latest? + if upgrade? && version_is_latest? staged_path = backup_path(@cask.staged_path) else staged_path = @cask.staged_path @@ -463,7 +463,7 @@ module Hbc # Homebrew-Cask metadata if @cask.metadata_versioned_path.respond_to?(:children) && @cask.metadata_versioned_path.exist? && - !version_is_latest? + !(upgrade? && version_is_latest?) @cask.metadata_versioned_path.children.each do |subdir| unless PERSISTENT_METADATA_SUBDIRS.include?(subdir.basename) gain_permissions_remove(subdir) From 9458e985b79d4c9fca78ed0beab07a5c72d31c3e Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Tue, 28 Nov 2017 17:37:36 +0000 Subject: [PATCH 05/11] Always backup the old Cask prior to upgrade (and if doing so, correctly set the staged_path when purging it) --- Library/Homebrew/cask/lib/hbc/installer.rb | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 30d5f30be8..ca13f7eed7 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -29,9 +29,10 @@ module Hbc @require_sha = require_sha @reinstall = false @upgrade = upgrade + @backed_up = false end - attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?, :upgrade?, :verbose? + attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?, :upgrade?, :verbose?, :backed_up? def self.print_caveats(cask) odebug "Printing caveats" @@ -378,26 +379,26 @@ module Hbc disable_accessibility_access uninstall_artifacts - backup if version_is_latest? + backup end def backup - @cask.staged_path.rename backup_path(@cask.staged_path) + @backed_up = true + @cask.staged_path.rename backup_path end def restore_backup - path = backup_path(@cask.staged_path) - - return unless path.directory? + return unless backup_path.directory? Pathname.new(@cask.staged_path).rmtree if @cask.staged_path.exist? - path.rename @cask.staged_path + backup_path.rename @cask.staged_path + @backed_up = false end def revert_upgrade opoo "Reverting upgrade for Cask #{@cask}" - restore_backup if version_is_latest? + restore_backup install_artifacts enable_accessibility_access end @@ -436,8 +437,13 @@ module Hbc purge_caskroom_path end - def backup_path(path) - Pathname.new "#{path}.upgrading" unless path.nil? + def backup_path + return nil if @cask.staged_path.nil? + if backed_up? + Pathname.new "#{@cask.staged_path}.upgrading" + else + @cask.staged_path + end end def version_is_latest? @@ -452,8 +458,8 @@ module Hbc ohai "Purging files for version #{@cask.version} of Cask #{@cask}" # versioned staged distribution - if upgrade? && version_is_latest? - staged_path = backup_path(@cask.staged_path) + if upgrade? + staged_path = backup_path else staged_path = @cask.staged_path end From 9227c8fe3c09cecf551cca060ee45c37cfc30be6 Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Tue, 28 Nov 2017 18:03:57 +0000 Subject: [PATCH 06/11] Try #2 at handling backed up Casks Avoid using variables altogether; fork out the purge into two specialized + one common function --- Library/Homebrew/cask/lib/hbc/installer.rb | 33 +++++++++++----------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index ca13f7eed7..83dcf2a557 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -29,7 +29,6 @@ module Hbc @require_sha = require_sha @reinstall = false @upgrade = upgrade - @backed_up = false end attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?, :upgrade?, :verbose?, :backed_up? @@ -383,7 +382,6 @@ module Hbc end def backup - @backed_up = true @cask.staged_path.rename backup_path end @@ -393,7 +391,6 @@ module Hbc Pathname.new(@cask.staged_path).rmtree if @cask.staged_path.exist? backup_path.rename @cask.staged_path - @backed_up = false end def revert_upgrade @@ -404,7 +401,7 @@ module Hbc end def finalize_upgrade - purge_versioned_files + purge_backed_versioned_files puts summary end @@ -439,11 +436,7 @@ module Hbc def backup_path return nil if @cask.staged_path.nil? - if backed_up? - Pathname.new "#{@cask.staged_path}.upgrading" - else - @cask.staged_path - end + Pathname.new "#{@cask.staged_path}.upgrading" end def version_is_latest? @@ -454,19 +447,27 @@ module Hbc Utils.gain_permissions_remove(path, command: @command) end + def purge_backed_versioned_files + ohai "Purging files for version #{@cask.version} of Cask #{@cask}" + + # versioned staged distribution + gain_permissions_remove(backup_path) if !backup_path.nil? && backup_path.exist? + + # Homebrew-Cask metadata + purge_metadata + end + def purge_versioned_files ohai "Purging files for version #{@cask.version} of Cask #{@cask}" # versioned staged distribution - if upgrade? - staged_path = backup_path - else - staged_path = @cask.staged_path - end - - gain_permissions_remove(staged_path) if !staged_path.nil? && staged_path.exist? + gain_permissions_remove(@cask.staged_path) if !@cask.staged_path.nil? && @cask.staged_path.exist? # Homebrew-Cask metadata + purge_metadata + end + + def purge_metadata if @cask.metadata_versioned_path.respond_to?(:children) && @cask.metadata_versioned_path.exist? && !(upgrade? && version_is_latest?) From 5840b2fa6842877b1ce8233d3139d4178e48b05a Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Tue, 28 Nov 2017 20:36:36 +0000 Subject: [PATCH 07/11] Rename purge_backed_versioned_files to purge_backed_up_versioned_files --- Library/Homebrew/cask/lib/hbc/installer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 83dcf2a557..ac04c42141 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -401,7 +401,7 @@ module Hbc end def finalize_upgrade - purge_backed_versioned_files + purge_backed_up_versioned_files puts summary end @@ -447,7 +447,7 @@ module Hbc Utils.gain_permissions_remove(path, command: @command) end - def purge_backed_versioned_files + def purge_backed_up_versioned_files ohai "Purging files for version #{@cask.version} of Cask #{@cask}" # versioned staged distribution From 63961ac4655851b6ec0141fc4bf8b3f97240bc91 Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Tue, 28 Nov 2017 21:00:16 +0000 Subject: [PATCH 08/11] Fully separate purge_versioned_files --- Library/Homebrew/cask/lib/hbc/installer.rb | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index ac04c42141..d56d10cc6c 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -383,14 +383,17 @@ module Hbc def backup @cask.staged_path.rename backup_path + @cask.metadata_versioned_path.rename backup_metadata_path end def restore_backup - return unless backup_path.directory? + return unless backup_path.directory? && backup_metadata_path.directory? Pathname.new(@cask.staged_path).rmtree if @cask.staged_path.exist? + Pathname.new(@cask.metadata_versioned_path).rmtree if @cask.metadata_versioned_path.exist? backup_path.rename @cask.staged_path + backup_metadata_path.rename @cask.metadata_versioned_path end def revert_upgrade @@ -439,6 +442,11 @@ module Hbc Pathname.new "#{@cask.staged_path}.upgrading" end + def backup_metadata_path + return nil if @cask.metadata_versioned_path.nil? + Pathname.new "#{@cask.metadata_versioned_path}.upgrading" + end + def version_is_latest? @cask.versions.include?("latest") end @@ -454,7 +462,19 @@ module Hbc gain_permissions_remove(backup_path) if !backup_path.nil? && backup_path.exist? # Homebrew-Cask metadata - purge_metadata + if backup_metadata_path.respond_to?(:children) && + backup_metadata_path.exist? && + backup_metadata_path.children.each do |subdir| + unless PERSISTENT_METADATA_SUBDIRS.include?(subdir.basename) + gain_permissions_remove(subdir) + end + end + end + backup_metadata_path.rmdir_if_possible + @cask.metadata_master_container_path.rmdir_if_possible unless upgrade? + + # toplevel staged distribution + @cask.caskroom_path.rmdir_if_possible unless upgrade? end def purge_versioned_files @@ -464,13 +484,8 @@ module Hbc gain_permissions_remove(@cask.staged_path) if !@cask.staged_path.nil? && @cask.staged_path.exist? # Homebrew-Cask metadata - purge_metadata - end - - def purge_metadata if @cask.metadata_versioned_path.respond_to?(:children) && - @cask.metadata_versioned_path.exist? && - !(upgrade? && version_is_latest?) + @cask.metadata_versioned_path.exist? @cask.metadata_versioned_path.children.each do |subdir| unless PERSISTENT_METADATA_SUBDIRS.include?(subdir.basename) gain_permissions_remove(subdir) From 657d4eaee9eccecea6052c5759ea68e31e28693e Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Tue, 28 Nov 2017 23:55:05 +0000 Subject: [PATCH 09/11] Remove unused backup and metadata logic --- Library/Homebrew/cask/lib/hbc/installer.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index d56d10cc6c..5879cd3e1c 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -31,7 +31,7 @@ module Hbc @upgrade = upgrade end - attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?, :upgrade?, :verbose?, :backed_up? + attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?, :upgrade?, :verbose? def self.print_caveats(cask) odebug "Printing caveats" @@ -447,10 +447,6 @@ module Hbc Pathname.new "#{@cask.metadata_versioned_path}.upgrading" end - def version_is_latest? - @cask.versions.include?("latest") - end - def gain_permissions_remove(path) Utils.gain_permissions_remove(path, command: @command) end @@ -471,10 +467,6 @@ module Hbc end end backup_metadata_path.rmdir_if_possible - @cask.metadata_master_container_path.rmdir_if_possible unless upgrade? - - # toplevel staged distribution - @cask.caskroom_path.rmdir_if_possible unless upgrade? end def purge_versioned_files From ab62be5345ddd30813aef1d1772a131bd0c32fa5 Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Wed, 29 Nov 2017 01:02:50 +0000 Subject: [PATCH 10/11] Implement @reitermarkus's comments Leftover && and remove xattr "copy" --- Library/Homebrew/cask/lib/hbc/artifact/moved.rb | 2 -- Library/Homebrew/cask/lib/hbc/installer.rb | 12 ++++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb index dfd6008cf0..f5ef790ebb 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb @@ -70,8 +70,6 @@ module Hbc else command.run("/bin/mv", args: [target, source], sudo: true) end - - add_altname_metadata(source, target.basename, command: command) end def delete(target, force: false, command: nil, **_) diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 5879cd3e1c..f7b8379590 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -459,12 +459,12 @@ module Hbc # Homebrew-Cask metadata if backup_metadata_path.respond_to?(:children) && - backup_metadata_path.exist? && - backup_metadata_path.children.each do |subdir| - unless PERSISTENT_METADATA_SUBDIRS.include?(subdir.basename) - gain_permissions_remove(subdir) - end - end + backup_metadata_path.exist? + backup_metadata_path.children.each do |subdir| + unless PERSISTENT_METADATA_SUBDIRS.include?(subdir.basename) + gain_permissions_remove(subdir) + end + end end backup_metadata_path.rmdir_if_possible end From 96187ade92c9ab222a5bc03aae96aa80ba80a6ae Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Wed, 29 Nov 2017 01:11:30 +0000 Subject: [PATCH 11/11] Leftover of @reitermarkus's comments Simplify a condition --- Library/Homebrew/cask/lib/hbc/installer.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index f7b8379590..553d947f9f 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -458,8 +458,7 @@ module Hbc gain_permissions_remove(backup_path) if !backup_path.nil? && backup_path.exist? # Homebrew-Cask metadata - if backup_metadata_path.respond_to?(:children) && - backup_metadata_path.exist? + if backup_metadata_path.directory? backup_metadata_path.children.each do |subdir| unless PERSISTENT_METADATA_SUBDIRS.include?(subdir.basename) gain_permissions_remove(subdir)