OutputCacheManager.js 22 KB

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