finki-main
main
|
Last change
on this file since 62b2964 was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago |
|
Initial commit
|
-
Property mode
set to
100644
|
|
File size:
839 bytes
|
| Line | |
|---|
| 1 | 'use strict'
|
|---|
| 2 |
|
|---|
| 3 | const fs = require('@npmcli/fs')
|
|---|
| 4 |
|
|---|
| 5 | const fixOwner = require('./fix-owner')
|
|---|
| 6 | const path = require('path')
|
|---|
| 7 |
|
|---|
| 8 | module.exports.mkdir = mktmpdir
|
|---|
| 9 |
|
|---|
| 10 | function mktmpdir (cache, opts = {}) {
|
|---|
| 11 | const { tmpPrefix } = opts
|
|---|
| 12 | const tmpDir = path.join(cache, 'tmp')
|
|---|
| 13 | return fs.mkdir(tmpDir, { recursive: true, owner: 'inherit' })
|
|---|
| 14 | .then(() => {
|
|---|
| 15 | // do not use path.join(), it drops the trailing / if tmpPrefix is unset
|
|---|
| 16 | const target = `${tmpDir}${path.sep}${tmpPrefix || ''}`
|
|---|
| 17 | return fs.mkdtemp(target, { owner: 'inherit' })
|
|---|
| 18 | })
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | module.exports.withTmp = withTmp
|
|---|
| 22 |
|
|---|
| 23 | function withTmp (cache, opts, cb) {
|
|---|
| 24 | if (!cb) {
|
|---|
| 25 | cb = opts
|
|---|
| 26 | opts = {}
|
|---|
| 27 | }
|
|---|
| 28 | return fs.withTempDir(path.join(cache, 'tmp'), cb, opts)
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | module.exports.fix = fixtmpdir
|
|---|
| 32 |
|
|---|
| 33 | function fixtmpdir (cache) {
|
|---|
| 34 | return fixOwner(cache, path.join(cache, 'tmp'))
|
|---|
| 35 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.