Commit 85c65849 authored by Fabio Pelosin's avatar Fabio Pelosin

[LocalPod] Fix bug where in #clean.

The bug would leave trailing directories like
'.git'
parent 66138897
...@@ -64,17 +64,19 @@ module Pod ...@@ -64,17 +64,19 @@ module Pod
root.rmtree if exists? root.rmtree if exists?
end end
# It deletes all the files identified by clean_paths, then it removes # It deletes all the files identified by clean_files, then it removes
# all the empty folders or symlinks. # all the empty folders or symlinks.
def clean def clean
clean_paths.each { |path| FileUtils.rm_rf(path) } clean_files.each { |path| FileUtils.rm_rf(path) }
Dir.glob("#{root}/**/{*,.*}").
sort_by(&:length).reverse. # Clean the deepest paths first to determine if the containing folders are empty # Get all the directories. Then sort them from the longest
reject { |d| d =~ /\/\.\.?$/ }. # Remove the `.` and `..` paths # to the shortest, so a directory will be empty if its
select { |d| File.directory?(d) }. # Get only directories or symlinks to directories # subdirs where empty. We need to delete the symlinks because
each do |d| # it might prevent a bundle from being deleted
FileUtils.rm_rf(d) if File.symlink?(d) || (Dir.entries(d) == %w[ . .. ]) # Remove the symlink and the empty dirs dirs = Dir.glob(root + "**/*", File::FNM_DOTMATCH)
end dirs = dirs.reject { |d| d.end_with? ('.', '..') || !File.directory?(d) }.sort_by(&:length).reverse
dirs.each { |d| puts d }
dirs.each { |d| FileUtils.rm_rf(d) if File.symlink?(d) || (Dir.entries(d) == %w[ . .. ]) }
end end
# File attributes # File attributes
...@@ -95,12 +97,13 @@ module Pod ...@@ -95,12 +97,13 @@ module Pod
chained_expanded_paths(:resources, :relative_to_sandbox => relative) chained_expanded_paths(:resources, :relative_to_sandbox => relative)
end end
def clean_paths def clean_files
expanded_paths('**/{*,.*}').reject { |p| p.directory? } - used_files all_files = Dir.glob(root + "**/*", File::FNM_DOTMATCH).map { |f| root + f }.reject { |p| p.directory? }
all_files - used_files
end end
def used_files def used_files
source_files(false) + resources(false) + [ readme_file, license_file, prefix_header_file ] + preserve_paths source_files(false) + resources(false) + preserve_paths + [ readme_file, license_file, prefix_header_file ]
end end
# TODO: implement case insensitive search # TODO: implement case insensitive search
......
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