Skip to content

brew uninstall --zap : Using sudo to gain ownership of path #19903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
loganoxo opened this issue May 6, 2025 · 7 comments · Fixed by #19941
Closed
3 tasks done

brew uninstall --zap : Using sudo to gain ownership of path #19903

loganoxo opened this issue May 6, 2025 · 7 comments · Fixed by #19941

Comments

@loganoxo
Copy link

loganoxo commented May 6, 2025

brew doctor output

Your system is ready to brew.

Verification

  • My "brew doctor output" above says Your system is ready to brew. and am still able to reproduce my issue.
  • I ran brew update twice and am still able to reproduce my issue.
  • This issue's title and/or description do not reference a single formula e.g. brew install wget. If they do, open an issue at https://github.com/Homebrew/homebrew-core/issues/new/choose instead.

brew config output

HOMEBREW_VERSION: 4.5.0
ORIGIN: https://github.com/Homebrew/brew
HEAD: 3332d3331b56e0aff675d3816d8ebfe564075299
Last commit: 7 days ago
Branch: stable
Core tap JSON: 06 May 00:53 UTC
Core cask tap JSON: 06 May 00:53 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_BAT_THEME: Catppuccin Mocha
HOMEBREW_CASK_OPTS: []
HOMEBREW_EDITOR: vim
HOMEBREW_MAKE_JOBS: 12
Homebrew Ruby: 3.4.3 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.4.3/bin/ruby
CPU: dodeca-core 64-bit arm_blizzard_avalanche
Clang: 16.0.0 build 1600
Git: 2.49.0 => /opt/homebrew/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 14.7.5-arm64
CLT: 16.2.0.0.1.1733547573
Xcode: 16.1
Rosetta 2: false

What were you trying to do (and why)?

uninstall a cask

What happened (include all command output)?

brew uninstall --zap --debug motrix

/opt/homebrew/Library/Homebrew/brew.rb (Formulary::NullLoader): loading motrix
/opt/homebrew/Library/Homebrew/brew.rb (Cask::CaskLoader::FromAPILoader): loading motrix
/opt/homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading homebrew/core/rubberband
/opt/homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading homebrew/core/cjson
/opt/homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading homebrew/core/lame

......

