class Pod::Sandbox::PodDirCleaner

Attributes

root[R]
specs_by_platform[R]

Public Class Methods

new(root, specs_by_platform) click to toggle source
# File lib/cocoapods/sandbox/pod_dir_cleaner.rb, line 7
def initialize(root, specs_by_platform)
  @root = root
  @specs_by_platform = specs_by_platform
end

Public Instance Methods

clean!() click to toggle source

Removes all the files not needed for the installation according to the specs by platform.

@return [void]

# File lib/cocoapods/sandbox/pod_dir_cleaner.rb, line 17
def clean!
  clean_paths.each { |path| FileUtils.rm_rf(path) } if root.exist?
end

Private Instance Methods

clean_paths() click to toggle source

Finds the absolute paths, including hidden ones, of the files that are not used by the pod and thus can be safely deleted.

@note Implementation detail: Don't use `Dir#glob` as there is an

unexplained issue (#568, #572 and #602).

@todo The paths are down-cased for the comparison as issues similar

to #602 lead the files not being matched and so cleaning all
the files. This solution might create side effects.

@return [Array<Strings>] The paths that can be deleted.

# File lib/cocoapods/sandbox/pod_dir_cleaner.rb, line 50
def clean_paths
  cached_used = used_files
  glob_options = File::FNM_DOTMATCH | File::FNM_CASEFOLD
  files = Pathname.glob(root + '**/*', glob_options).map(&:to_s)

  files.reject do |candidate|
    candidate = candidate.downcase
    candidate.end_with?('.', '..') || cached_used.any? do |path|
      path = path.downcase
      path.include?(candidate) || candidate.include?(path)
    end
  end
end
file_accessors() click to toggle source

@return [Array<Sandbox::FileAccessor>] the file accessors for all the

specifications on their respective platform.
# File lib/cocoapods/sandbox/pod_dir_cleaner.rb, line 26
def file_accessors
  @file_accessors ||= specs_by_platform.flat_map do |platform, specs|
    specs.flat_map { |spec| Sandbox::FileAccessor.new(path_list, spec.consumer(platform)) }
  end
end
path_list() click to toggle source

@return [Sandbox::PathList] The path list for this Pod.

# File lib/cocoapods/sandbox/pod_dir_cleaner.rb, line 34
def path_list
  @path_list ||= Sandbox::PathList.new(root)
end
used_files() click to toggle source

@return [Array<String>] The absolute path of all the files used by the

specifications (according to their platform) of this Pod.
# File lib/cocoapods/sandbox/pod_dir_cleaner.rb, line 67
def used_files
  files = [
    file_accessors.map(&:vendored_frameworks),
    file_accessors.map(&:vendored_libraries),
    file_accessors.map(&:resource_bundle_files),
    file_accessors.map(&:license),
    file_accessors.map(&:prefix_header),
    file_accessors.map(&:preserve_paths),
    file_accessors.map(&:readme),
    file_accessors.map(&:resources),
    file_accessors.map(&:source_files),
    file_accessors.map(&:module_map),
  ]

  files.flatten.compact.map(&:to_s).uniq
end