66a9ecb09ddf3f3337e3238d5e3fd5950c142901bd5571a2e58ab91659247bbac734b134055dff3c5d61cbdf188a661f797c954dec0ba3adfd01c34fee6df4 917 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict'
  2. const util = require('util')
  3. const figgyPudding = require('figgy-pudding')
  4. const fixOwner = require('./fix-owner')
  5. const path = require('path')
  6. const rimraf = util.promisify(require('rimraf'))
  7. const uniqueFilename = require('unique-filename')
  8. const { disposer } = require('./disposer')
  9. const TmpOpts = figgyPudding({
  10. tmpPrefix: {}
  11. })
  12. module.exports.mkdir = mktmpdir
  13. function mktmpdir (cache, opts) {
  14. opts = TmpOpts(opts)
  15. const tmpTarget = uniqueFilename(path.join(cache, 'tmp'), opts.tmpPrefix)
  16. return fixOwner.mkdirfix(cache, tmpTarget).then(() => {
  17. return tmpTarget
  18. })
  19. }
  20. module.exports.withTmp = withTmp
  21. function withTmp (cache, opts, cb) {
  22. if (!cb) {
  23. cb = opts
  24. opts = null
  25. }
  26. opts = TmpOpts(opts)
  27. return disposer(mktmpdir(cache, opts), rimraf, cb)
  28. }
  29. module.exports.fix = fixtmpdir
  30. function fixtmpdir (cache) {
  31. return fixOwner(cache, path.join(cache, 'tmp'))
  32. }