1'use strict' 2 3// A module for chowning things we just created, to preserve 4// ownership of new links and directories. 5 6const chownr = require('chownr') 7 8const selfOwner = { 9 uid: process.getuid && process.getuid(), 10 gid: process.getgid && process.getgid() 11} 12 13module.exports = (path, uid, gid, cb) => { 14 if (selfOwner.uid !== 0 || 15 uid === undefined || gid === undefined || 16 (selfOwner.uid === uid && selfOwner.gid === gid)) { 17 // don't need to, or can't chown anyway, so just leave it. 18 // this also handles platforms where process.getuid is undefined 19 return cb() 20 } 21 chownr(path, uid, gid, cb) 22} 23 24module.exports.selfOwner = selfOwner 25