Sfoglia il codice sorgente

add glob matching to isExtraneousFile (#34633)

GitOrigin-RevId: f12aedb52195cfc9e3254936f1db6189f49c3f37
Brian Gough 1 mese fa
parent
commit
be4108a573

+ 10 - 0
services/clsi/app/js/ResourceWriter.js

@@ -23,9 +23,15 @@ import Metrics from '@overleaf/metrics'
 import logger from '@overleaf/logger'
 import settings from '@overleaf/settings'
 import ClsiMetrics from './Metrics.js'
+import { Minimatch } from 'minimatch'
 
 const { shouldSkipMetrics } = ClsiMetrics
 
+// Additional file patterns to keep between compiles
+const preciousFileMatcher = new Minimatch(settings.preciousFilePattern, {
+  dot: true,
+})
+
 let ResourceWriter
 
 const parallelFileDownloads = settings.parallelFileDownloads || 1
@@ -265,6 +271,10 @@ export default ResourceWriter = {
       // Epstopdf generated files
       shouldDelete = false
     }
+    // Keep additional precious files and directories
+    if (shouldDelete && preciousFileMatcher.match(path)) {
+      shouldDelete = false
+    }
     if (
       path === 'output.tar.gz' ||
       path === 'output.synctex.gz' ||

+ 1 - 0
services/clsi/config/settings.defaults.cjs

@@ -35,6 +35,7 @@ module.exports = {
     process.env.PDFTOCAIRO_IMAGE || 'quay.io/sharelatex/pdftocairo:24.02',
   enablePdfConversions: process.env.ENABLE_PDF_CONVERSIONS === 'true',
   maxUploadSize: 50 * 1024 * 1024,
+  preciousFilePattern: process.env.PRECIOUS_FILE_PATTERN || '',
 
   internal: {
     clsi: {

+ 1 - 0
services/clsi/package.json

@@ -31,6 +31,7 @@
     "dockerode": "^4.0.9",
     "express": "4.22.1",
     "lodash": "^4.18.1",
+    "minimatch": "^10.2.5",
     "multer": "2.1.1",
     "overleaf-editor-core": "workspace:*",
     "p-limit": "^3.1.0",

+ 24 - 0
services/clsi/test/unit/js/ResourceWriter.test.js

@@ -19,6 +19,12 @@ describe('ResourceWriter', () => {
       }),
     }))
 
+    vi.doMock('@overleaf/settings', () => ({
+      default: (ctx.settings = {
+        preciousFilePattern: '{keepdir/**,.other/keepdir/**}',
+      }),
+    }))
+
     vi.doMock('../../../app/js/ResourceStateManager', () => ({
       default: (ctx.ResourceStateManager = {}),
     }))
@@ -246,6 +252,12 @@ describe('ResourceWriter', () => {
         {
           path: 'output.stderr',
         },
+        {
+          path: 'keepdir/file',
+        },
+        {
+          path: '.other/keepdir/.subdir/file',
+        },
       ]
       ctx.resources = 'mock-resources'
       ctx.request = {
@@ -297,6 +309,18 @@ describe('ResourceWriter', () => {
         .should.equal(true)
     })
 
+    it('should not delete additionally specified files', ctx => {
+      return ctx.ResourceWriter._deleteFileIfNotDirectory
+        .calledWith(path.join(ctx.basePath, 'keepdir/file'))
+        .should.equal(false)
+    })
+
+    it('should not delete additionally specified hidden files', ctx => {
+      return ctx.ResourceWriter._deleteFileIfNotDirectory
+        .calledWith(path.join(ctx.basePath, '.other/keepdir/.subdir/file'))
+        .should.equal(false)
+    })
+
     it('should not delete the extra aux files', ctx => {
       return ctx.ResourceWriter._deleteFileIfNotDirectory
         .calledWith(path.join(ctx.basePath, 'extra.aux'))

+ 2 - 1
yarn.lock

@@ -6531,6 +6531,7 @@ __metadata:
     express: "npm:4.22.1"
     form-data: "npm:^4.0.5"
     lodash: "npm:^4.18.1"
+    minimatch: "npm:^10.2.5"
     mocha: "npm:^11.1.0"
     mocha-junit-reporter: "npm:^2.2.1"
     mocha-multi-reporters: "npm:^1.5.1"
@@ -24476,7 +24477,7 @@ __metadata:
   languageName: node
   linkType: hard
 
-"minimatch@npm:^10.1.1, minimatch@npm:^10.2.1, minimatch@npm:^10.2.2, minimatch@npm:^10.2.4":
+"minimatch@npm:^10.1.1, minimatch@npm:^10.2.1, minimatch@npm:^10.2.2, minimatch@npm:^10.2.4, minimatch@npm:^10.2.5":
   version: 10.2.5
   resolution: "minimatch@npm:10.2.5"
   dependencies: