Permalink
Browse files

Make --exclude on 'foo' kill any files like foo/bar/baz - #248

  • Loading branch information...
1 parent 32f282d commit 376ea7d7943ac9d9c3edf013707059a7c1787e85 @jordansissel committed Aug 14, 2012
Showing with 40 additions and 10 deletions.
  1. +30 −10 lib/fpm/package.rb
  2. +10 −0 spec/fpm/package_spec.rb
View
@@ -343,23 +343,43 @@ def exclude
installdir = staging_path
end
+ exclude_path = proc do |file|
+ FileUtils.remove_entry_secure(staging_path(file))
+ Pathname.new(staging_path(file)).parent.ascend do |d|
+ if (::Dir.entries(d) - %w[ . .. ]).empty?
+ ::Dir.rmdir(d)
+ @logger.info("Deleting empty directory left by removing exluded file", :path => d)
+ else
+ break
+ end
+ end
+ end # exclude_path
+
attributes[:excludes].each do |wildcard|
@logger.debug("Checking for things to exclude", :wildcard => wildcard)
files.each do |file|
+ @logger.debug("Checking path against wildcard", :path => file, :wildcard => wildcard)
if File.fnmatch(wildcard, file)
@logger.info("Removing excluded file", :path => file, :matches => wildcard)
- FileUtils.remove_entry_secure(staging_path(file))
- Pathname.new(staging_path(file)).parent.ascend do |d|
- if (::Dir.entries(d) - %w[ . .. ]).empty?
- ::Dir.rmdir(d)
- @logger.info("Deleting empty directory left by removing exluded file", :path => d)
- else
- break
- end
+ exclude_path.call(file)
+ next
+ end
+
+ @logger.debug("Checking if path is a child of an excluded directory",
+ :path => file, :wildcard => wildcard,
+ :directory? => File.directory?(staging_path(wildcard)))
+ if File.directory?(staging_path(wildcard))
+ # issue #248, if the excludes entry is a directory, ignore that
+ # directory and anything inside it.
+ exclude_re = Regexp.new("^#{Regexp.escape(wildcard)}($|/)")
+ if exclude_re.match(file)
+ @logger.info("Removing excluded file which has a parent excluded directory",
+ :path => file, :excluded => wildcard)
+ exclude_path.call(file)
end
end
- end
- end
+ end
+ end # files.each
end # def exclude
View
@@ -140,6 +140,16 @@
subject.instance_eval { exclude }
insist { subject.files } == ["hello"]
end
+
+ it "should obey attributes[:excludes] for child directories" do
+ Dir.mkdir(subject.staging_path("example"))
+ Dir.mkdir(subject.staging_path("example/foo"))
+ File.write(subject.staging_path("example/foo/delete_me"), "Hello!")
+ File.write(subject.staging_path("keeper"), "Hello!")
+ subject.attributes[:excludes] = [ "example/foo" ]
+ subject.instance_eval { exclude }
+ insist { subject.files } == [ "keeper" ]
+ end
end
context "#script (internal method)" do

0 comments on commit 376ea7d

Please sign in to comment.