finki-main
main
|
Last change
on this file since 81bc7da was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago |
|
Initial commit
|
-
Property mode
set to
100644
|
|
File size:
981 bytes
|
| Line | |
|---|
| 1 | const fs = require('../fs.js')
|
|---|
| 2 | const getOptions = require('../common/get-options.js')
|
|---|
| 3 | const node = require('../common/node.js')
|
|---|
| 4 | const owner = require('../common/owner.js')
|
|---|
| 5 |
|
|---|
| 6 | const polyfill = require('./polyfill.js')
|
|---|
| 7 |
|
|---|
| 8 | // node 10.12.0 added the options parameter, which allows recursive and mode
|
|---|
| 9 | // properties to be passed
|
|---|
| 10 | const useNative = node.satisfies('>=10.12.0')
|
|---|
| 11 |
|
|---|
| 12 | // extends mkdir with the ability to specify an owner of the new dir
|
|---|
| 13 | const mkdir = async (path, opts) => {
|
|---|
| 14 | const options = getOptions(opts, {
|
|---|
| 15 | copy: ['mode', 'recursive', 'owner'],
|
|---|
| 16 | wrap: 'mode',
|
|---|
| 17 | })
|
|---|
| 18 | const { uid, gid } = await owner.validate(path, options.owner)
|
|---|
| 19 |
|
|---|
| 20 | // the polyfill is tested separately from this module, no need to hack
|
|---|
| 21 | // process.version to try to trigger it just for coverage
|
|---|
| 22 | // istanbul ignore next
|
|---|
| 23 | const result = useNative
|
|---|
| 24 | ? await fs.mkdir(path, options)
|
|---|
| 25 | : await polyfill(path, options)
|
|---|
| 26 |
|
|---|
| 27 | await owner.update(path, uid, gid)
|
|---|
| 28 |
|
|---|
| 29 | return result
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | module.exports = mkdir
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.