Don't remove cask directories when upgrading.
Fixes Homebrew/homebrew-cask#102721.
This commit is contained in:
parent
a88397096d
commit
8c4f29d983
@ -34,39 +34,50 @@ module Cask
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def move(adopt: false, force: false, verbose: false, command: nil, **options)
|
def move(adopt: false, force: false, verbose: false, upgrade: false, command: nil, **options)
|
||||||
unless source.exist?
|
unless source.exist?
|
||||||
raise CaskError, "It seems the #{self.class.english_name} source '#{source}' is not there."
|
raise CaskError, "It seems the #{self.class.english_name} source '#{source}' is not there."
|
||||||
end
|
end
|
||||||
|
|
||||||
if Utils.path_occupied?(target)
|
if Utils.path_occupied?(target)
|
||||||
if adopt
|
if upgrade && target.directory? && target.children.empty?
|
||||||
ohai "Adopting existing #{self.class.english_name} at '#{target}'"
|
# An upgrade removed the directory contents but left the directory itself (see below).
|
||||||
same = command.run(
|
unless source.directory?
|
||||||
"/usr/bin/diff",
|
if target.parent.writable? && !force
|
||||||
args: ["--recursive", "--brief", source, target],
|
target.rmdir
|
||||||
verbose: verbose,
|
else
|
||||||
print_stdout: verbose,
|
Utils.gain_permissions_remove(target, command: command)
|
||||||
).success?
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if adopt
|
||||||
|
ohai "Adopting existing #{self.class.english_name} at '#{target}'"
|
||||||
|
same = command.run(
|
||||||
|
"/usr/bin/diff",
|
||||||
|
args: ["--recursive", "--brief", source, target],
|
||||||
|
verbose: verbose,
|
||||||
|
print_stdout: verbose,
|
||||||
|
).success?
|
||||||
|
|
||||||
unless same
|
unless same
|
||||||
raise CaskError,
|
raise CaskError,
|
||||||
"It seems the existing #{self.class.english_name} is different from " \
|
"It seems the existing #{self.class.english_name} is different from " \
|
||||||
"the one being installed."
|
"the one being installed."
|
||||||
|
end
|
||||||
|
|
||||||
|
# Remove the source as we don't need to move it to the target location
|
||||||
|
source.rmtree
|
||||||
|
|
||||||
|
return post_move(command)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove the source as we don't need to move it to the target location
|
message = "It seems there is already #{self.class.english_article} " \
|
||||||
source.rmtree
|
"#{self.class.english_name} at '#{target}'"
|
||||||
|
raise CaskError, "#{message}." unless force
|
||||||
|
|
||||||
return post_move(command)
|
opoo "#{message}; overwriting."
|
||||||
|
delete(target, force: force, command: command, **options)
|
||||||
end
|
end
|
||||||
|
|
||||||
message = "It seems there is already #{self.class.english_article} " \
|
|
||||||
"#{self.class.english_name} at '#{target}'"
|
|
||||||
raise CaskError, "#{message}." unless force
|
|
||||||
|
|
||||||
opoo "#{message}; overwriting."
|
|
||||||
delete(target, force: force, command: command, **options)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
ohai "Moving #{self.class.english_name} '#{source.basename}' to '#{target}'"
|
ohai "Moving #{self.class.english_name} '#{source.basename}' to '#{target}'"
|
||||||
@ -79,7 +90,16 @@ module Cask
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if target.dirname.writable?
|
if target.directory?
|
||||||
|
if target.writable?
|
||||||
|
source.children.each { |child| FileUtils.move(child, target + child.basename) }
|
||||||
|
else
|
||||||
|
command.run!("/bin/cp", args: ["-pR", "#{source}/*", "#{source}/.*", "#{target}/"],
|
||||||
|
sudo: true)
|
||||||
|
end
|
||||||
|
# TODO: copy extended attributes
|
||||||
|
source.rmtree
|
||||||
|
elsif target.dirname.writable?
|
||||||
FileUtils.move(source, target)
|
FileUtils.move(source, target)
|
||||||
else
|
else
|
||||||
# default sudo user isn't necessarily able to write to Homebrew's locations
|
# default sudo user isn't necessarily able to write to Homebrew's locations
|
||||||
@ -125,13 +145,23 @@ module Cask
|
|||||||
delete(target, force: force, command: command, **options)
|
delete(target, force: force, command: command, **options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(target, force: false, command: nil, **_)
|
def delete(target, force: false, upgrade: false, command: nil, **_)
|
||||||
ohai "Removing #{self.class.english_name} '#{target}'"
|
ohai "Removing #{self.class.english_name} '#{target}'"
|
||||||
raise CaskError, "Cannot remove undeletable #{self.class.english_name}." if MacOS.undeletable?(target)
|
raise CaskError, "Cannot remove undeletable #{self.class.english_name}." if MacOS.undeletable?(target)
|
||||||
|
|
||||||
return unless Utils.path_occupied?(target)
|
return unless Utils.path_occupied?(target)
|
||||||
|
|
||||||
if target.parent.writable? && !force
|
if upgrade && target.directory?
|
||||||
|
# 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|
|
||||||
|
if target.writable? && !force
|
||||||
|
child.rmtree
|
||||||
|
else
|
||||||
|
Utils.gain_permissions_remove(child, command: command)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elsif target.parent.writable? && !force
|
||||||
target.rmtree
|
target.rmtree
|
||||||
else
|
else
|
||||||
Utils.gain_permissions_remove(target, command: command)
|
Utils.gain_permissions_remove(target, command: command)
|
||||||
|
|||||||
@ -234,7 +234,7 @@ on_request: true)
|
|||||||
|
|
||||||
next if artifact.is_a?(Artifact::Binary) && !binaries?
|
next if artifact.is_a?(Artifact::Binary) && !binaries?
|
||||||
|
|
||||||
artifact.install_phase(command: @command, verbose: verbose?, adopt: adopt?, force: force?)
|
artifact.install_phase(command: @command, verbose: verbose?, adopt: adopt?, force: force?, upgrade: upgrade?)
|
||||||
already_installed_artifacts.unshift(artifact)
|
already_installed_artifacts.unshift(artifact)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user