Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
fix(extract-stream): miscellaneous post-test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Feb 22, 2017
1 parent 93214eb commit 73c14b2
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions lib/extract-stream.js
Expand Up @@ -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),
Expand All @@ -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
}

0 comments on commit 73c14b2

Please sign in to comment.