[rubygems/rubygems] Clean up temporary directory after generate_index --update

While generate_index did clean up temporary directory, when running with
--update flag, that did not happen and the temporary directory was left
behind.

This commit fixes that and modifies tests in order to make sure this is
not reintroduced later on.

Fixes #5635.

https://github.com/rubygems/rubygems/commit/9fa34dc329
This commit is contained in:
Tomas Volf 2022-06-24 09:21:47 +02:00 committed by git
parent f159bbd17d
commit 56809537a4
3 changed files with 12 additions and 0 deletions

View File

@ -401,6 +401,8 @@ class Gem::Indexer
File.utime newest_mtime, newest_mtime, dst_name File.utime newest_mtime, newest_mtime, dst_name
end end
ensure
FileUtils.rm_rf @directory
end end
## ##

View File

@ -119,6 +119,12 @@ class Gem::TestCase < Test::Unit::TestCase
assert File.directory?(path), msg assert File.directory?(path), msg
end end
def refute_directory_exists(path, msg = nil)
msg = build_message(msg, "Expected path '#{path}' not to be a directory")
assert_path_not_exist path
refute File.directory?(path), msg
end
# https://github.com/seattlerb/minitest/blob/21d9e804b63c619f602f3f4ece6c71b48974707a/lib/minitest/assertions.rb#L188 # https://github.com/seattlerb/minitest/blob/21d9e804b63c619f602f3f4ece6c71b48974707a/lib/minitest/assertions.rb#L188
def _synchronize def _synchronize
yield yield

View File

@ -103,6 +103,8 @@ class TestGemIndexer < Gem::TestCase
assert_indexed @indexerdir, "latest_specs.#{@marshal_version}" assert_indexed @indexerdir, "latest_specs.#{@marshal_version}"
assert_indexed @indexerdir, "latest_specs.#{@marshal_version}.gz" assert_indexed @indexerdir, "latest_specs.#{@marshal_version}.gz"
refute_directory_exists @indexer.directory
end end
def test_generate_index_modern def test_generate_index_modern
@ -342,6 +344,8 @@ class TestGemIndexer < Gem::TestCase
assert_includes pre_specs_index, @d2_1_a_tuple assert_includes pre_specs_index, @d2_1_a_tuple
refute_includes pre_specs_index, @d2_1_tuple refute_includes pre_specs_index, @d2_1_tuple
refute_directory_exists @indexer.directory
end end
end end