Skip to content
Closed
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
6 changes: 2 additions & 4 deletions Library/Homebrew/cask/artifact/moved.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,13 @@ def move_back(skip: false, force: false, adopt: false, command: nil, **options)
# This may fail and need sudo if the source has files with restricted permissions.
[!source.parent.writable?, true].uniq.each do |sudo|
result = command.run(
"/bin/cp",
args: ["-pR", target, source],
"/bin/mv",
args: [target, source.dirname],
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from cp to mv with source.dirname as destination will not correctly restore the artifact if the target basename differs from the source basename.

For example, if a cask specifies a custom target name:

  • source in staging: OriginalName.app
  • target installed: /Applications/CustomName.app

The original code would copy to the exact source path: cp -pR /Applications/CustomName.app /path/to/staging/OriginalName.app

The new code moves to the parent directory: mv /Applications/CustomName.app /path/to/staging/ which results in /path/to/staging/CustomName.app (wrong basename).

Consider using mv target source instead of mv target source.dirname to preserve the exact source path.

Suggested change
args: [target, source.dirname],
args: [target, source],

Copilot uses AI. Check for mistakes.
must_succeed: sudo,
sudo:,
)
break if result.success?
end

delete(target, force:, command:, **options)
end

def delete(target, force: false, successor: nil, command: nil, **_)
Expand Down
Loading