diff --git a/lib/mixlib/archive.rb b/lib/mixlib/archive.rb index 09b3929..e7bac82 100644 --- a/lib/mixlib/archive.rb +++ b/lib/mixlib/archive.rb @@ -40,7 +40,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) @@ -49,6 +49,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 f6f95c7..4f2034b 100644 --- a/spec/mixlib/archive_spec.rb +++ b/spec/mixlib/archive_spec.rb @@ -61,22 +61,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