Commit d1a9af21 authored by Fabio Pelosin's avatar Fabio Pelosin

[LocalPod] Fix for over aggressive #clean.

Paths that contain or are contained by an used path are now preserved.
The new logic works well with used path that are directories.

Closes #300
parent ff2a73ab
...@@ -64,21 +64,36 @@ module Pod ...@@ -64,21 +64,36 @@ module Pod
root.rmtree if exists? root.rmtree if exists?
end end
# It deletes all the files identified by clean_files, then it removes ### Cleaning
# all the empty folders or symlinks.
# Public: Deletes any path that is not used by the pod.
def clean def clean
clean_files.each { |path| FileUtils.rm_rf(path) } clean_paths.each { |path| FileUtils.rm_rf(path) }
end
# Get all the directories. Then sort them from the longest # Public: Finds the absolute paths, including hidden ones, of the files
# to the shortest, so a directory will be empty if its # that are not used by the pod and can be safely deleted.
# subdirs where empty. We need to delete the symlinks because #
# it might prevent a bundle from being deleted # Returns an Array of Strings containing the absolute paths.
dirs = Dir.glob(root + "**/*", File::FNM_DOTMATCH) def clean_paths
dirs = dirs.reject { |d| d.end_with?('.', '..') || !File.directory?(d) }.sort_by(&:length).reverse cached_used_paths = used_paths.map{ |path| path.to_s }
dirs.each { |d| FileUtils.rm_rf(d) if File.symlink?(d) || (Dir.entries(d) == %w[ . .. ]) } files = Dir.glob(root + "**/*", File::FNM_DOTMATCH)
files.reject! do |candidate|
candidate.end_with?('.', '..') ||
cached_used_paths.any? { |path| path.include?(candidate) || candidate.include?(path) }
end
files
end end
# File attributes # Public: Finds all the absolute paths used by pod.
#
# Returns an Array of Pathnames containing the absolute paths.
def used_paths
files = source_files(false) + resources(false) + preserve_paths + [ readme_file, license_file, prefix_header_file ]
files.compact
end
### File attributes
def prefix_header_file def prefix_header_file
root + top_specification.prefix_header_file if top_specification.prefix_header_file root + top_specification.prefix_header_file if top_specification.prefix_header_file
...@@ -96,15 +111,6 @@ module Pod ...@@ -96,15 +111,6 @@ module Pod
chained_expanded_paths(:resources, :relative_to_sandbox => relative) chained_expanded_paths(:resources, :relative_to_sandbox => relative)
end end
def clean_files
all_files = Dir.glob(root + "**/*", File::FNM_DOTMATCH).map { |f| root + f }.reject { |p| p.directory? }
all_files - used_files
end
def used_files
source_files(false) + resources(false) + preserve_paths + [ readme_file, license_file, prefix_header_file ]
end
# TODO: implement case insensitive search # TODO: implement case insensitive search
def preserve_paths def preserve_paths
chained_expanded_paths(:preserve_paths) + expanded_paths(%w[ *.podspec notice* NOTICE* CREDITS* ]) chained_expanded_paths(:preserve_paths) + expanded_paths(%w[ *.podspec notice* NOTICE* CREDITS* ])
......
...@@ -38,10 +38,11 @@ describe Pod::LocalPod do ...@@ -38,10 +38,11 @@ describe Pod::LocalPod do
end end
it 'returns an expanded list the files to clean' do it 'returns an expanded list the files to clean' do
clean_files = @pod.clean_files.map { |p| p.to_s } clean_paths = @pod.clean_paths.map { |p| p.to_s.gsub(/.*Pods\/BananaLib/,'') }
clean_files.should.include "#{@sandbox.root}/BananaLib/.git/config" clean_paths.should.include "/.git/config"
clean_files_without_hidden = clean_files.reject { |p| p.to_s.include?('/.') } # There are some hidden files on Travis
clean_files_without_hidden.should == ["#{@sandbox.root}/BananaLib/sub-dir/sub-dir-2/somefile.txt"] clean_files_without_hidden = clean_paths.reject { |p| p.to_s.include?('/.') }
clean_files_without_hidden.should == %W[ /sub-dir /sub-dir/sub-dir-2 /sub-dir/sub-dir-2/somefile.txt ]
end end
it 'returns an expanded list of resources, relative to the sandbox root' do it 'returns an expanded list of resources, relative to the sandbox root' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment