diff options
author | Gar <gar+gh@danger.computer> | 2021-08-26 21:20:59 +0300 |
---|---|---|
committer | Gar <gar+gh@danger.computer> | 2021-08-26 21:20:59 +0300 |
commit | e63a942c685233fa546788981ed9c144220d50e1 (patch) | |
tree | 4115e9ae913ad1b688c35711418a528184c9b337 /node_modules/cacache/lib/util/tmp.js | |
parent | 7af36bb9f8e5c9facaa8deb114b76368841fbc66 (diff) |
cacache@15.3.0
* feat: introduce @npmcli/fs for tmp dir methods
Diffstat (limited to 'node_modules/cacache/lib/util/tmp.js')
-rw-r--r-- | node_modules/cacache/lib/util/tmp.js | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/node_modules/cacache/lib/util/tmp.js b/node_modules/cacache/lib/util/tmp.js index fbcd2ab13..0a5a50eba 100644 --- a/node_modules/cacache/lib/util/tmp.js +++ b/node_modules/cacache/lib/util/tmp.js @@ -1,21 +1,21 @@ 'use strict' -const util = require('util') +const fs = require('@npmcli/fs') const fixOwner = require('./fix-owner') const path = require('path') -const rimraf = util.promisify(require('rimraf')) -const uniqueFilename = require('unique-filename') -const { disposer } = require('./disposer') module.exports.mkdir = mktmpdir function mktmpdir (cache, opts = {}) { const { tmpPrefix } = opts - const tmpTarget = uniqueFilename(path.join(cache, 'tmp'), tmpPrefix) - return fixOwner.mkdirfix(cache, tmpTarget).then(() => { - return tmpTarget - }) + const tmpDir = path.join(cache, 'tmp') + return fs.mkdir(tmpDir, { recursive: true, owner: 'inherit' }) + .then(() => { + // do not use path.join(), it drops the trailing / if tmpPrefix is unset + const target = `${tmpDir}${path.sep}${tmpPrefix || ''}` + return fs.mkdtemp(target, { owner: 'inherit' }) + }) } module.exports.withTmp = withTmp @@ -25,7 +25,7 @@ function withTmp (cache, opts, cb) { cb = opts opts = {} } - return disposer(mktmpdir(cache, opts), rimraf, cb) + return fs.withTempDir(path.join(cache, 'tmp'), cb, opts) } module.exports.fix = fixtmpdir |