Class: Pod::Sandbox::PodDirCleaner
- Inherits:
-
Object
- Object
- Pod::Sandbox::PodDirCleaner
- Defined in:
- lib/cocoapods/sandbox/pod_dir_cleaner.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#specs_by_platform ⇒ Object
readonly
Returns the value of attribute specs_by_platform.
Instance Method Summary collapse
-
#clean! ⇒ void
Removes all the files not needed for the installation according to the specs by platform.
-
#clean_paths ⇒ Array<Strings>
private
Finds the absolute paths, including hidden ones, of the files that are not used by the pod and thus can be safely deleted.
-
#file_accessors ⇒ Array<Sandbox::FileAccessor>
private
The file accessors for all the specifications on their respective platform.
-
#initialize(root, specs_by_platform) ⇒ PodDirCleaner
constructor
A new instance of PodDirCleaner.
-
#path_list ⇒ Sandbox::PathList
private
The path list for this Pod.
-
#used_files ⇒ Array<String>
private
The absolute path of all the files used by the specifications (according to their platform) of this Pod.
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
#root ⇒ Object (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_platform ⇒ Object (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_paths ⇒ Array<Strings> (private)
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.
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.
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) = File::FNM_DOTMATCH | File::FNM_CASEFOLD files = Pathname.glob(root + '**/*', ).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_accessors ⇒ Array<Sandbox::FileAccessor> (private)
Returns 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_list ⇒ Sandbox::PathList (private)
Returns The path list for this Pod.
34 35 36 |
# File 'lib/cocoapods/sandbox/pod_dir_cleaner.rb', line 34 def path_list @path_list ||= Sandbox::PathList.new(root) end |
#used_files ⇒ Array<String> (private)
Returns 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 |