diff --git a/lib/mixlib/archive.rb b/lib/mixlib/archive.rb index ae31cd9..25deef5 100644 --- a/lib/mixlib/archive.rb +++ b/lib/mixlib/archive.rb @@ -26,7 +26,7 @@ def create(files = [], gzip: false) end def extract(destination, perms: true, ignore: []) - ignore = [/^\.$/, /\.{2}/] + Array(ignore) + ignore = [/^\.$/, /\.{2}#{path_separator}/] + Array(ignore) create_and_empty(destination) @@ -35,6 +35,16 @@ def extract(destination, perms: true, ignore: []) private + BACKSLASH = '\\'.freeze + + def path_separator + if Gem.win_platform? + File::ALT_SEPARATOR || BACKSLASH + else + File::SEPARATOR + end + end + def create_and_empty(destination) FileUtils.mkdir_p(destination) if @empty diff --git a/spec/mixlib/archive_spec.rb b/spec/mixlib/archive_spec.rb index 48dd331..b5c75a6 100644 --- a/spec/mixlib/archive_spec.rb +++ b/spec/mixlib/archive_spec.rb @@ -58,22 +58,22 @@ end it "runs the extractor" do - expect(archiver).to receive(:extract).with(destination, { perms: true, ignore: [/^\.$/, /\.{2}/] }) + expect(archiver).to receive(:extract).with(destination, { perms: true, ignore: [/^\.$/, /\.{2}\//] }) archive.extract(destination) end it "passes options to the extractor" do - expect(archiver).to receive(:extract).with(destination, { perms: false, ignore: [/^\.$/, /\.{2}/] }) + expect(archiver).to receive(:extract).with(destination, { perms: false, ignore: [/^\.$/, /\.{2}\//] }) archive.extract(destination, perms: false) end it "allows the user to ignore more patterns" do - expect(archiver).to receive(:extract).with(destination, { perms: false, ignore: [/^\.$/, /\.{2}/, /^$/] }) + expect(archiver).to receive(:extract).with(destination, { perms: false, ignore: [/^\.$/, /\.{2}\//, /^$/] }) archive.extract(destination, perms: false, ignore: [/^$/]) end it "accepts a single ignore pattern" do - expect(archiver).to receive(:extract).with(destination, { perms: false, ignore: [/^\.$/, /\.{2}/, /^$/] }) + expect(archiver).to receive(:extract).with(destination, { perms: false, ignore: [/^\.$/, /\.{2}\//, /^$/] }) archive.extract(destination, perms: false, ignore: /^$/) end end