/opt/homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading libnghttp2
/opt/homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading unbound
==> Zapping Cask motrix
/opt/homebrew/Library/Homebrew/brew.rb (Cask::CaskLoader::FromPathLoader): loading /opt/homebrew/Caskroom/motrix/.metadata/1.8.19/20250506010643.212/Casks/motrix.json
==> Implied `brew uninstall --cask motrix`
==> Uninstalling artifacts
==> 2 artifacts defined
#<Cask::ArtifactSet: {#<Cask::Artifact::App:0x000000014131fdc0 @cask=#<Cask motrix /opt/homebrew/Caskroom/motrix/.metadata/1.8.19/20250506010643.212/Casks/motrix.json>, @dsl_args=["Motrix.app"], @source_string="Motrix.app", @target_string="">, #<Cask::Artifact::Zap:0x00000001412fec60 @cask=#<Cask motrix /opt/homebrew/Caskroom/motrix/.metadata/1.8.19/20250506010643.212/Casks/motrix.json>, @dsl_args=[{trash: ["~/Library/Application Support/Motrix", "~/Library/Caches/app.motrix.native", "~/Library/Logs/Motrix", "~/Library/Preferences/app.motrix.native.plist", "~/Library/Saved Application State/app.motrix.native.savedState"]}], @directives={trash: ["~/Library/Application Support/Motrix", "~/Library/Caches/app.motrix.native", "~/Library/Logs/Motrix", "~/Library/Preferences/app.motrix.native.plist", "~/Library/Saved Application State/app.motrix.native.savedState"], signal: []}>}>
==> Uninstalling artifact of class Cask::Artifact::App
==> Backing App 'Motrix.app' up to '/opt/homebrew/Caskroom/motrix/1.8.19/Motrix.app'
/usr/bin/env /bin/cp -pR /Applications/Motrix.app /opt/homebrew/Caskroom/motrix/1.8.19/Motrix.app
==> Removing App '/Applications/Motrix.app'
==> Dispatching zap stanza
==> Trashing files:
~/Library/Application Support/Motrix
~/Library/Caches/app.motrix.native
~/Library/Logs/Motrix
~/Library/Preferences/app.motrix.native.plist
~/Library/Saved Application State/app.motrix.native.savedState
/usr/bin/env /opt/homebrew/Library/Homebrew/cask/utils/trash.swift /Users/logan/Library/Application\ Support/Motrix /Users/logan/Library/Logs/Motrix /Users/logan/Library/Preferences/app.motrix.native.plist
/usr/bin/env /opt/homebrew/Library/Homebrew/cask/utils/trash.swift /Users/logan/Library/Application\ Support/Motrix
/usr/bin/env /usr/bin/chflags -R -- 000 /Users/logan/Library/Application\ Support/Motrix
chflags: /Users/logan/Library/Application Support/Motrix: No such file or directory
/usr/bin/env /bin/chmod -R -- u+rwx /Users/logan/Library/Application\ Support/Motrix
chmod: /Users/logan/Library/Application Support/Motrix: No such file or directory
/usr/bin/env /bin/chmod -R -N /Users/logan/Library/Application\ Support/Motrix
chmod: Failed to clear ACL on file /Users/logan/Library/Application Support/Motrix: No such file or directory
/usr/bin/env /opt/homebrew/Library/Homebrew/cask/utils/trash.swift /Users/logan/Library/Application\ Support/Motrix
==> Using sudo to gain ownership of path '/Users/logan/Library/Application Support/Motrix'
/usr/bin/sudo -E -- /usr/sbin/chown -R -- logan /Users/logan/Library/Application\ Support/Motrix
Password:
chown: /Users/logan/Library/Application Support/Motrix: No such file or directory
/usr/bin/env /opt/homebrew/Library/Homebrew/cask/utils/trash.swift /Users/logan/Library/Application\ Support/Motrix
/usr/bin/env /usr/bin/chflags -R -- 000 /Users/logan/Library/Application\ Support/Motrix
chflags: /Users/logan/Library/Application Support/Motrix: No such file or directory
/usr/bin/env /bin/chmod -R -- u+rwx /Users/logan/Library/Application\ Support/Motrix
chmod: /Users/logan/Library/Application Support/Motrix: No such file or directory
/usr/bin/env /bin/chmod -R -N /Users/logan/Library/Application\ Support/Motrix
chmod: Failed to clear ACL on file /Users/logan/Library/Application Support/Motrix: No such file or directory
/usr/bin/env /opt/homebrew/Library/Homebrew/cask/utils/trash.swift /Users/logan/Library/Application\ Support/Motrix
/usr/bin/env /opt/homebrew/Library/Homebrew/cask/utils/trash.swift /Users/logan/Library/Logs/Motrix
/usr/bin/env /usr/bin/chflags -R -- 000 /Users/logan/Library/Logs/Motrix
chflags: /Users/logan/Library/Logs/Motrix: No such file or directory
/usr/bin/env /bin/chmod -R -- u+rwx /Users/logan/Library/Logs/Motrix
chmod: /Users/logan/Library/Logs/Motrix: No such file or directory
/usr/bin/env /bin/chmod -R -N /Users/logan/Library/Logs/Motrix
chmod: Failed to clear ACL on file /Users/logan/Library/Logs/Motrix: No such file or directory
/usr/bin/env /opt/homebrew/Library/Homebrew/cask/utils/trash.swift /Users/logan/Library/Logs/Motrix
==> Using sudo to gain ownership of path '/Users/logan/Library/Logs/Motrix'
/usr/bin/sudo -E -- /usr/sbin/chown -R -- logan /Users/logan/Library/Logs/Motrix
chown: /Users/logan/Library/Logs/Motrix: No such file or directory
/usr/bin/env /opt/homebrew/Library/Homebrew/cask/utils/trash.swift /Users/logan/Library/Logs/Motrix
/usr/bin/env /usr/bin/chflags -R -- 000 /Users/logan/Library/Logs/Motrix
chflags: /Users/logan/Library/Logs/Motrix: No such file or directory
/usr/bin/env /bin/chmod -R -- u+rwx /Users/logan/Library/Logs/Motrix
chmod: /Users/logan/Library/Logs/Motrix: No such file or directory
/usr/bin/env /bin/chmod -R -N /Users/logan/Library/Logs/Motrix
chmod: Failed to clear ACL on file /Users/logan/Library/Logs/Motrix: No such file or directory
/usr/bin/env /opt/homebrew/Library/Homebrew/cask/utils/trash.swift /Users/logan/Library/Logs/Motrix
/usr/bin/env /opt/homebrew/Library/Homebrew/cask/utils/trash.swift /Users/logan/Library/Preferences/app.motrix.native.plist
/usr/bin/env /usr/bin/chflags -R -- 000 /Users/logan/Library/Preferences/app.motrix.native.plist
chflags: /Users/logan/Library/Preferences/app.motrix.native.plist: No such file or directory
/usr/bin/env /bin/chmod -R -- u+rwx /Users/logan/Library/Preferences/app.motrix.native.plist
chmod: /Users/logan/Library/Preferences/app.motrix.native.plist: No such file or directory
/usr/bin/env /bin/chmod -R -N /Users/logan/Library/Preferences/app.motrix.native.plist
chmod: Failed to clear ACL on file /Users/logan/Library/Preferences/app.motrix.native.plist: No such file or directory
/usr/bin/env /opt/homebrew/Library/Homebrew/cask/utils/trash.swift /Users/logan/Library/Preferences/app.motrix.native.plist
==> Using sudo to gain ownership of path '/Users/logan/Library/Preferences/app.motrix.native.plist'
/usr/bin/sudo -E -- /usr/sbin/chown -R -- logan /Users/logan/Library/Preferences/app.motrix.native.plist
chown: /Users/logan/Library/Preferences/app.motrix.native.plist: No such file or directory
/usr/bin/env /opt/homebrew/Library/Homebrew/cask/utils/trash.swift /Users/logan/Library/Preferences/app.motrix.native.plist
/usr/bin/env /usr/bin/chflags -R -- 000 /Users/logan/Library/Preferences/app.motrix.native.plist
chflags: /Users/logan/Library/Preferences/app.motrix.native.plist: No such file or directory
/usr/bin/env /bin/chmod -R -- u+rwx /Users/logan/Library/Preferences/app.motrix.native.plist
chmod: /Users/logan/Library/Preferences/app.motrix.native.plist: No such file or directory
/usr/bin/env /bin/chmod -R -N /Users/logan/Library/Preferences/app.motrix.native.plist
chmod: Failed to clear ACL on file /Users/logan/Library/Preferences/app.motrix.native.plist: No such file or directory
/usr/bin/env /opt/homebrew/Library/Homebrew/cask/utils/trash.swift /Users/logan/Library/Preferences/app.motrix.native.plist
Warning: The following files could not be trashed, please do so manually:
/Users/logan/Library/Application Support/Motrix
/Users/logan/Library/Logs/Motrix
/Users/logan/Library/Preferences/app.motrix.native.plist
==> Removing all staged versions of Cask 'motrix'
==> Purging all staged versions of Cask motrix
/opt/homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading homebrew/core/rubberband
/opt/homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading homebrew/core/cjson
/opt/homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading homebrew/core/lame
/opt/homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading homebrew/core/vim

