From e8667f825d1d80d98365236a899a143bb7d6e7dd Mon Sep 17 00:00:00 2001 From: Florian Meyer Date: Sun, 9 Aug 2026 06:32:13 +0200 Subject: [PATCH] Report permission errors from bundle clean --- lib/bundler/runtime.rb | 4 +++- spec/commands/clean_spec.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index d821dc022b6e..bbd4a9f987cd 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -304,7 +304,9 @@ def remove_dir(dir, dry_run) Bundler.ui.info "Would have removed #{output}" else Bundler.ui.info "Removing #{output}" - FileUtils.rm_rf(dir) + SharedHelpers.filesystem_access(dir) do |path| + FileUtils.rm_r(path) + end end output diff --git a/spec/commands/clean_spec.rb b/spec/commands/clean_spec.rb index 9d8bfa3b59af..d4f4acc77a08 100644 --- a/spec/commands/clean_spec.rb +++ b/spec/commands/clean_spec.rb @@ -46,6 +46,38 @@ def should_not_have_gems(*gems) expect(vendored_gems("bin/myrackup")).to exist end + it "reports an error when an unused gem directory cannot be removed", :permissions do + gemfile <<-G + source "https://gem.repo1" + + gem "foo" + gem "myrack" + G + + bundle_config "path vendor/bundle" + bundle_config "clean false" + bundle "install" + + gemfile <<-G + source "https://gem.repo1" + + gem "myrack" + G + bundle "install" + + stale_gem_path = vendored_gems("gems/foo-1.0") + FileUtils.chmod(0o500, stale_gem_path) + + bundle :clean, raise_on_error: false + + expect(exitstatus).to eq(23) + expect(err).to include(stale_gem_path.to_s) + expect(err).to include("grant write permissions") + expect(stale_gem_path).to exist + ensure + FileUtils.chmod(0o755, stale_gem_path) if stale_gem_path&.exist? + end + it "removes unused gems when the bundle path contains glob metacharacters" do gemfile <<-G source "https://gem.repo1"