Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion lib/bundler/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions spec/commands/clean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down