Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

tmp.js 879B

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