-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: fix-owner now uses Promises instead of callbacks
- Loading branch information
Showing
1 changed file
with
19 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,44 @@ | ||
'use strict' | ||
|
||
var chownr = require('chownr') | ||
var dezalgo = require('dezalgo') | ||
var inflight = require('inflight') | ||
var mkdirp = require('mkdirp') | ||
const Promise = require('bluebird') | ||
|
||
const chownr = Promise.promisify(require('chownr')) | ||
const mkdirp = Promise.promisify(require('mkdirp')) | ||
|
||
module.exports.chownr = fixOwner | ||
function fixOwner (filepath, uid, gid, cb) { | ||
cb = dezalgo(cb) | ||
function fixOwner (filepath, uid, gid) { | ||
if (!process.getuid) { | ||
// This platform doesn't need ownership fixing | ||
return cb() | ||
return Promise.resolve() | ||
} | ||
if (typeof uid !== 'number' && typeof gid !== 'number') { | ||
// There's no permissions override. Nothing to do here. | ||
return cb() | ||
return Promise.resolve() | ||
} | ||
if ((typeof uid === 'number' && process.getuid() === uid) && | ||
(typeof gid === 'number' && process.getgid() === gid)) { | ||
// No need to override if it's already what we used. | ||
return cb() | ||
} | ||
cb = inflight('fixOwner: fixing ownership on ' + filepath, cb) | ||
if (!cb) { | ||
// We're inflight! whoosh! | ||
return | ||
return Promise.resolve() | ||
} | ||
// cb = inflight('fixOwner: fixing ownership on ' + filepath, cb) | ||
// if (!cb) { | ||
// // We're inflight! whoosh! | ||
// return | ||
// } | ||
|
||
// *now* we override perms | ||
chownr( | ||
return chownr( | ||
filepath, | ||
typeof uid === 'number' ? uid : process.getuid(), | ||
typeof gid === 'number' ? gid : process.getgid(), | ||
cb | ||
typeof gid === 'number' ? gid : process.getgid() | ||
) | ||
} | ||
|
||
module.exports.mkdirfix = mkdirfix | ||
function mkdirfix (p, uid, gid, cb) { | ||
mkdirp(p, function (err, made) { | ||
if (err || !made) { return cb(err, made) } | ||
fixOwner(made, uid, gid, cb) | ||
return mkdirp(p).then(made => { | ||
if (made) { | ||
return fixOwner(made, uid, gid).then(() => made) | ||
} | ||
}) | ||
} |