Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Library/Homebrew/cask/artifact/moved.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ def move(adopt: false, auto_updates: false, force: false, verbose: false, predec
end
end

ohai "Moving #{self.class.english_name} '#{source.basename}' to '#{target}'"

Utils.gain_permissions_mkpath(target.dirname, command:) unless target.dirname.exist?

if target.directory? && Quarantine.app_management_permissions_granted?(app: target, command:)
ohai "Moving #{self.class.english_name} contents of '#{source.basename}' into '#{target}'"
if target.writable?
source.children.each { |child| FileUtils.move(child, target/child.basename) }
else
Expand All @@ -116,8 +115,10 @@ def move(adopt: false, auto_updates: false, force: false, verbose: false, predec
Quarantine.copy_xattrs(source, target, command:)
FileUtils.rm_r(source)
elsif target.dirname.writable?
ohai "Moving #{self.class.english_name} '#{source.basename}' to '#{target}'"
FileUtils.move(source, target)
else
ohai "Moving #{self.class.english_name} '#{source.basename}' to '#{target}'"
# default sudo user isn't necessarily able to write to Homebrew's locations
# e.g. with runas_default set in the sudoers (5) file.
command.run!("/bin/cp", args: ["-pR", source, target], sudo: true)
Expand Down Expand Up @@ -179,20 +180,21 @@ def move_back(skip: false, force: false, adopt: false, command: nil, **options)
end

def delete(target, force: false, successor: nil, command: nil, **_)
ohai "Removing #{self.class.english_name} '#{target}'"
raise CaskError, "Cannot remove undeletable #{self.class.english_name}." if undeletable?(target)

return unless Utils.path_occupied?(target)

if target.directory? && matching_artifact?(successor) && Quarantine.app_management_permissions_granted?(
app: target, command:,
)
ohai "Upgrading #{self.class.english_name} '#{target}' in-place"
# 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|
Utils.gain_permissions_remove(child, command:)
end
else
ohai "Removing #{self.class.english_name} '#{target}'"
Utils.gain_permissions_remove(target, command:)
end
end
Expand Down
Loading