This repository has been archived by the owner on Jul 3, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: this changes the underlying tar library, and thus may introduce some subtle low-level incompatibility. Also: * The tarball packer built into pacote works much closer to how the one npm injects does. * Special characters on Windows will now be escaped the way tar(1) usually does: by replacing them with the `0xf000` masked character on the way out. * Directories won't be chowned.
- Loading branch information
Showing
7 changed files
with
123 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,33 @@ | ||
'use strict' | ||
|
||
const gunzip = require('./util/gunzip-maybe') | ||
const path = require('path') | ||
const pipeline = require('mississippi').pipeline | ||
const tar = require('tar-fs') | ||
const tar = require('tar') | ||
|
||
module.exports = extractStream | ||
function extractStream (dest, opts) { | ||
function extractStream (dest, opts, cb) { | ||
opts = opts || {} | ||
const sawIgnores = {} | ||
return pipeline(gunzip(), tar.extract(dest, { | ||
map: (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') { | ||
const base = path.basename(header.name) | ||
if (base === '.npmignore') { | ||
sawIgnores[header.name] = true | ||
} else if (base === '.gitignore') { | ||
const npmignore = header.name.replace(/\.gitignore$/, '.npmignore') | ||
if (!sawIgnores[npmignore]) { | ||
// Rename, may be clobbered later. | ||
header.name = npmignore | ||
} | ||
} | ||
} | ||
return header | ||
}, | ||
ignore: makeIgnore(opts.log), | ||
dmode: opts.dmode, | ||
fmode: opts.fmode, | ||
umask: opts.umask, | ||
strip: 1 | ||
})) | ||
return tar.x({ | ||
cwd: dest, | ||
filter: (name, entry) => !entry.header.type.match(/^.*link$/i), | ||
strip: 1, | ||
onwarn: msg => opts.log && opts.log.warn('tar', msg), | ||
onentry: makeOnEntry(opts), | ||
preserveOwner: opts.uid != null || opts.gid != null | ||
}) | ||
} | ||
|
||
function makeIgnore (log) { | ||
const sawIgnores = {} | ||
return (name, header) => _ignore(name, header, sawIgnores, log) | ||
function makeOnEntry (opts) { | ||
const sawEntry = {} | ||
return entry => _onentry(entry, sawEntry, opts) | ||
} | ||
|
||
function _ignore (name, header, sawIgnores, logger) { | ||
if (header.type.match(/^.*link$/)) { | ||
if (logger) { | ||
logger.warn( | ||
'extract-stream', | ||
'excluding symbolic link', | ||
header.name, '->', header.linkname) | ||
} | ||
return true | ||
function _onentry (entry, sawIgnores, opts) { | ||
if (process.getuid) { | ||
entry.uid = opts.uid == null ? entry.uid : opts.uid | ||
entry.gid = opts.gid == null ? entry.gid : opts.gid | ||
} | ||
if (entry.type.toLowerCase() === 'file') { | ||
entry.mode = opts.fmode & ~(opts.umask || 0) | ||
} else if (entry.type.toLowerCase() === 'directory') { | ||
entry.mode = opts.dmode & ~(opts.umask || 0) | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.