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