Make mktmpdir cleanup tolerate missing paths#80
Merged
ioquatix merged 1 commit intoJun 21, 2026
Conversation
There was a problem hiding this comment.
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)duringDir.mktmpdirblock cleanup to ignore missing paths during teardown. - Add a test asserting
Dir.mktmpdirdoes 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Dir.mktmpdircurrently removes block-created temporary directories withFileUtils.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 byFileUtils.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"'