You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
495 B
22 lines
495 B
2 years ago
|
const getOptions = require('./common/get-options.js')
|
||
|
const owner = require('./common/owner.js')
|
||
|
|
||
|
const withOwner = async (path, fn, opts) => {
|
||
|
const options = getOptions(opts, {
|
||
|
copy: ['owner'],
|
||
|
})
|
||
|
|
||
|
const { uid, gid } = await owner.validate(path, options.owner)
|
||
|
|
||
|
const result = await fn({ uid, gid })
|
||
|
|
||
|
await Promise.all([
|
||
|
owner.update(path, uid, gid),
|
||
|
typeof result === 'string' ? owner.update(result, uid, gid) : null,
|
||
|
])
|
||
|
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
module.exports = withOwner
|