Commit 7a5a7e7 1 parent 3fecab5 commit 7a5a7e7 Copy full SHA for 7a5a7e7
File tree 3 files changed +26
-1
lines changed
3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 1
1
## Unreleased
2
2
3
3
### Changed/Added
4
+ - Prevent warnings on Ruby 3.1 if finalizer is called twice [ TODO] ( https://github.com/roo-rb/roo/pull/TODO )
4
5
5
6
## [ 2.10.0] 2023-02-07
6
7
Original file line number Diff line number Diff line change @@ -4,7 +4,10 @@ def finalize_tempdirs(object_id)
4
4
if @tempdirs && ( dirs_to_remove = @tempdirs [ object_id ] )
5
5
@tempdirs . delete ( object_id )
6
6
dirs_to_remove . each do |dir |
7
- ::FileUtils . remove_entry ( dir )
7
+ # Pass force=true to avoid an exception (and thus warnings in Ruby 3.1) if dir has
8
+ # already been removed. This can occur when the finalizer is called both in a forked
9
+ # child process and in the parent.
10
+ ::FileUtils . remove_entry ( dir , true )
8
11
end
9
12
end
10
13
end
Original file line number Diff line number Diff line change @@ -36,6 +36,27 @@ def test_finalize
36
36
end
37
37
end
38
38
39
+ def test_finalize_twice
40
+ skip if defined? JRUBY_VERSION
41
+
42
+ instance = Class . new { include Roo ::Tempdir } . new
43
+
44
+ tempdir = instance . make_tempdir ( instance , "my_temp_prefix" , nil )
45
+ assert File . exist? ( tempdir ) , "Expected #{ tempdir } to initially exist"
46
+
47
+ pid = Process . fork do
48
+ # Inside the forked process finalize does not affect the parent process, but does delete the
49
+ # tempfile on disk
50
+ instance . finalize_tempdirs ( instance . object_id )
51
+ end
52
+
53
+ Process . wait ( pid )
54
+ refute File . exist? ( tempdir ) , "Expected #{ tempdir } to have been cleaned up by child process"
55
+
56
+ instance . finalize_tempdirs ( instance . object_id )
57
+ refute File . exist? ( tempdir ) , "Expected #{ tempdir } to still have been cleaned up"
58
+ end
59
+
39
60
def test_cleanup_on_error
40
61
# NOTE: This test was occasionally failing because when it started running
41
62
# other tests would have already added folders to the temp directory,
You can’t perform that action at this time.
0 commit comments