diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index f78fd72..6341177 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -73,7 +73,7 @@ def self.tmpdir # If a block is given, # it is yielded with the path of the directory. # The directory and its contents are removed - # using FileUtils.remove_entry before Dir.mktmpdir returns. + # using FileUtils.remove_entry with force before Dir.mktmpdir returns. # The value of the block is returned. # # Dir.mktmpdir {|dir| @@ -111,7 +111,7 @@ def self.mktmpdir(prefix_suffix=nil, *rest, **options, &block) raise ArgumentError, "parent directory is world writable but not sticky: #{base}" end end - FileUtils.remove_entry path + FileUtils.remove_entry path, true end else path diff --git a/test/test_tmpdir.rb b/test/test_tmpdir.rb index c91fc33..43617c6 100644 --- a/test/test_tmpdir.rb +++ b/test/test_tmpdir.rb @@ -77,6 +77,17 @@ def test_mktmpdir_nil } end + def test_mktmpdir_tolerates_removed_directory + dir = nil + assert_nothing_raised do + Dir.mktmpdir do |d| + dir = d + FileUtils.remove_entry(d) + end + end + assert_file.not_exist?(dir) + end + def test_mktmpdir_mutate bug16918 = '[ruby-core:98563]' assert_nothing_raised(bug16918) do