mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
7f48c67512
* Add `unicorn/prefer-node-protocol` * Fix `unicorn/prefer-node-protocol` ESLint errors * Run `npm run format:fix` * Add sandboxed-module sourceTransformers in mocha setups Fix `no such file or directory, open 'node:fs'` in `sandboxed-module` * Remove `node:` in the SandboxedModule requires * Fix new linting errors with `node:` GitOrigin-RevId: 68f6e31e2191fcff4cb8058dd0a6914c14f59926
25 lines
841 B
JavaScript
25 lines
841 B
JavaScript
/*
|
|
* Taken from renderer/app/helpers/temp.js with minor cosmetic changes.
|
|
* Promisify the temp package. The temp package provides a 'track' feature
|
|
* that automatically cleans up temp files at process exit, but that is not
|
|
* very useful. They also provide a method to trigger cleanup, but that is not
|
|
* safe for concurrent use. So, we use a disposer to unlink the file.
|
|
*/
|
|
|
|
const BPromise = require('bluebird')
|
|
const fs = BPromise.promisifyAll(require('node:fs'))
|
|
const temp = BPromise.promisifyAll(require('temp'))
|
|
|
|
exports.open = function (affixes) {
|
|
return temp.openAsync(affixes).disposer(function (fileInfo) {
|
|
fs.closeAsync(fileInfo.fd)
|
|
.then(() => {
|
|
return fs.unlinkAsync(fileInfo.path)
|
|
})
|
|
.catch(function (err) {
|
|
if (err.code !== 'ENOENT') {
|
|
throw err
|
|
}
|
|
})
|
|
})
|
|
}
|