Prevent directory not empty error when running file_test on Windows
Fixed error: ZipFileTest#test_open_buffer_no_op_does_not_change_file: Errno::ENOTEMPTY: Directory not empty @ dir_s_rmdir - D:/a/_temp/d20210605-6612-1yi35sp C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:1335:in `rmdir' C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:1335:in `block in remove_dir1' C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:1349:in `platform_support' C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:1334:in `remove_dir1' C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:1327:in `remove' C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:689:in `block in remove_entry' C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:1384:in `ensure in postorder_traverse' C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:1384:in `postorder_traverse' C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:687:in `remove_entry' C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/tmpdir.rb:101:in `mktmpdir' D:/a/rubyzip/rubyzip/test/file_test.rb:136:in `test_open_buffer_no_op_does_not_change_file' Rationale: File#dup does not behave like what you would expect from #dup on Ruby. File#dup calls dup(2), which has OS dependant behavoir. On Windows, calling File#dup seems to cause an extra reference to an open file, which prevents deleting that file later. With this commit, we leave out the call to File#dup on Windows. It is not clear to me that removing this call has no undesired consequences, but all other existing tests still succeed.
This commit is contained in:
parent
8a5fef8074
commit
cdef4a5187
|
@ -30,7 +30,7 @@ module Zip
|
||||||
super()
|
super()
|
||||||
@file_name = file_name
|
@file_name = file_name
|
||||||
@output_stream = if stream
|
@output_stream = if stream
|
||||||
iostream = @file_name.dup
|
iostream = Zip::RUNNING_ON_WINDOWS ? @file_name : @file_name.dup
|
||||||
iostream.reopen(@file_name)
|
iostream.reopen(@file_name)
|
||||||
iostream.rewind
|
iostream.rewind
|
||||||
iostream
|
iostream
|
||||||
|
|
Loading…
Reference in New Issue