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
root.rmtree if exists?
end
# It deletes all the files identified by clean_files, then it removes
# all the empty folders or symlinks.
### Cleaning
# Public: Deletes any path that is not used by the pod.
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
# to the shortest, so a directory will be empty if its
# subdirs where empty. We need to delete the symlinks because
# it might prevent a bundle from being deleted
dirs = Dir.glob(root + "**/*", File::FNM_DOTMATCH)
dirs = dirs.reject { |d| d.end_with?('.', '..') || !File.directory?(d) }.sort_by(&:length).reverse
dirs.each { |d| FileUtils.rm_rf(d) if File.symlink?(d) || (Dir.entries(d) == %w[ . .. ]) }
# Public: Finds the absolute paths, including hidden ones, of the files
# that are not used by the pod and can be safely deleted.
#
# Returns an Array of Strings containing the absolute paths.
def clean_paths
cached_used_paths = used_paths.map{ |path| path.to_s }
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
# 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
root + top_specification.prefix_header_file if top_specification.prefix_header_file
......@@ -96,15 +111,6 @@ module Pod
chained_expanded_paths(:resources, :relative_to_sandbox => relative)
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
def preserve_paths
chained_expanded_paths(:preserve_paths) + expanded_paths(%w[ *.podspec notice* NOTICE* CREDITS* ])
......
......@@ -38,10 +38,11 @@ describe Pod::LocalPod do
end
it 'returns an expanded list the files to clean' do
clean_files = @pod.clean_files.map { |p| p.to_s }
clean_files.should.include "#{@sandbox.root}/BananaLib/.git/config"
clean_files_without_hidden = clean_files.reject { |p| p.to_s.include?('/.') }
clean_files_without_hidden.should == ["#{@sandbox.root}/BananaLib/sub-dir/sub-dir-2/somefile.txt"]
clean_paths = @pod.clean_paths.map { |p| p.to_s.gsub(/.*Pods\/BananaLib/,'') }
clean_paths.should.include "/.git/config"
# There are some hidden files on Travis
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
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