OutputCacheManager.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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, status) => {
  183. Metrics.inc('pdf-caching-status', 1, {
  184. status,
  185. ...request.metricsOpts,
  186. })
  187. if (err) {
  188. logger.warn(
  189. { err, outputDir, stats, timings },
  190. 'pdf caching failed'
  191. )
  192. return callback(null, outputFiles)
  193. }
  194. callback(err, outputFiles)
  195. }
  196. )
  197. }
  198. )
  199. }
  200. )
  201. })
  202. },
  203. saveOutputFilesInBuildDir(
  204. outputFiles,
  205. compileDir,
  206. outputDir,
  207. buildId,
  208. callback
  209. ) {
  210. // make a compileDir/CACHE_SUBDIR/build_id directory and
  211. // copy all the output files into it
  212. if (callback == null) {
  213. callback = function () {}
  214. }
  215. // Put the files into a new cache subdirectory
  216. const cacheDir = Path.join(
  217. outputDir,
  218. OutputCacheManager.CACHE_SUBDIR,
  219. buildId
  220. )
  221. // Is it a per-user compile? check if compile directory is PROJECTID-USERID
  222. const perUser = Path.basename(compileDir).match(
  223. /^[0-9a-f]{24}-[0-9a-f]{24}$/
  224. )
  225. // Archive logs in background
  226. if (
  227. (Settings.clsi != null ? Settings.clsi.archive_logs : undefined) ||
  228. (Settings.clsi != null ? Settings.clsi.strace : undefined)
  229. ) {
  230. OutputCacheManager.archiveLogs(
  231. outputFiles,
  232. compileDir,
  233. outputDir,
  234. buildId,
  235. function (err) {
  236. if (err != null) {
  237. return logger.warn({ err }, 'erroring archiving log files')
  238. }
  239. }
  240. )
  241. }
  242. // make the new cache directory
  243. return fse.ensureDir(cacheDir, function (err) {
  244. if (err != null) {
  245. logger.error(
  246. { err, directory: cacheDir },
  247. 'error creating cache directory'
  248. )
  249. return callback(err, outputFiles)
  250. } else {
  251. // copy all the output files into the new cache directory
  252. const results = []
  253. return async.mapSeries(
  254. outputFiles,
  255. function (file, cb) {
  256. // don't send dot files as output, express doesn't serve them
  257. if (OutputCacheManager._fileIsHidden(file.path)) {
  258. logger.debug(
  259. { compileDir, path: file.path },
  260. 'ignoring dotfile in output'
  261. )
  262. return cb()
  263. }
  264. // copy other files into cache directory if valid
  265. const newFile = _.clone(file)
  266. const [src, dst] = Array.from([
  267. Path.join(compileDir, file.path),
  268. Path.join(cacheDir, file.path),
  269. ])
  270. return OutputCacheManager._checkFileIsSafe(
  271. src,
  272. function (err, isSafe) {
  273. if (err != null) {
  274. return cb(err)
  275. }
  276. if (!isSafe) {
  277. return cb()
  278. }
  279. return OutputCacheManager._checkIfShouldCopy(
  280. src,
  281. function (err, shouldCopy) {
  282. if (err != null) {
  283. return cb(err)
  284. }
  285. if (!shouldCopy) {
  286. return cb()
  287. }
  288. return OutputCacheManager._copyFile(
  289. src,
  290. dst,
  291. function (err) {
  292. if (err != null) {
  293. return cb(err)
  294. }
  295. newFile.build = buildId // attach a build id if we cached the file
  296. results.push(newFile)
  297. return cb()
  298. }
  299. )
  300. }
  301. )
  302. }
  303. )
  304. },
  305. function (err) {
  306. if (err != null) {
  307. // pass back the original files if we encountered *any* error
  308. callback(err, outputFiles)
  309. // clean up the directory we just created
  310. return fse.remove(cacheDir, function (err) {
  311. if (err != null) {
  312. return logger.error(
  313. { err, dir: cacheDir },
  314. 'error removing cache dir after failure'
  315. )
  316. }
  317. })
  318. } else {
  319. // pass back the list of new files in the cache
  320. callback(err, results)
  321. // let file expiry run in the background, expire all previous files if per-user
  322. cleanupDirectory(outputDir, {
  323. keep: buildId,
  324. limit: perUser ? 1 : null,
  325. }).catch(() => {})
  326. }
  327. }
  328. )
  329. }
  330. })
  331. },
  332. collectOutputPdfSize(outputFiles, outputDir, stats, callback) {
  333. const outputFile = outputFiles.find(x => x.path === 'output.pdf')
  334. if (!outputFile) return callback(null, outputFiles)
  335. const outputFilePath = Path.join(
  336. outputDir,
  337. OutputCacheManager.path(outputFile.build, outputFile.path)
  338. )
  339. fs.stat(outputFilePath, (err, stat) => {
  340. if (err) return callback(err, outputFiles)
  341. outputFile.size = stat.size
  342. stats['pdf-size'] = outputFile.size
  343. callback(null, outputFiles)
  344. })
  345. },
  346. saveStreamsInContentDir(
  347. { request, stats, timings, enablePdfCachingDark },
  348. outputFiles,
  349. compileDir,
  350. outputDir,
  351. callback
  352. ) {
  353. const cacheRoot = Path.join(outputDir, OutputCacheManager.CONTENT_SUBDIR)
  354. // check if content dir exists
  355. OutputCacheManager.ensureContentDir(cacheRoot, function (err, contentDir) {
  356. if (err) return callback(err, 'content-dir-unavailable')
  357. const outputFile = outputFiles.find(x => x.path === 'output.pdf')
  358. if (outputFile) {
  359. // possibly we should copy the file from the build dir here
  360. const outputFilePath = Path.join(
  361. outputDir,
  362. OutputCacheManager.path(outputFile.build, outputFile.path)
  363. )
  364. const pdfSize = outputFile.size
  365. const timer = new Metrics.Timer(
  366. 'compute-pdf-ranges',
  367. 1,
  368. request.metricsOpts
  369. )
  370. ContentCacheManager.update(
  371. contentDir,
  372. outputFilePath,
  373. pdfSize,
  374. timings.compile,
  375. function (err, result) {
  376. if (err && err instanceof QueueLimitReachedError) {
  377. logger.warn({ err, outputDir }, 'pdf caching queue limit reached')
  378. stats['pdf-caching-queue-limit-reached'] = 1
  379. return callback(null, 'queue-limit')
  380. }
  381. if (err && err instanceof TimedOutError) {
  382. logger.warn(
  383. { err, outputDir, stats, timings },
  384. 'pdf caching timed out'
  385. )
  386. stats['pdf-caching-timed-out'] = 1
  387. return callback(null, 'timed-out')
  388. }
  389. if (err) return callback(err, 'failed')
  390. const {
  391. contentRanges,
  392. newContentRanges,
  393. reclaimedSpace,
  394. startXRefTable,
  395. } = result
  396. if (enablePdfCachingDark) {
  397. // In dark mode we are doing the computation only and do not emit
  398. // any ranges to the frontend.
  399. } else {
  400. outputFile.contentId = Path.basename(contentDir)
  401. outputFile.ranges = contentRanges
  402. outputFile.startXRefTable = startXRefTable
  403. }
  404. timings['compute-pdf-caching'] = timer.done()
  405. stats['pdf-caching-n-ranges'] = contentRanges.length
  406. stats['pdf-caching-total-ranges-size'] = contentRanges.reduce(
  407. (sum, next) => sum + (next.end - next.start),
  408. 0
  409. )
  410. stats['pdf-caching-n-new-ranges'] = newContentRanges.length
  411. stats['pdf-caching-new-ranges-size'] = newContentRanges.reduce(
  412. (sum, next) => sum + (next.end - next.start),
  413. 0
  414. )
  415. stats['pdf-caching-reclaimed-space'] = reclaimedSpace
  416. callback(null, 'success')
  417. }
  418. )
  419. } else {
  420. callback(null, 'missing-pdf')
  421. }
  422. })
  423. },
  424. ensureContentDir(contentRoot, callback) {
  425. fse.ensureDir(contentRoot, function (err) {
  426. if (err != null) {
  427. return callback(err)
  428. }
  429. fs.readdir(contentRoot, function (err, results) {
  430. if (err) return callback(err)
  431. const dirs = results.sort()
  432. const contentId = dirs.find(dir =>
  433. OutputCacheManager.BUILD_REGEX.test(dir)
  434. )
  435. if (contentId) {
  436. callback(null, Path.join(contentRoot, contentId))
  437. } else {
  438. // make a content directory
  439. OutputCacheManager.generateBuildId(function (err, contentId) {
  440. if (err) {
  441. return callback(err)
  442. }
  443. const contentDir = Path.join(contentRoot, contentId)
  444. fse.ensureDir(contentDir, function (err) {
  445. if (err) {
  446. return callback(err)
  447. }
  448. return callback(null, contentDir)
  449. })
  450. })
  451. }
  452. })
  453. })
  454. },
  455. archiveLogs(outputFiles, compileDir, outputDir, buildId, callback) {
  456. if (callback == null) {
  457. callback = function () {}
  458. }
  459. const archiveDir = Path.join(
  460. outputDir,
  461. OutputCacheManager.ARCHIVE_SUBDIR,
  462. buildId
  463. )
  464. logger.debug({ dir: archiveDir }, 'archiving log files for project')
  465. return fse.ensureDir(archiveDir, function (err) {
  466. if (err != null) {
  467. return callback(err)
  468. }
  469. return async.mapSeries(
  470. outputFiles,
  471. function (file, cb) {
  472. const [src, dst] = Array.from([
  473. Path.join(compileDir, file.path),
  474. Path.join(archiveDir, file.path),
  475. ])
  476. return OutputCacheManager._checkFileIsSafe(
  477. src,
  478. function (err, isSafe) {
  479. if (err != null) {
  480. return cb(err)
  481. }
  482. if (!isSafe) {
  483. return cb()
  484. }
  485. return OutputCacheManager._checkIfShouldArchive(
  486. src,
  487. function (err, shouldArchive) {
  488. if (err != null) {
  489. return cb(err)
  490. }
  491. if (!shouldArchive) {
  492. return cb()
  493. }
  494. return OutputCacheManager._copyFile(src, dst, cb)
  495. }
  496. )
  497. }
  498. )
  499. },
  500. callback
  501. )
  502. })
  503. },
  504. expireOutputFiles(outputDir, options, callback) {
  505. // look in compileDir for build dirs and delete if > N or age of mod time > T
  506. if (callback == null) {
  507. callback = function () {}
  508. }
  509. const cleanupAll = cb => {
  510. fse.remove(outputDir, err => {
  511. if (err) {
  512. return cb(err)
  513. }
  514. // Drop reference after successful cleanup of the output dir.
  515. OLDEST_BUILD_DIR.delete(outputDir)
  516. cb(null)
  517. })
  518. }
  519. const cacheRoot = Path.join(outputDir, OutputCacheManager.CACHE_SUBDIR)
  520. return fs.readdir(cacheRoot, function (err, results) {
  521. if (err != null) {
  522. if (err.code === 'ENOENT') {
  523. // cache directory is empty
  524. return cleanupAll(callback)
  525. }
  526. logger.error({ err, project_id: cacheRoot }, 'error clearing cache')
  527. return callback(err)
  528. }
  529. const dirs = results.sort().reverse()
  530. const currentTime = Date.now()
  531. let oldestDirTimeToKeep = 0
  532. const isExpired = function (dir, index) {
  533. if ((options != null ? options.keep : undefined) === dir) {
  534. // This is the directory we just created for the compile request.
  535. oldestDirTimeToKeep = currentTime
  536. return false
  537. }
  538. // remove any directories over the requested (non-null) limit
  539. if (
  540. (options != null ? options.limit : undefined) != null &&
  541. index > options.limit
  542. ) {
  543. return true
  544. }
  545. // remove any directories over the hard limit
  546. if (index > OutputCacheManager.CACHE_LIMIT) {
  547. return true
  548. }
  549. // we can get the build time from the first part of the directory name DDDD-RRRR
  550. // DDDD is date and RRRR is random bytes
  551. const dirTime = parseInt(
  552. __guard__(dir.split('-'), x => x[0]),
  553. 16
  554. )
  555. const age = currentTime - dirTime
  556. const expired = age > OutputCacheManager.CACHE_AGE
  557. if (expired) {
  558. return true
  559. }
  560. oldestDirTimeToKeep = dirTime
  561. return false
  562. }
  563. const toRemove = _.filter(dirs, isExpired)
  564. if (toRemove.length === dirs.length) {
  565. // No builds left after cleanup.
  566. return cleanupAll(callback)
  567. }
  568. const removeDir = (dir, cb) =>
  569. fse.remove(Path.join(cacheRoot, dir), function (err, result) {
  570. logger.debug({ cache: cacheRoot, dir }, 'removed expired cache dir')
  571. if (err != null) {
  572. logger.error({ err, dir }, 'cache remove error')
  573. }
  574. return cb(err, result)
  575. })
  576. return async.eachSeries(
  577. toRemove,
  578. (dir, cb) => removeDir(dir, cb),
  579. err => {
  580. if (err) {
  581. // On error: keep the timestamp in the past.
  582. // The next iteration of the cleanup loop will retry the deletion.
  583. return callback(err)
  584. }
  585. // On success: push the timestamp into the future.
  586. OLDEST_BUILD_DIR.set(outputDir, oldestDirTimeToKeep)
  587. callback(null)
  588. }
  589. )
  590. })
  591. },
  592. _fileIsHidden(path) {
  593. return (path != null ? path.match(/^\.|\/\./) : undefined) != null
  594. },
  595. _checkFileIsSafe(src, callback) {
  596. // check if we have a valid file to copy into the cache
  597. if (callback == null) {
  598. callback = function () {}
  599. }
  600. return fs.stat(src, function (err, stats) {
  601. if ((err != null ? err.code : undefined) === 'ENOENT') {
  602. logger.warn(
  603. { err, file: src },
  604. 'file has disappeared before copying to build cache'
  605. )
  606. return callback(err, false)
  607. } else if (err != null) {
  608. // some other problem reading the file
  609. logger.error({ err, file: src }, 'stat error for file in cache')
  610. return callback(err, false)
  611. } else if (!stats.isFile()) {
  612. // other filetype - reject it
  613. logger.warn(
  614. { src, stat: stats },
  615. 'nonfile output - refusing to copy to cache'
  616. )
  617. return callback(null, false)
  618. } else {
  619. // it's a plain file, ok to copy
  620. return callback(null, true)
  621. }
  622. })
  623. },
  624. _copyFile(src, dst, callback) {
  625. // copy output file into the cache
  626. return fse.copy(src, dst, function (err) {
  627. if ((err != null ? err.code : undefined) === 'ENOENT') {
  628. logger.warn(
  629. { err, file: src },
  630. 'file has disappeared when copying to build cache'
  631. )
  632. return callback(err, false)
  633. } else if (err != null) {
  634. logger.error({ err, src, dst }, 'copy error for file in cache')
  635. return callback(err)
  636. } else {
  637. if (
  638. Settings.clsi != null ? Settings.clsi.optimiseInDocker : undefined
  639. ) {
  640. // don't run any optimisations on the pdf when they are done
  641. // in the docker container
  642. return callback()
  643. } else {
  644. // call the optimiser for the file too
  645. return OutputFileOptimiser.optimiseFile(src, dst, callback)
  646. }
  647. }
  648. })
  649. },
  650. _checkIfShouldCopy(src, callback) {
  651. if (callback == null) {
  652. callback = function () {}
  653. }
  654. return callback(null, !Path.basename(src).match(/^strace/))
  655. },
  656. _checkIfShouldArchive(src, callback) {
  657. let needle
  658. if (callback == null) {
  659. callback = function () {}
  660. }
  661. if (Path.basename(src).match(/^strace/)) {
  662. return callback(null, true)
  663. }
  664. if (
  665. (Settings.clsi != null ? Settings.clsi.archive_logs : undefined) &&
  666. ((needle = Path.basename(src)),
  667. ['output.log', 'output.blg'].includes(needle))
  668. ) {
  669. return callback(null, true)
  670. }
  671. return callback(null, false)
  672. },
  673. }
  674. function __guard__(value, transform) {
  675. return typeof value !== 'undefined' && value !== null
  676. ? transform(value)
  677. : undefined
  678. }
  679. OutputCacheManager.promises = {
  680. expireOutputFiles: promisify(OutputCacheManager.expireOutputFiles),
  681. saveOutputFiles: promisify(OutputCacheManager.saveOutputFiles),
  682. saveOutputFilesInBuildDir: promisify(
  683. OutputCacheManager.saveOutputFilesInBuildDir
  684. ),
  685. }