......

What did you expect to happen?

Before I was prompted to enter my password, Homebrew had already deleted the app’s related files and moved them to the Trash. Subsequently, it attempted to perform operations on those files, but they no longer existed. This seems like a potential issue—could you confirm if this behavior is expected?

Step-by-step reproduction instructions (by running brew commands)

# 1、install a cask


brew install motrix
==> Downloading https://github.com/agalwood/Motrix/releases/download/v1.8.19/Motrix-1.8.19-arm64.dmg
Already downloaded: /Users/logan/Library/Caches/Homebrew/downloads/d1ee2fdb2bf9526a7ca9b4e7af1e32a438ec0d3fda037504377b3bfaf755d166--Motrix-1.8.19-arm64.dmg
==> Installing Cask motrix
==> Moving App 'Motrix.app' to '/Applications/Motrix.app'
🍺  motrix was successfully installed!


# 2、open the app, and quit

# 3、uninstall with --zap

brew uninstall --zap motrix
==> Implied `brew uninstall --cask motrix`
==> Backing App 'Motrix.app' up to '/opt/homebrew/Caskroom/motrix/1.8.19/Motrix.app'
==> Removing App '/Applications/Motrix.app'
==> Dispatching zap stanza
==> Trashing files:
~/Library/Application Support/Motrix
~/Library/Caches/app.motrix.native
~/Library/Logs/Motrix
~/Library/Preferences/app.motrix.native.plist
~/Library/Saved Application State/app.motrix.native.savedState
==> Using sudo to gain ownership of path '/Users/logan/Library/Application Support/Motrix'
Password:
chown: /Users/logan/Library/Application Support/Motrix: No such file or directory
==> Using sudo to gain ownership of path '/Users/logan/Library/Logs/Motrix'
chown: /Users/logan/Library/Logs/Motrix: No such file or directory
==> Using sudo to gain ownership of path '/Users/logan/Library/Preferences/app.motrix.native.plist'
chown: /Users/logan/Library/Preferences/app.motrix.native.plist: No such file or directory
Warning: The following files could not be trashed, please do so manually:
/Users/logan/Library/Application Support/Motrix
/Users/logan/Library/Logs/Motrix
/Users/logan/Library/Preferences/app.motrix.native.plist
==> Removing all staged versions of Cask 'motrix'
@loganoxo
Copy link
Author

loganoxo commented May 6, 2025

here is motrix.rb

