Class: Pod::Sandbox::PodDirCleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/sandbox/pod_dir_cleaner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, specs_by_platform) ⇒ PodDirCleaner

Returns a new instance of PodDirCleaner.



7
8
9
10
# 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

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



4
5
6
# File 'lib/cocoapods/sandbox/pod_dir_cleaner.rb', line 4

def root
  @root
end

#specs_by_platformObject (readonly)

Returns the value of attribute specs_by_platform.



5
6
7
# File 'lib/cocoapods/sandbox/pod_dir_cleaner.rb', line 5

def specs_by_platform
  @specs_by_platform
end

Instance Method Details

#clean!void

This method returns an undefined value.

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



17
18
19
# File 'lib/cocoapods/sandbox/pod_dir_cleaner.rb', line 17

def clean!
  clean_paths.each { |path| FileUtils.rm_rf(path) } if root.exist?
end

#clean_pathsArray<Strings> (private)

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.

Note:

Implementation detail: Don't use Dir#glob as there is an unexplained issue (#568, #572 and #602).

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

Returns:

  • (Array<Strings>)

    The paths that can be deleted.



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cocoapods/sandbox/pod_dir_cleaner.rb', line 50

def clean_paths
  cached_used = used_files.map(&:downcase)
  glob_options = File::FNM_DOTMATCH | File::FNM_CASEFOLD
  files = Pathname.glob(root + '**/*', glob_options).map(&:to_s)
  cached_used_set = cached_used.to_set
  files.reject do |candidate|
    candidate = candidate.downcase
    candidate.end_with?('.', '..') || cached_used_set.include?(candidate) || cached_used.any? do |path|
      path.include?(candidate) || candidate.include?(path)
    end
  end
end

#file_accessorsArray<Sandbox::FileAccessor> (private)

Returns the file accessors for all the specifications on their respective platform.

Returns:

  • (Array<Sandbox::FileAccessor>)

    the file accessors for all the specifications on their respective platform.



26
27
28
29
30
# 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_listSandbox::PathList (private)

Returns The path list for this Pod.

Returns:



34
35
36
# File 'lib/cocoapods/sandbox/pod_dir_cleaner.rb', line 34

def path_list
  @path_list ||= Sandbox::PathList.new(root)
end

#used_filesArray<String> (private)

Returns The absolute path of all the files used by the specifications (according to their platform) of this Pod.

Returns:

  • (Array<String>)

    The absolute path of all the files used by the specifications (according to their platform) of this Pod.



66
67
68
# File 'lib/cocoapods/sandbox/pod_dir_cleaner.rb', line 66

def used_files
  FileAccessor.all_files(file_accessors).map(&:to_s)
end