diff --git a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb index 11e019af2c..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(target, source.basename, command: command) end def delete(target, force: false, command: nil, **_) 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 b2087e643d..8520f154db 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -360,16 +360,33 @@ module Hbc disable_accessibility_access uninstall_artifacts + backup + end + + 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? && 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 opoo "Reverting upgrade for Cask #{@cask}" + restore_backup install_artifacts enable_accessibility_access end def finalize_upgrade - purge_versioned_files + purge_backed_up_versioned_files puts summary end @@ -402,10 +419,37 @@ module Hbc purge_caskroom_path end + def backup_path + return nil if @cask.staged_path.nil? + 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 gain_permissions_remove(path) Utils.gain_permissions_remove(path, command: @command) end + def purge_backed_up_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 + if backup_metadata_path.directory? + 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 + def purge_versioned_files ohai "Purging files for version #{@cask.version} of Cask #{@cask}" 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