cask "motrix" do
  arch arm: "-arm64"

  version "1.8.19"
  sha256 arm:   "d73f4d69f3597ad8f98b821aa0fb58ba964bf85061b4a13f00edcb3618001c0e",
         intel: "b644cc83aa98224147ef2942fd49ecfc8cdcebfce9616550fa35caa6850c4178"

  url "https://github.com/agalwood/Motrix/releases/download/v#{version}/Motrix-#{version}#{arch}.dmg",
      verified: "github.com/agalwood/Motrix/"
  name "Motrix"
  desc "Open-source download manager"
  homepage "https://motrix.app/"

  livecheck do
    url :url
    strategy :github_latest
  end

  depends_on macos: ">= :high_sierra"

  app "Motrix.app"

  zap trash: [
    "~/Library/Application Support/Motrix",
    "~/Library/Caches/app.motrix.native",
    "~/Library/Logs/Motrix",
    "~/Library/Preferences/app.motrix.native.plist",
    "~/Library/Saved Application State/app.motrix.native.savedState",
  ]
end

@loganoxo
Copy link
Author

loganoxo commented May 6, 2025

SCR-20250506-irzh

@loganoxo
Copy link
Author

loganoxo commented May 8, 2025

Hi @carlocab, any updates on this?
Happy to assist with debugging or testing if needed. Thanks!

@monlite
Copy link

monlite commented May 9, 2025

It seems like this commit f816a39 caused the issue. After rolling back this commit, the issue was resolved, but I'm not sure about the mechanism. Still need @carlocab's help.

@carlocab
Copy link
Member

carlocab commented May 13, 2025

I don't think f816a39 broke things here. There is a pre-existing bug with --zap that prevents it from trashing paths properly; all that f816a39 did is make that bug more visible.

Does rolling back f816a39 actually allow the paths to be trashed correctly, or does it just stop brew from complaining about not being able to trash them?

@monlite
Copy link

monlite commented May 13, 2025

Does rolling back f816a39 actually allow the paths to be trashed correctly, or does it just stop brew from complaining about not being able to trash them?

@carlocab Yes, after rolling back f816a39, there was no prompt to obtain root permissions, and all files were successfully trashed. In this scenario(uninstall motrix via brew rm --zap), I think it's no necessary to obtain root permissions, because the ownership of all files in the zap list belongs to the current user. After this commit, untrashable appears to incorrectly include files that have already been trashed.

# Before rolling back f816a39d1fbe1af4e5306ab9b8c940625d450f88
~ ❯ brew rm --zap motrix
==> Implied `brew uninstall --cask motrix`
==> Backing App 'Motrix.app' up to '/opt/homebrew/Caskroom/motrix/1.8.19/Motrix.app'
==> Removing App '/Applications/Motrix.app'
==> Dispatching zap stanza
==> Trashing files:
~/Library/Application Support/Motrix
~/Library/Caches/app.motrix.native
~/Library/Logs/Motrix
~/Library/Preferences/app.motrix.native.plist
~/Library/Saved Application State/app.motrix.native.savedState
==> Using sudo to gain ownership of path '/Users/howe/Library/Application Support/Motrix'
Password:
chown: /Users/howe/Library/Application Support/Motrix: No such file or directory
==> Using sudo to gain ownership of path '/Users/howe/Library/Logs/Motrix'
chown: /Users/howe/Library/Logs/Motrix: No such file or directory
==> Using sudo to gain ownership of path '/Users/howe/Library/Saved Application State/app.motrix.native.savedState'
chown: /Users/howe/Library/Saved Application State/app.motrix.native.savedState: No such file or directory
Warning: The following files could not be trashed, please do so manually:
/Users/howe/Library/Application Support/Motrix
/Users/howe/Library/Logs/Motrix
/Users/howe/Library/Saved Application State/app.motrix.native.savedState
==> Removing all staged versions of Cask 'motrix'

# After rolling back f816a39d1fbe1af4e5306ab9b8c940625d450f88
~ ❯ brew rm --zap motrix
==> Implied `brew uninstall --cask motrix`
==> Backing App 'Motrix.app' up to '/opt/homebrew/Caskroom/motrix/1.8.19/Motrix.app'
==> Removing App '/Applications/Motrix.app'
==> Dispatching zap stanza
==> Trashing files:
~/Library/Application Support/Motrix
~/Library/Caches/app.motrix.native
~/Library/Logs/Motrix
~/Library/Preferences/app.motrix.native.plist
~/Library/Saved Application State/app.motrix.native.savedState
==> Removing all staged versions of Cask 'motrix'

@carlocab
Copy link
Member

Weird, ok. Thanks for checking! I've opened #19941 to revert this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants