1'use strict' 2 3const mkdirp = require('mkdirp') 4const inferOwner = require('infer-owner') 5const chown = require('./chown.js') 6 7module.exports = (path, cb) => { 8 // don't bother chowning if we can't anyway 9 if (process.platform === 'win32' || chown.selfOwner.uid !== 0) { 10 return mkdirp(path, cb) 11 } 12 13 inferOwner(path).then(owner => { 14 mkdirp(path, (er, made) => { 15 if (er || !made) { 16 cb(er, made) 17 } else { 18 chown(made || path, owner.uid, owner.gid, cb) 19 } 20 }) 21 }, cb) 22} 23