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

Commit

Permalink
fix(extract): preserve executable perms on extracted files
Browse files Browse the repository at this point in the history
Fixes: npm/npm#18324

This is basically a copy-paste from the old way npm
would set permissions on extract, and should now be
fully compatible again. I hope. Sigh.
  • Loading branch information
zkat committed Sep 5, 2017
1 parent 9ddc52e commit 8d61978
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions lib/extract-stream.js
Expand Up @@ -15,11 +15,10 @@ function extractStream (dest, opts) {
uid: opts.uid,
gid: opts.gid,
onentry (entry) {
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)
}
entry.mode = entry.mode | (
entry.type.toLowerCase() === 'directory' ? opts.dmode : opts.fmode
)
entry.mode = entry.mode & (~opts.umask || 0)

// Note: This mirrors logic in the fs read operations that are
// employed during tarball creation, in the fstream-npm module.
Expand Down
4 changes: 2 additions & 2 deletions test/extract-stream.chown.js
Expand Up @@ -54,11 +54,11 @@ test('accepts gid and uid opts', {skip: !process.getuid}, t => {
log: npmlog
}))
}).then(() => {
t.deepEqual(updatedPaths, [
t.deepEqual(updatedPaths.sort(), [
'target',
'target/foo',
'target/package.json',
'target/foo/index.js'
], 'extracted files had correct uid/gid set')
].sort(), 'extracted files had correct uid/gid set')
})
})

0 comments on commit 8d61978

Please sign in to comment.