Skip to content

Make mktmpdir cleanup tolerate missing paths#80

Merged
ioquatix merged 1 commit into
ruby:masterfrom
samuel-williams-shopify:mktmpdir-force-cleanup
Jun 21, 2026
Merged

Make mktmpdir cleanup tolerate missing paths#80
ioquatix merged 1 commit into
ruby:masterfrom
samuel-williams-shopify:mktmpdir-force-cleanup

Conversation

@samuel-williams-shopify

Copy link
Copy Markdown
Contributor

Summary

Dir.mktmpdir currently removes block-created temporary directories with FileUtils.remove_entry(path), which uses strict cleanup semantics. If the directory or one of its children has already been removed before teardown, cleanup can raise even though the requested final state has already been reached.

This changes block cleanup to use FileUtils.remove_entry(path, true), matching forceful recursive removal semantics used by FileUtils.rm_rf.

Testing

  • /Users/samuel/.local/state/tec/toolchain/base_profile/bin/bundle exec rake test
  • /Users/samuel/.local/state/tec/toolchain/base_profile/bin/ruby --disable-gems -Ilib -e 'require "tmpdir"; dir = nil; Dir.mktmpdir {|path| dir = path; FileUtils.remove_entry(path)}; abort "still exists" if File.exist?(dir); puts "ok"'

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Dir.mktmpdir’s block-cleanup behavior to tolerate already-removed temporary directories by switching teardown from strict FileUtils.remove_entry(path) to forceful removal (FileUtils.remove_entry(path, true)), and adds a regression test to ensure no exception is raised when the directory is removed within the block.

Changes:

  • Use FileUtils.remove_entry(path, true) during Dir.mktmpdir block cleanup to ignore missing paths during teardown.
  • Add a test asserting Dir.mktmpdir does not raise if the yielded directory is removed inside the block.
  • Update the inline documentation to reflect the new cleanup semantics.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/tmpdir.rb Switches block cleanup to forceful remove_entry to tolerate missing paths; updates docs.
test/test_tmpdir.rb Adds coverage for the “directory removed before teardown” scenario.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/tmpdir.rb
@ioquatix ioquatix merged commit 57c6cad into ruby:master Jun 21, 2026
26 checks passed
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 this pull request may close these issues.

3 participants