[rubygems/rubygems] Fix gem pristine etc resetting gem twice sometimes

If a default version and a regular version of etc are present at the
same time, RubyGems will end up duplicating work and running pristine
twice.

The `etc` gem is special because it's loaded by RubyGems by default.
When doing this, RubyGems will activate the regularly installed version.
The when `gem pristine` runs, it will find to installed specifications
but materialize both to the already activated specification.

Before:

```
$ gem pristine etc --version 1.4.3
Restoring gems to pristine condition...
Building native extensions. This could take a while...
Restored etc-1.4.3
Building native extensions. This could take a while...
Restored etc-1.4.3
```

After:

```
$ gem pristine etc --version 1.4.3
Restoring gems to pristine condition...
Skipped etc-1.4.3, it is a default gem
Building native extensions. This could take a while...
Restored etc-1.4.3
```

5c279ac56b
This commit is contained in:
David Rodríguez 2024-10-08 20:01:25 +02:00 committed by git
parent 36e9a6bb41
commit d12c8cbf14
3 changed files with 41 additions and 11 deletions

View file

@ -100,7 +100,7 @@ class Gem::BasicSpecification
end
def default_gem?
loaded_from &&
!loaded_from.nil? &&
File.dirname(loaded_from) == Gem.default_specifications_dir
end