Skip to content

Commit 3f7e63a

Browse files
authored
Merge pull request #3492 from amyspark/fix-latest-casks
Properly upgrade Casks with version :latest
2 parents 6cf38d0 + 96187ad commit 3f7e63a

File tree

6 files changed

+81
-5
lines changed

6 files changed

+81
-5
lines changed

Diff for: Library/Homebrew/cask/lib/hbc/artifact/moved.rb

-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ def move_back(skip: false, force: false, command: nil, **options)
7070
else
7171
command.run("/bin/mv", args: [target, source], sudo: true)
7272
end
73-
74-
add_altname_metadata(target, source.basename, command: command)
7573
end
7674

7775
def delete(target, force: false, command: nil, **_)

Diff for: Library/Homebrew/cask/lib/hbc/cli/upgrade.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ def run
5555

5656
new_cask_installer.fetch
5757

58-
new_cask_installer.stage
59-
6058
# Move the old Cask's artifacts back to staging
6159
old_cask_installer.start_upgrade
6260
# And flag it so in case of error
6361
started_upgrade = true
6462

6563
# Install the new Cask
64+
new_cask_installer.stage
65+
6666
new_cask_installer.install_artifacts
6767
new_artifacts_installed = true
6868

Diff for: Library/Homebrew/cask/lib/hbc/installer.rb

+45-1
Original file line numberDiff line numberDiff line change
@@ -360,16 +360,33 @@ def start_upgrade
360360

361361
disable_accessibility_access
362362
uninstall_artifacts
363+
backup
364+
end
365+
366+
def backup
367+
@cask.staged_path.rename backup_path
368+
@cask.metadata_versioned_path.rename backup_metadata_path
369+
end
370+
371+
def restore_backup
372+
return unless backup_path.directory? && backup_metadata_path.directory?
373+
374+
Pathname.new(@cask.staged_path).rmtree if @cask.staged_path.exist?
375+
Pathname.new(@cask.metadata_versioned_path).rmtree if @cask.metadata_versioned_path.exist?
376+
377+
backup_path.rename @cask.staged_path
378+
backup_metadata_path.rename @cask.metadata_versioned_path
363379
end
364380

365381
def revert_upgrade
366382
opoo "Reverting upgrade for Cask #{@cask}"
383+
restore_backup
367384
install_artifacts
368385
enable_accessibility_access
369386
end
370387

371388
def finalize_upgrade
372-
purge_versioned_files
389+
purge_backed_up_versioned_files
373390

374391
puts summary
375392
end
@@ -402,10 +419,37 @@ def zap
402419
purge_caskroom_path
403420
end
404421

422+
def backup_path
423+
return nil if @cask.staged_path.nil?
424+
Pathname.new "#{@cask.staged_path}.upgrading"
425+
end
426+
427+
def backup_metadata_path
428+
return nil if @cask.metadata_versioned_path.nil?
429+
Pathname.new "#{@cask.metadata_versioned_path}.upgrading"
430+
end
431+
405432
def gain_permissions_remove(path)
406433
Utils.gain_permissions_remove(path, command: @command)
407434
end
408435

436+
def purge_backed_up_versioned_files
437+
ohai "Purging files for version #{@cask.version} of Cask #{@cask}"
438+
439+
# versioned staged distribution
440+
gain_permissions_remove(backup_path) if !backup_path.nil? && backup_path.exist?
441+
442+
# Homebrew-Cask metadata
443+
if backup_metadata_path.directory?
444+
backup_metadata_path.children.each do |subdir|
445+
unless PERSISTENT_METADATA_SUBDIRS.include?(subdir.basename)
446+
gain_permissions_remove(subdir)
447+
end
448+
end
449+
end
450+
backup_metadata_path.rmdir_if_possible
451+
end
452+
409453
def purge_versioned_files
410454
ohai "Purging files for version #{@cask.version} of Cask #{@cask}"
411455

Diff for: Library/Homebrew/test/cask/cli/upgrade_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"outdated/local-caffeine",
1010
"outdated/local-transmission",
1111
"outdated/auto-updates",
12+
"outdated/version-latest",
1213
]
1314
}
1415

@@ -103,6 +104,9 @@
103104
auto_updates_path = Hbc.appdir.join("MyFancyApp.app")
104105
local_transmission = Hbc::CaskLoader.load("local-transmission")
105106
local_transmission_path = Hbc.appdir.join("Transmission.app")
107+
version_latest = Hbc::CaskLoader.load("version-latest")
108+
version_latest_path_1 = Hbc.appdir.join("Caffeine Mini.app")
109+
version_latest_path_2 = Hbc.appdir.join("Caffeine Pro.app")
106110

107111
expect(local_caffeine).to be_installed
108112
expect(local_caffeine_path).to be_a_directory
@@ -116,6 +120,11 @@
116120
expect(local_transmission_path).to be_a_directory
117121
expect(local_transmission.versions).to include("2.60")
118122

123+
expect(version_latest).to be_installed
124+
expect(version_latest_path_1).to be_a_directory
125+
expect(version_latest_path_2).to be_a_directory
126+
expect(version_latest.versions).to include("latest")
127+
119128
described_class.run("--greedy")
120129

121130
expect(local_caffeine).to be_installed
@@ -129,6 +138,11 @@
129138
expect(local_transmission).to be_installed
130139
expect(local_transmission_path).to be_a_directory
131140
expect(local_transmission.versions).to include("2.61")
141+
142+
expect(version_latest).to be_installed
143+
expect(version_latest_path_1).to be_a_directory
144+
expect(version_latest_path_2).to be_a_directory
145+
expect(version_latest.versions).to include("latest")
132146
end
133147

134148
it 'does not include the Casks with "auto_updates true" when the version did not change' do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cask 'version-latest' do
2+
version :latest
3+
sha256 :no_check
4+
5+
url "file://#{TEST_FIXTURE_DIR}/cask/caffeines.zip"
6+
homepage 'http://example.com/local-caffeine'
7+
8+
app 'Caffeine Mini.app'
9+
app 'Caffeine Pro.app'
10+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cask 'version-latest' do
2+
version :latest
3+
sha256 :no_check
4+
5+
url "file://#{TEST_FIXTURE_DIR}/cask/caffeines.zip"
6+
homepage 'http://example.com/local-caffeine'
7+
8+
app 'Caffeine Mini.app'
9+
app 'Caffeine Pro.app'
10+
end

0 commit comments

Comments
 (0)