OutputCacheManager.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. // TODO: This file was created by bulk-decaffeinate.
  2. // Fix any style issues and re-enable lint.
  3. /*
  4. * decaffeinate suggestions:
  5. * DS101: Remove unnecessary use of Array.from
  6. * DS102: Remove unnecessary code created because of implicit returns
  7. * DS103: Rewrite code to no longer use __guard__
  8. * DS104: Avoid inline assignments
  9. * DS204: Change includes calls to have a more natural evaluation order
  10. * DS207: Consider shorter variations of null checks
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. let OutputCacheManager
  14. const { callbackify, promisify } = require('util')
  15. const async = require('async')
  16. const fs = require('fs')
  17. const fse = require('fs-extra')
  18. const Path = require('path')
  19. const logger = require('@overleaf/logger')
  20. const _ = require('lodash')
  21. const Settings = require('@overleaf/settings')
  22. const crypto = require('crypto')
  23. const Metrics = require('./Metrics')
  24. const OutputFileOptimiser = require('./OutputFileOptimiser')
  25. const ContentCacheManager = require('./ContentCacheManager')
  26. const { QueueLimitReachedError, TimedOutError } = require('./Errors')
  27. const OLDEST_BUILD_DIR = new Map()
  28. const PENDING_PROJECT_ACTIONS = new Map()
  29. function init() {
  30. doInit().catch(err => {
  31. logger.fatal({ err }, 'low level error setting up cleanup of output dir')
  32. // consider shutting down?
  33. })
  34. }
  35. async function doInit() {
  36. await fillCache()
  37. const oldestTimestamp = await runBulkCleanup()
  38. scheduleBulkCleanup(oldestTimestamp)
  39. }
  40. function scheduleBulkCleanup(oldestTimestamp) {
  41. const delay =
  42. Math.max(OutputCacheManager.CACHE_AGE + oldestTimestamp - Date.now(), 0) +
  43. 60 * 1000
  44. setTimeout(async function () {
  45. const oldestTimestamp = await runBulkCleanup()
  46. scheduleBulkCleanup(oldestTimestamp)
  47. }, delay)
  48. }
  49. async function fillCache() {
  50. const handle = await fs.promises.opendir(Settings.path.outputDir)
  51. try {
  52. for await (const { name: projectIdAndUserId } of handle) {
  53. OLDEST_BUILD_DIR.set(
  54. Path.join(Settings.path.outputDir, projectIdAndUserId),
  55. // Queue them for cleanup in the next hour.
  56. Date.now() - Math.random() * OutputCacheManager.CACHE_AGE
  57. )
  58. }
  59. } finally {
  60. try {
  61. await handle.close()
  62. } catch (e) {}
  63. }
  64. }
  65. async function runBulkCleanup() {
  66. const cleanupThreshold = Date.now() - OutputCacheManager.CACHE_AGE
  67. let oldestTimestamp = Date.now()
  68. for (const [dir, timeStamp] of OLDEST_BUILD_DIR.entries()) {
  69. if (timeStamp < cleanupThreshold) {
  70. await cleanupDirectory(dir, { limit: OutputCacheManager.CACHE_LIMIT })
  71. } else if (timeStamp < oldestTimestamp) {
  72. oldestTimestamp = timeStamp
  73. }
  74. }
  75. return oldestTimestamp
  76. }
  77. async function cleanupDirectory(dir, options) {
  78. return queueDirOperation(dir, async () => {
  79. try {
  80. await OutputCacheManager.promises.expireOutputFiles(dir, options)
  81. } catch (err) {
  82. logger.err({ dir, err }, 'cleanup of output directory failed')
  83. }
  84. })
  85. }
  86. async function queueDirOperation(dir, fn) {
  87. const pending = PENDING_PROJECT_ACTIONS.get(dir) || Promise.resolve()
  88. const p = pending.then(fn, fn).finally(() => {
  89. if (PENDING_PROJECT_ACTIONS.get(dir) === p) {
  90. PENDING_PROJECT_ACTIONS.delete(dir)
  91. }
  92. })
  93. PENDING_PROJECT_ACTIONS.set(dir, p)
  94. return p
  95. }
  96. module.exports = OutputCacheManager = {
  97. CONTENT_SUBDIR: 'content',
  98. CACHE_SUBDIR: 'generated-files',
  99. ARCHIVE_SUBDIR: 'archived-logs',
  100. // build id is HEXDATE-HEXRANDOM from Date.now()and RandomBytes
  101. // for backwards compatibility, make the randombytes part optional
  102. BUILD_REGEX: /^[0-9a-f]+(-[0-9a-f]+)?$/,
  103. CONTENT_REGEX: /^[0-9a-f]+(-[0-9a-f]+)?$/,
  104. CACHE_LIMIT: 2, // maximum number of cache directories
  105. CACHE_AGE: 60 * 60 * 1000, // up to one hour old
  106. init,
  107. queueDirOperation: callbackify(queueDirOperation),
  108. path(buildId, file) {
  109. // used by static server, given build id return '.cache/clsi/buildId'
  110. if (buildId.match(OutputCacheManager.BUILD_REGEX)) {
  111. return Path.join(OutputCacheManager.CACHE_SUBDIR, buildId, file)
  112. } else {
  113. // for invalid build id, return top level
  114. return file
  115. }
  116. },
  117. generateBuildId(callback) {
  118. // generate a secure build id from Date.now() and 8 random bytes in hex
  119. if (callback == null) {
  120. callback = function () {}
  121. }
  122. return crypto.randomBytes(8, function (err, buf) {
  123. if (err != null) {
  124. return callback(err)
  125. }
  126. const random = buf.toString('hex')
  127. const date = Date.now().toString(16)
  128. return callback(err, `${date}-${random}`)
  129. })
  130. },
  131. saveOutputFiles(
  132. { request, stats, timings },
  133. outputFiles,
  134. compileDir,
  135. outputDir,
  136. callback
  137. ) {
  138. if (callback == null) {
  139. callback = function () {}
  140. }
  141. return OutputCacheManager.generateBuildId(function (err, buildId) {
  142. if (err != null) {
  143. return callback(err)
  144. }
  145. if (!OLDEST_BUILD_DIR.has(outputDir)) {
  146. // Register for cleanup
  147. OLDEST_BUILD_DIR.set(outputDir, Date.now())
  148. }
  149. OutputCacheManager.queueDirOperation(
  150. outputDir,
  151. () =>
  152. OutputCacheManager.promises.saveOutputFilesInBuildDir(
  153. outputFiles,
  154. compileDir,
  155. outputDir,
  156. buildId
  157. ),
  158. function (err, result) {
  159. if (err != null) {
  160. return callback(err)
  161. }
  162. OutputCacheManager.collectOutputPdfSize(
  163. result,
  164. outputDir,
  165. stats,
  166. (err, outputFiles) => {
  167. if (err) return callback(err, outputFiles)
  168. const enablePdfCaching = request.enablePdfCaching
  169. const enablePdfCachingDark =
  170. Settings.enablePdfCachingDark && !request.enablePdfCaching
  171. if (
  172. !Settings.enablePdfCaching ||
  173. (!enablePdfCaching && !enablePdfCachingDark)
  174. ) {
  175. return callback(null, outputFiles)
  176. }
  177. OutputCacheManager.saveStreamsInContentDir(
  178. { request, stats, timings, enablePdfCachingDark },
  179. outputFiles,
  180. compileDir,
  181. outputDir,
  182. err => {
  183. if (err) {
  184. logger.warn(
  185. { err, outputDir, stats, timings },
  186. 'pdf caching failed'
  187. )
  188. return callback(null, outputFiles)
  189. }
  190. callback(err, outputFiles)
  191. }
  192. )
  193. }
  194. )
  195. }
  196. )
  197. })
  198. },
  199. saveOutputFilesInBuildDir(
  200. outputFiles,
  201. compileDir,
  202. outputDir,
  203. buildId,
  204. callback
  205. ) {
  206. // make a compileDir/CACHE_SUBDIR/build_id directory and
  207. // copy all the output files into it
  208. if (callback == null) {
  209. callback = function () {}
  210. }
  211. // Put the files into a new cache subdirectory
  212. const cacheDir = Path.join(
  213. outputDir,
  214. OutputCacheManager.CACHE_SUBDIR,
  215. buildId
  216. )
  217. // Is it a per-user compile? check if compile directory is PROJECTID-USERID
  218. const perUser = Path.basename(compileDir).match(
  219. /^[0-9a-f]{24}-[0-9a-f]{24}$/
  220. )
  221. // Archive logs in background
  222. if (
  223. (Settings.clsi != null ? Settings.clsi.archive_logs : undefined) ||
  224. (Settings.clsi != null ? Settings.clsi.strace : undefined)
  225. ) {
  226. OutputCacheManager.archiveLogs(
  227. outputFiles,
  228. compileDir,
  229. outputDir,
  230. buildId,
  231. function (err) {
  232. if (err != null) {
  233. return logger.warn({ err }, 'erroring archiving log files')
  234. }
  235. }
  236. )
  237. }
  238. // make the new cache directory
  239. return fse.ensureDir(cacheDir, function (err) {
  240. if (err != null) {
  241. logger.error(
  242. { err, directory: cacheDir },
  243. 'error creating cache directory'
  244. )
  245. return callback(err, outputFiles)
  246. } else {
  247. // copy all the output files into the new cache directory
  248. const results = []
  249. return async.mapSeries(
  250. outputFiles,
  251. function (file, cb) {
  252. // don't send dot files as output, express doesn't serve them
  253. if (OutputCacheManager._fileIsHidden(file.path)) {
  254. logger.debug(
  255. { compileDir, path: file.path },
  256. 'ignoring dotfile in output'
  257. )
  258. return cb()
  259. }
  260. // copy other files into cache directory if valid
  261. const newFile = _.clone(file)
  262. const [src, dst] = Array.from([
  263. Path.join(compileDir, file.path),
  264. Path.join(cacheDir, file.path),
  265. ])
  266. return OutputCacheManager._checkFileIsSafe(
  267. src,
  268. function (err, isSafe) {
  269. if (err != null) {
  270. return cb(err)
  271. }
  272. if (!isSafe) {
  273. return cb()
  274. }
  275. return OutputCacheManager._checkIfShouldCopy(
  276. src,
  277. function (err, shouldCopy) {
  278. if (err != null) {
  279. return cb(err)
  280. }
  281. if (!shouldCopy) {
  282. return cb()
  283. }
  284. return OutputCacheManager._copyFile(
  285. src,
  286. dst,
  287. function (err) {
  288. if (err != null) {
  289. return cb(err)
  290. }
  291. newFile.build = buildId // attach a build id if we cached the file
  292. results.push(newFile)
  293. return cb()
  294. }
  295. )
  296. }
  297. )
  298. }
  299. )
  300. },
  301. function (err) {
  302. if (err != null) {
  303. // pass back the original files if we encountered *any* error
  304. callback(err, outputFiles)
  305. // clean up the directory we just created
  306. return fse.remove(cacheDir, function (err) {
  307. if (err != null) {
  308. return logger.error(
  309. { err, dir: cacheDir },
  310. 'error removing cache dir after failure'
  311. )
  312. }
  313. })
  314. } else {
  315. // pass back the list of new files in the cache
  316. callback(err, results)
  317. // let file expiry run in the background, expire all previous files if per-user
  318. cleanupDirectory(outputDir, {
  319. keep: buildId,
  320. limit: perUser ? 1 : null,
  321. }).catch(() => {})
  322. }
  323. }
  324. )
  325. }
  326. })
  327. },
  328. collectOutputPdfSize(outputFiles, outputDir, stats, callback) {
  329. const outputFile = outputFiles.find(x => x.path === 'output.pdf')
  330. if (!outputFile) return callback(null, outputFiles)
  331. const outputFilePath = Path.join(
  332. outputDir,
  333. OutputCacheManager.path(outputFile.build, outputFile.path)
  334. )
  335. fs.stat(outputFilePath, (err, stat) => {
  336. if (err) return callback(err, outputFiles)
  337. outputFile.size = stat.size
  338. stats['pdf-size'] = outputFile.size
  339. callback(null, outputFiles)
  340. })
  341. },
  342. saveStreamsInContentDir(
  343. { request, stats, timings, enablePdfCachingDark },
  344. outputFiles,
  345. compileDir,
  346. outputDir,
  347. callback
  348. ) {
  349. const cacheRoot = Path.join(outputDir, OutputCacheManager.CONTENT_SUBDIR)
  350. // check if content dir exists
  351. OutputCacheManager.ensureContentDir(cacheRoot, function (err, contentDir) {
  352. if (err) return callback(err)
  353. const outputFile = outputFiles.find(x => x.path === 'output.pdf')
  354. if (outputFile) {
  355. // possibly we should copy the file from the build dir here
  356. const outputFilePath = Path.join(
  357. outputDir,
  358. OutputCacheManager.path(outputFile.build, outputFile.path)
  359. )
  360. const pdfSize = outputFile.size
  361. const timer = new Metrics.Timer(
  362. 'compute-pdf-ranges',
  363. 1,
  364. request.metricsOpts
  365. )
  366. ContentCacheManager.update(
  367. contentDir,
  368. outputFilePath,
  369. pdfSize,
  370. timings.compile,
  371. function (err, result) {
  372. if (err && err instanceof QueueLimitReachedError) {
  373. logger.warn({ err, outputDir }, 'pdf caching queue limit reached')
  374. stats['pdf-caching-queue-limit-reached'] = 1
  375. return callback(null)
  376. }
  377. if (err && err instanceof TimedOutError) {
  378. logger.warn(
  379. { err, outputDir, stats, timings },
  380. 'pdf caching timed out'
  381. )
  382. stats['pdf-caching-timed-out'] = 1
  383. return callback(null)
  384. }
  385. if (err) return callback(err)
  386. const [
  387. contentRanges,
  388. newContentRanges,
  389. reclaimedSpace,
  390. startXRefTable,
  391. ] = result
  392. if (enablePdfCachingDark) {
  393. // In dark mode we are doing the computation only and do not emit
  394. // any ranges to the frontend.
  395. } else {
  396. outputFile.contentId = Path.basename(contentDir)
  397. outputFile.ranges = contentRanges
  398. outputFile.startXRefTable = startXRefTable
  399. }
  400. timings['compute-pdf-caching'] = timer.done()
  401. stats['pdf-caching-n-ranges'] = contentRanges.length
  402. stats['pdf-caching-total-ranges-size'] = contentRanges.reduce(
  403. (sum, next) => sum + (next.end - next.start),
  404. 0
  405. )
  406. stats['pdf-caching-n-new-ranges'] = newContentRanges.length
  407. stats['pdf-caching-new-ranges-size'] = newContentRanges.reduce(
  408. (sum, next) => sum + (next.end - next.start),
  409. 0
  410. )
  411. stats['pdf-caching-reclaimed-space'] = reclaimedSpace
  412. callback(null)
  413. }
  414. )
  415. } else {
  416. callback(null)
  417. }
  418. })
  419. },
  420. ensureContentDir(contentRoot, callback) {
  421. fse.ensureDir(contentRoot, function (err) {
  422. if (err != null) {
  423. return callback(err)
  424. }
  425. fs.readdir(contentRoot, function (err, results) {
  426. if (err) return callback(err)
  427. const dirs = results.sort()
  428. const contentId = dirs.find(dir =>
  429. OutputCacheManager.BUILD_REGEX.test(dir)
  430. )
  431. if (contentId) {
  432. callback(null, Path.join(contentRoot, contentId))
  433. } else {
  434. // make a content directory
  435. OutputCacheManager.generateBuildId(function (err, contentId) {
  436. if (err) {
  437. return callback(err)
  438. }
  439. const contentDir = Path.join(contentRoot, contentId)
  440. fse.ensureDir(contentDir, function (err) {
  441. if (err) {
  442. return callback(err)
  443. }
  444. return callback(null, contentDir)
  445. })
  446. })
  447. }
  448. })
  449. })
  450. },
  451. archiveLogs(outputFiles, compileDir, outputDir, buildId, callback) {
  452. if (callback == null) {
  453. callback = function () {}
  454. }
  455. const archiveDir = Path.join(
  456. outputDir,
  457. OutputCacheManager.ARCHIVE_SUBDIR,
  458. buildId
  459. )
  460. logger.debug({ dir: archiveDir }, 'archiving log files for project')
  461. return fse.ensureDir(archiveDir, function (err) {
  462. if (err != null) {
  463. return callback(err)
  464. }
  465. return async.mapSeries(
  466. outputFiles,
  467. function (file, cb) {
  468. const [src, dst] = Array.from([
  469. Path.join(compileDir, file.path),
  470. Path.join(archiveDir, file.path),
  471. ])
  472. return OutputCacheManager._checkFileIsSafe(
  473. src,
  474. function (err, isSafe) {
  475. if (err != null) {
  476. return cb(err)
  477. }
  478. if (!isSafe) {
  479. return cb()
  480. }
  481. return OutputCacheManager._checkIfShouldArchive(
  482. src,
  483. function (err, shouldArchive) {
  484. if (err != null) {
  485. return cb(err)
  486. }
  487. if (!shouldArchive) {
  488. return cb()
  489. }
  490. return OutputCacheManager._copyFile(src, dst, cb)
  491. }
  492. )
  493. }
  494. )
  495. },
  496. callback
  497. )
  498. })
  499. },
  500. expireOutputFiles(outputDir, options, callback) {
  501. // look in compileDir for build dirs and delete if > N or age of mod time > T
  502. if (callback == null) {
  503. callback = function () {}
  504. }
  505. const cleanupAll = cb => {
  506. fse.remove(outputDir, err => {
  507. if (err) {
  508. return cb(err)
  509. }
  510. // Drop reference after successful cleanup of the output dir.
  511. OLDEST_BUILD_DIR.delete(outputDir)
  512. cb(null)
  513. })
  514. }
  515. const cacheRoot = Path.join(outputDir, OutputCacheManager.CACHE_SUBDIR)
  516. return fs.readdir(cacheRoot, function (err, results) {
  517. if (err != null) {
  518. if (err.code === 'ENOENT') {
  519. // cache directory is empty
  520. return cleanupAll(callback)
  521. }
  522. logger.error({ err, project_id: cacheRoot }, 'error clearing cache')
  523. return callback(err)
  524. }
  525. const dirs = results.sort().reverse()
  526. const currentTime = Date.now()
  527. let oldestDirTimeToKeep = 0
  528. const isExpired = function (dir, index) {
  529. if ((options != null ? options.keep : undefined) === dir) {
  530. // This is the directory we just created for the compile request.
  531. oldestDirTimeToKeep = currentTime
  532. return false
  533. }
  534. // remove any directories over the requested (non-null) limit
  535. if (
  536. (options != null ? options.limit : undefined) != null &&
  537. index > options.limit
  538. ) {
  539. return true
  540. }
  541. // remove any directories over the hard limit
  542. if (index > OutputCacheManager.CACHE_LIMIT) {
  543. return true
  544. }
  545. // we can get the build time from the first part of the directory name DDDD-RRRR
  546. // DDDD is date and RRRR is random bytes
  547. const dirTime = parseInt(
  548. __guard__(dir.split('-'), x => x[0]),
  549. 16
  550. )
  551. const age = currentTime - dirTime
  552. const expired = age > OutputCacheManager.CACHE_AGE
  553. if (expired) {
  554. return true
  555. }
  556. oldestDirTimeToKeep = dirTime
  557. return false
  558. }
  559. const toRemove = _.filter(dirs, isExpired)
  560. if (toRemove.length === dirs.length) {
  561. // No builds left after cleanup.
  562. return cleanupAll(callback)
  563. }
  564. const removeDir = (dir, cb) =>
  565. fse.remove(Path.join(cacheRoot, dir), function (err, result) {
  566. logger.debug({ cache: cacheRoot, dir }, 'removed expired cache dir')
  567. if (err != null) {
  568. logger.error({ err, dir }, 'cache remove error')
  569. }
  570. return cb(err, result)
  571. })
  572. return async.eachSeries(
  573. toRemove,
  574. (dir, cb) => removeDir(dir, cb),
  575. err => {
  576. if (err) {
  577. // On error: keep the timestamp in the past.
  578. // The next iteration of the cleanup loop will retry the deletion.
  579. return callback(err)
  580. }
  581. // On success: push the timestamp into the future.
  582. OLDEST_BUILD_DIR.set(outputDir, oldestDirTimeToKeep)
  583. callback(null)
  584. }
  585. )
  586. })
  587. },
  588. _fileIsHidden(path) {
  589. return (path != null ? path.match(/^\.|\/\./) : undefined) != null
  590. },
  591. _checkFileIsSafe(src, callback) {
  592. // check if we have a valid file to copy into the cache
  593. if (callback == null) {
  594. callback = function () {}
  595. }
  596. return fs.stat(src, function (err, stats) {
  597. if ((err != null ? err.code : undefined) === 'ENOENT') {
  598. logger.warn(
  599. { err, file: src },
  600. 'file has disappeared before copying to build cache'
  601. )
  602. return callback(err, false)
  603. } else if (err != null) {
  604. // some other problem reading the file
  605. logger.error({ err, file: src }, 'stat error for file in cache')
  606. return callback(err, false)
  607. } else if (!stats.isFile()) {
  608. // other filetype - reject it
  609. logger.warn(
  610. { src, stat: stats },
  611. 'nonfile output - refusing to copy to cache'
  612. )
  613. return callback(null, false)
  614. } else {
  615. // it's a plain file, ok to copy
  616. return callback(null, true)
  617. }
  618. })
  619. },
  620. _copyFile(src, dst, callback) {
  621. // copy output file into the cache
  622. return fse.copy(src, dst, function (err) {
  623. if ((err != null ? err.code : undefined) === 'ENOENT') {
  624. logger.warn(
  625. { err, file: src },
  626. 'file has disappeared when copying to build cache'
  627. )
  628. return callback(err, false)
  629. } else if (err != null) {
  630. logger.error({ err, src, dst }, 'copy error for file in cache')
  631. return callback(err)
  632. } else {
  633. if (
  634. Settings.clsi != null ? Settings.clsi.optimiseInDocker : undefined
  635. ) {
  636. // don't run any optimisations on the pdf when they are done
  637. // in the docker container
  638. return callback()
  639. } else {
  640. // call the optimiser for the file too
  641. return OutputFileOptimiser.optimiseFile(src, dst, callback)
  642. }
  643. }
  644. })
  645. },
  646. _checkIfShouldCopy(src, callback) {
  647. if (callback == null) {
  648. callback = function () {}
  649. }
  650. return callback(null, !Path.basename(src).match(/^strace/))
  651. },
  652. _checkIfShouldArchive(src, callback) {
  653. let needle
  654. if (callback == null) {
  655. callback = function () {}
  656. }
  657. if (Path.basename(src).match(/^strace/)) {
  658. return callback(null, true)
  659. }
  660. if (
  661. (Settings.clsi != null ? Settings.clsi.archive_logs : undefined) &&
  662. ((needle = Path.basename(src)),
  663. ['output.log', 'output.blg'].includes(needle))
  664. ) {
  665. return callback(null, true)
  666. }
  667. return callback(null, false)
  668. },
  669. }
  670. function __guard__(value, transform) {
  671. return typeof value !== 'undefined' && value !== null
  672. ? transform(value)
  673. : undefined
  674. }
  675. OutputCacheManager.promises = {
  676. expireOutputFiles: promisify(OutputCacheManager.expireOutputFiles),
  677. saveOutputFiles: promisify(OutputCacheManager.saveOutputFiles),
  678. saveOutputFilesInBuildDir: promisify(
  679. OutputCacheManager.saveOutputFilesInBuildDir
  680. ),
  681. }