Permalink
Browse files

Make sure the glob matching for copy excludes does not delete parent …

…dirs
  • Loading branch information...
1 parent d558838 commit 6d1ca8ca504889843da1defd109f913077407c82 @akitaonrails akitaonrails committed with jamis Sep 17, 2008
Showing with 14 additions and 5 deletions.
  1. +2 −0 CHANGELOG.rdoc
  2. +8 −1 lib/capistrano/recipes/deploy/strategy/copy.rb
  3. +4 −4 test/deploy/strategy/copy_test.rb
View
@@ -1,5 +1,7 @@
== (unreleased)
+* Make sure the glob matching for copy excludes does not delete parent directories [Fabio Akita]
+
* Ruby 1.9 compatibility [Jamis Buck]
@@ -80,7 +80,14 @@ def deploy!
if copy_exclude.any?
logger.debug "processing exclusions..."
- copy_exclude.each { |pattern| FileUtils.rm_rf(Dir.glob(File.join(destination, pattern), File::FNM_DOTMATCH)) }
+ if copy_exclude.any?
+ copy_exclude.each do |pattern|
+ delete_list = Dir.glob(File.join(destination, pattern), File::FNM_DOTMATCH)
+ # avoid the /.. trap that deletes the parent directories
+ delete_list.delete_if { |dir| dir =~ /\/\.\.$/ }
+ FileUtils.rm_rf(delete_list.compact)
+ end
+ end
end
end
@@ -29,9 +29,9 @@ def test_deploy_with_exclusions_should_remove_patterns_from_destination
Dir.expects(:tmpdir).returns("/temp/dir")
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
@strategy.expects(:system).with(:local_checkout)
- Dir.expects(:glob).with("/temp/dir/1234567890/.git", File::FNM_DOTMATCH).returns("/temp/dir/1234567890/.git")
+ Dir.expects(:glob).with("/temp/dir/1234567890/.git", File::FNM_DOTMATCH).returns(%w(/temp/dir/1234567890/.git))
- FileUtils.expects(:rm_rf).with("/temp/dir/1234567890/.git")
+ FileUtils.expects(:rm_rf).with(%w(/temp/dir/1234567890/.git))
prepare_standard_compress_and_copy!
@strategy.deploy!
end
@@ -41,9 +41,9 @@ def test_deploy_with_exclusions_should_remove_glob_patterns_from_destination
Dir.expects(:tmpdir).returns("/temp/dir")
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
@strategy.expects(:system).with(:local_checkout)
- Dir.expects(:glob).with("/temp/dir/1234567890/.gi*", File::FNM_DOTMATCH).returns("/temp/dir/1234567890/.git")
+ Dir.expects(:glob).with("/temp/dir/1234567890/.gi*", File::FNM_DOTMATCH).returns(%w(/temp/dir/1234567890/.git))
- FileUtils.expects(:rm_rf).with("/temp/dir/1234567890/.git")
+ FileUtils.expects(:rm_rf).with(%w(/temp/dir/1234567890/.git))
prepare_standard_compress_and_copy!
@strategy.deploy!
end

0 comments on commit 6d1ca8c

Please sign in to comment.