From 73c14b28d87932a81c6e710ce7f15e7d022d28d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Tue, 21 Feb 2017 00:03:14 -0800 Subject: [PATCH] fix(extract-stream): miscellaneous post-test fixes --- lib/extract-stream.js | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/lib/extract-stream.js b/lib/extract-stream.js index a7f0457..4d5a513 100644 --- a/lib/extract-stream.js +++ b/lib/extract-stream.js @@ -7,12 +7,30 @@ var tar = require('tar-fs') module.exports = extractStream function extractStream (dest, opts) { + opts = opts || {} + var sawIgnores = {} return pipeline(gunzip(), tar.extract(dest, { map: function (header) { if (process.platform !== 'win32') { header.uid = opts.uid == null ? header.uid : opts.uid header.gid = opts.gid == null ? header.gid : opts.gid } + // Note: This mirrors logic in the fs read operations that are + // employed during tarball creation, in the fstream-npm module. + // It is duplicated here to handle tarballs that are created + // using other means, such as system tar or git archive. + if (header.type === 'file') { + var base = path.basename(header.name) + if (base === '.npmignore') { + sawIgnores[header.name] = true + } else if (base === '.gitignore') { + var npmignore = header.name.replace(/\.gitignore$/, '.npmignore') + if (!sawIgnores[npmignore]) { + // Rename, may be clobbered later. + header.name = npmignore + } + } + } return header }, ignore: makeIgnore(opts.log), @@ -31,36 +49,15 @@ function makeIgnore (log) { } function _ignore (name, header, sawIgnores, logger) { - if (header.type.match(/^.*Link$/)) { + if (header.type.match(/^.*link$/)) { if (logger) { logger.warn( 'extract-stream', 'excluding symbolic link', - header.path, '->', header.linkname) + header.name, '->', header.linkname) } return true } - // Note: This mirrors logic in the fs read operations that are - // employed during tarball creation, in the fstream-npm module. - // It is duplicated here to handle tarballs that are created - // using other means, such as system tar or git archive. - if (header.type === 'File') { - var base = path.basename(header.path) - if (base === '.npmignore') { - sawIgnores[header.path] = true - } else if (base === '.gitignore') { - var npmignore = header.path.replace(/\.gitignore$/, '.npmignore') - if (sawIgnores[npmignore]) { - // Skip this one, already seen. - return true - } else { - // Rename, may be clobbered later. - header.path = npmignore - header._path = npmignore - } - } - } - return false }