source: node_modules/@npmcli/fs/lib/mkdtemp.js@ 81bc7da

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: 891 bytes
RevLine 
[81bc7da]1const { dirname, sep } = require('path')
2
3const fs = require('./fs.js')
4const getOptions = require('./common/get-options.js')
5const owner = require('./common/owner.js')
6
7const mkdtemp = async (prefix, opts) => {
8 const options = getOptions(opts, {
9 copy: ['encoding', 'owner'],
10 wrap: 'encoding',
11 })
12
13 // mkdtemp relies on the trailing path separator to indicate if it should
14 // create a directory inside of the prefix. if that's the case then the root
15 // we infer ownership from is the prefix itself, otherwise it's the dirname
16 // /tmp -> /tmpABCDEF, infers from /
17 // /tmp/ -> /tmp/ABCDEF, infers from /tmp
18 const root = prefix.endsWith(sep) ? prefix : dirname(prefix)
19 const { uid, gid } = await owner.validate(root, options.owner)
20
21 const result = await fs.mkdtemp(prefix, options)
22
23 await owner.update(result, uid, gid)
24
25 return result
26}
27
28module.exports = mkdtemp
Note: See TracBrowser for help on using the repository browser.