Skip to content

Commit

Permalink
fix(extract): revert uid/gid change
Browse files Browse the repository at this point in the history
This reverts commit 6fc01a5.

This was the wrong thing to do.

BREAKING CHANGE: behavior for setting uid/gid on extracted contents was restored to what it was in pacote@2
  • Loading branch information
zkat committed Jun 29, 2017
1 parent 71c5ee1 commit 41852e0
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lib/extract-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@ const path = require('path')
const pipeline = require('mississippi').pipeline
const tar = require('tar-fs')

let uid
let gid
if (process.platform !== 'win32') {
uid = process.getuid()
gid = process.getgid()
}

module.exports = extractStream
function extractStream (dest, opts) {
opts = opts || {}
const sawIgnores = {}
return pipeline(gunzip(), tar.extract(dest, {
map: (header) => {
if (uid != null) { header.uid = uid }
if (gid != null) { header.gid = gid }
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
Expand Down
65 changes: 65 additions & 0 deletions test/extract-stream.chown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'use strict'

const BB = require('bluebird')

const fs = require('fs')
const mockTar = require('./util/mock-tarball')
const npmlog = require('npmlog')
const path = require('path')
const pipe = BB.promisify(require('mississippi').pipe)
const requireInject = require('require-inject')
const test = require('tap').test

require('./util/test-dir')(__filename)

npmlog.level = process.env.LOGLEVEL || 'silent'

test('accepts gid and uid opts', {
skip: !process.getuid
}, function (t) {
const pkg = {
'package.json': {
data: JSON.stringify({
name: 'foo',
version: '1.0.0'
})
},
'foo/index.js': 'console.log("hello world!")'
}
const NEWUID = process.getuid() + 1
const NEWGID = process.getgid() + 1
// All of this only happens on uid === 0
process.getuid = () => 0
const updatedPaths = []
const fsClone = Object.create(fs)
fsClone.chown = (p, uid, gid, cb) => {
process.nextTick(() => {
t.deepEqual({
uid: uid,
gid: gid
}, {
uid: NEWUID,
gid: NEWGID
}, 'correct owner set on ' + p)
updatedPaths.push(path.relative('.', p))
cb(null)
})
}
const extractStream = requireInject('../lib/extract-stream', {
fs: fsClone
})
return mockTar(pkg, {stream: true}).then(tarStream => {
return pipe(tarStream, extractStream('./target', {
uid: NEWUID,
gid: NEWGID,
log: npmlog
}))
}).then(() => {
t.deepEqual(updatedPaths, [
'target',
'target/package.json',
'target/foo',
'target/foo/index.js'
], 'extracted files had correct uid/gid set')
})
})

0 comments on commit 41852e0

Please sign in to comment.