Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 835bd48

Browse files
zkatmafintosh
authored andcommitted
chown directories too (#60)
1 parent 12968d9 commit 835bd48

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

index.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var chownr = require('chownr')
12
var tar = require('tar-stream')
23
var pump = require('pump')
34
var mkdirp = require('mkdirp')
@@ -285,10 +286,14 @@ exports.extract = function (cwd, opts) {
285286

286287
if (header.type === 'directory') {
287288
stack.push([name, header.mtime])
288-
return mkdirp(name, {fs: xfs}, stat)
289+
return mkdirfix(name, {
290+
fs: xfs, own: own, uid: header.uid, gid: header.gid
291+
}, stat)
289292
}
290293

291-
mkdirp(path.dirname(name), {fs: xfs}, function (err) {
294+
mkdirfix(path.dirname(name), {
295+
fs: xfs, own: own, uid: header.uid, gid: header.gid
296+
}, function (err) {
292297
if (err) return next(err)
293298

294299
switch (header.type) {
@@ -306,3 +311,13 @@ exports.extract = function (cwd, opts) {
306311

307312
return extract
308313
}
314+
315+
function mkdirfix (name, opts, cb) {
316+
mkdirp(name, {fs: opts.xfs}, function (err, made) {
317+
if (!err && made && opts.own) {
318+
chownr(made, opts.uid, opts.gid, cb)
319+
} else {
320+
cb(err)
321+
}
322+
})
323+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.15.0",
44
"description": "filesystem bindings for tar-stream",
55
"dependencies": {
6+
"chownr": "^1.0.1",
67
"mkdirp": "^0.5.0",
78
"pump": "^1.0.0",
89
"tar-stream": "^1.1.2"

0 commit comments

Comments
 (0)