Commit 1eca09e9 authored by Ian Baum's avatar Ian Baum

Merge branch 'exclude-fnmatch-tweaking' into 'gitlab-omnibus-v5.6.12'

Change exclude to use `**` to skip levels

See merge request gitlab-org/omnibus!10
parents 8c83c9df 9fd87394
......@@ -56,13 +56,13 @@ module Omnibus
#
def all_files_under(source, options = {})
excludes = Array(options[:exclude]).map do |exclude|
[exclude, "#{exclude}/*"]
[exclude, "#{exclude}/**"]
end.flatten
source_files = glob(File.join(source, "**/*"))
source_files = source_files.reject do |source_file|
basename = relative_path_for(source_file, source)
excludes.any? { |exclude| File.fnmatch?(exclude, basename, File::FNM_DOTMATCH) }
excludes.any? { |exclude| File.fnmatch?(exclude, basename, File::FNM_DOTMATCH | File::FNM_PATHNAME) }
end
end
......
......@@ -56,6 +56,15 @@ module Omnibus
FileUtils.touch(File.join(source, ".dot_folder", "file_f"))
FileUtils.touch(File.join(source, ".file_g"))
FileUtils.mkdir_p(File.join(source, "nested", "deep", "folder"))
FileUtils.touch(File.join(source, "nested", "deep", "folder", "file_h"))
FileUtils.touch(File.join(source, "nested", "deep", "folder", "file_i"))
FileUtils.mkdir_p(File.join(source, "nested", "deep", "deep", "folder"))
FileUtils.touch(File.join(source, "nested", "deep", "deep", "folder", "file_j"))
FileUtils.touch(File.join(source, "nested", "deep", "deep", "folder", "file_k"))
source
end
......@@ -233,6 +242,40 @@ module Omnibus
expect("#{destination}/.file_g").to be_a_file
end
it "does not copy files and folders that match the wildcard pattern" do
described_class.sync(source, destination, exclude: "nested/*/folder")
expect("#{destination}/file_a").to be_a_file
expect("#{destination}/file_b").to be_a_file
expect("#{destination}/file_c").to be_a_file
expect("#{destination}/folder/file_d").to be_a_file
expect("#{destination}/folder/file_e").to be_a_file
expect("#{destination}/.dot_folder").to be_a_directory
expect("#{destination}/.dot_folder/file_f").to be_a_file
expect("#{destination}/.file_g").to be_a_file
expect("#{destination}/nested/deep/folder/file_h").to_not be_a_file
expect("#{destination}/nested/deep/folder/file_i").to_not be_a_file
expect("#{destination}/nested/deep/deep/folder/file_j").to be_a_file
expect("#{destination}/nested/deep/deep/folder/file_k").to be_a_file
end
it "does not copy files and folders that match the super wildcard pattern" do
described_class.sync(source, destination, exclude: "nested/**/folder")
expect("#{destination}/file_a").to be_a_file
expect("#{destination}/file_b").to be_a_file
expect("#{destination}/file_c").to be_a_file
expect("#{destination}/folder/file_d").to be_a_file
expect("#{destination}/folder/file_e").to be_a_file
expect("#{destination}/.dot_folder").to be_a_directory
expect("#{destination}/.dot_folder/file_f").to be_a_file
expect("#{destination}/.file_g").to be_a_file
expect("#{destination}/nested/deep/folder/file_h").to_not be_a_file
expect("#{destination}/nested/deep/folder/file_i").to_not be_a_file
expect("#{destination}/nested/deep/deep/folder/file_j").to_not be_a_file
expect("#{destination}/nested/deep/deep/folder/file_k").to_not be_a_file
end
it "removes existing files and folders in destination" do
FileUtils.mkdir_p("#{destination}/existing_folder")
FileUtils.touch("#{destination}/existing_file")
......
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