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

Commit

Permalink
fix(tar): chown directories on extract as well
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Aug 17, 2017
1 parent e702e17 commit 2fa4598
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
28 changes: 9 additions & 19 deletions lib/extract-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,14 @@ function extractStream (dest, opts, cb) {
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
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)
}
}
})
}

function makeOnEntry (opts) {
const sawEntry = {}
return entry => _onentry(entry, sawEntry, opts)
}

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)
}
}
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"safe-buffer": "^5.1.1",
"semver": "^5.4.1",
"ssri": "^4.1.6",
"tar": "^3.1.13",
"tar": "^3.2.0",
"unique-filename": "^1.1.0",
"which": "^1.3.0"
},
Expand Down
2 changes: 2 additions & 0 deletions test/extract-stream.chown.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ test('accepts gid and uid opts', {skip: !process.getuid}, t => {
}))
}).then(() => {
t.deepEqual(updatedPaths, [
'target',
'target/foo',
'target/package.json',
'target/foo/index.js'
], 'extracted files had correct uid/gid set')
Expand Down

0 comments on commit 2fa4598

Please sign in to comment.