PHP 8.2.31
Preview: doctor.rb Size: 2.86 KB
//proc/thread-self/root/opt/alt/ruby20/lib64/ruby/2.0.0/rubygems/doctor.rb

require 'rubygems'
require 'rubygems/user_interaction'
require 'pathname'

##
# Cleans up after a partially-failed uninstall or for an invalid
# Gem::Specification.
#
# If a specification was removed by hand this will remove any remaining files.
#
# If a corrupt specification was installed this will clean up warnings by
# removing the bogus specification.

class Gem::Doctor

  include Gem::UserInteraction

  ##
  # Maps a gem subdirectory to the files that are expected to exist in the
  # subdirectory.

  REPOSITORY_EXTENSION_MAP = [ # :nodoc:
    ['specifications', '.gemspec'],
    ['build_info',     '.info'],
    ['cache',          '.gem'],
    ['doc',            ''],
    ['gems',           ''],
  ]

  raise 'Update REPOSITORY_EXTENSION_MAP' unless
    Gem::REPOSITORY_SUBDIRECTORIES.sort ==
      REPOSITORY_EXTENSION_MAP.map { |(k,_)| k }.sort

  ##
  # Creates a new Gem::Doctor that will clean up +gem_repository+.  Only one
  # gem repository may be cleaned at a time.
  #
  # If +dry_run+ is true no files or directories will be removed.

  def initialize gem_repository, dry_run = false
    @gem_repository = Pathname(gem_repository)
    @dry_run        = dry_run

    @installed_specs = nil
  end

  ##
  # Specs installed in this gem repository

  def installed_specs # :nodoc:
    @installed_specs ||= Gem::Specification.map { |s| s.full_name }
  end

  ##
  # Are we doctoring a gem repository?

  def gem_repository?
    not installed_specs.empty?
  end

  ##
  # Cleans up uninstalled files and invalid gem specifications

  def doctor
    @orig_home = Gem.dir
    @orig_path = Gem.path

    say "Checking #{@gem_repository}"

    Gem.use_paths @gem_repository.to_s

    unless gem_repository? then
      say 'This directory does not appear to be a RubyGems repository, ' +
          'skipping'
      say
      return
    end

    doctor_children

    say
  ensure
    Gem.use_paths @orig_home, *@orig_path
  end

  ##
  # Cleans up children of this gem repository

  def doctor_children # :nodoc:
    REPOSITORY_EXTENSION_MAP.each do |sub_directory, extension|
      doctor_child sub_directory, extension
    end
  end

  ##
  # Removes files in +sub_directory+ with +extension+

  def doctor_child sub_directory, extension # :nodoc:
    directory = @gem_repository + sub_directory

    directory.children.sort.each do |child|
      next unless child.exist?

      basename = child.basename(extension).to_s
      next if installed_specs.include? basename
      next if /^rubygems-\d/ =~ basename
      next if 'specifications' == sub_directory and 'default' == basename

      type = child.directory? ? 'directory' : 'file'

      action = if @dry_run then
                 'Extra'
               else
                 child.rmtree
                 'Removed'
               end

      say "#{action} #{type} #{sub_directory}/#{child.basename}"
    end
  rescue Errno::ENOENT
    # ignore
  end

end

Directory Contents

Dirs: 6 × Files: 53

Name Size Perms Modified Actions
commands DIR
- drwxr-xr-x 2024-03-03 22:43:42
Edit Download
core_ext DIR
- drwxr-xr-x 2024-03-03 22:43:42
Edit Download
ext DIR
- drwxr-xr-x 2024-03-03 22:43:42
Edit Download
package DIR
- drwxr-xr-x 2024-03-03 22:43:42
Edit Download
security DIR
- drwxr-xr-x 2024-03-03 22:43:42
Edit Download
ssl_certs DIR
- drwxr-xr-x 2024-03-03 22:43:42
Edit Download
1.56 KB lrw-r--r-- 2013-03-17 14:51:53
Edit Download
13.43 KB lrw-r--r-- 2012-11-30 16:27:52
Edit Download
5.27 KB lrw-r--r-- 2012-12-06 05:26:46
Edit Download
1.58 KB lrw-r--r-- 2013-02-05 21:06:14
Edit Download
11.82 KB lrw-r--r-- 2023-07-26 14:06:15
Edit Download
2.76 KB lrw-r--r-- 2013-07-22 16:33:18
Edit Download
7.74 KB lrw-r--r-- 2012-12-23 00:35:09
Edit Download
12.36 KB lrw-r--r-- 2013-11-13 02:59:08
Edit Download
5.53 KB lrw-r--r-- 2013-03-17 14:51:53
Edit Download
14.97 KB lrw-r--r-- 2013-07-22 16:33:18
Edit Download
1.73 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
2.86 KB lrw-r--r-- 2013-01-04 07:31:57
Edit Download
2.14 KB lrw-r--r-- 2013-07-22 16:33:18
Edit Download
2.70 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
416 B lrw-r--r-- 2012-12-10 00:40:39
Edit Download
2.84 KB lrw-r--r-- 2013-09-15 14:23:26
Edit Download
1.98 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
12.89 KB lrw-r--r-- 2012-12-06 05:26:46
Edit Download
22.19 KB lrw-r--r-- 2013-08-16 15:35:06
Edit Download
4.28 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
281 B lrw-r--r-- 2012-11-29 06:52:18
Edit Download
5.09 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
3.36 KB lrw-r--r-- 2011-07-27 01:40:07
Edit Download
1.35 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
1.96 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
13.22 KB lrw-r--r-- 2023-07-26 14:06:15
Edit Download
3.77 KB lrw-r--r-- 2013-08-16 15:35:06
Edit Download
1.58 KB lrw-r--r-- 2012-11-30 00:23:15
Edit Download
5.63 KB lrw-r--r-- 2013-07-22 16:33:18
Edit Download
249 B lrw-r--r-- 2013-07-25 15:42:22
Edit Download
763 B lrw-r--r-- 2013-07-22 16:33:18
Edit Download
7.75 KB lrw-r--r-- 2013-03-17 14:51:53
Edit Download
15.99 KB lrw-r--r-- 2015-08-18 13:01:02
Edit Download
3.67 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
6.02 KB lrw-r--r-- 2012-11-30 16:27:52
Edit Download
1.11 KB lrw-r--r-- 2023-07-26 14:06:15
Edit Download
20.56 KB lrw-r--r-- 2013-03-17 15:01:47
Edit Download
21.69 KB lrw-r--r-- 2013-10-26 17:44:33
Edit Download
3.12 KB lrw-r--r-- 2013-10-26 17:44:33
Edit Download
1.22 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
1.88 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
552 B lrw-r--r-- 2012-11-29 06:52:18
Edit Download
66.90 KB lrw-r--r-- 2023-07-26 14:06:15
Edit Download
5.17 KB lrw-r--r-- 2013-10-26 17:44:33
Edit Download
2.07 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
28.09 KB lrw-r--r-- 2013-07-25 15:42:22
Edit Download
4.03 KB lrw-r--r-- 2013-03-17 15:07:00
Edit Download
1.23 KB lrw-r--r-- 2011-07-27 01:40:07
Edit Download
8.29 KB lrw-r--r-- 2012-12-19 07:19:10
Edit Download
11.44 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
4.08 KB lrw-r--r-- 2012-12-23 00:35:09
Edit Download
10.50 KB lrw-r--r-- 2013-10-26 17:44:33
Edit Download
1.59 KB lrw-r--r-- 2011-07-27 01:40:07
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).