add glob matching to isExtraneousFile (#34633)

GitOrigin-RevId: f12aedb52195cfc9e3254936f1db6189f49c3f37
This commit is contained in:
Brian Gough
2026-06-16 08:07:09 +00:00
committed by Copybot
parent 0778a0e4d3
commit be4108a573
5 changed files with 38 additions and 1 deletions
+10
View File
@@ -23,9 +23,15 @@ import Metrics from '@overleaf/metrics'
import logger from '@overleaf/logger' import logger from '@overleaf/logger'
import settings from '@overleaf/settings' import settings from '@overleaf/settings'
import ClsiMetrics from './Metrics.js' import ClsiMetrics from './Metrics.js'
import { Minimatch } from 'minimatch'
const { shouldSkipMetrics } = ClsiMetrics const { shouldSkipMetrics } = ClsiMetrics
// Additional file patterns to keep between compiles
const preciousFileMatcher = new Minimatch(settings.preciousFilePattern, {
dot: true,
})
let ResourceWriter let ResourceWriter
const parallelFileDownloads = settings.parallelFileDownloads || 1 const parallelFileDownloads = settings.parallelFileDownloads || 1
@@ -265,6 +271,10 @@ export default ResourceWriter = {
// Epstopdf generated files // Epstopdf generated files
shouldDelete = false shouldDelete = false
} }
// Keep additional precious files and directories
if (shouldDelete && preciousFileMatcher.match(path)) {
shouldDelete = false
}
if ( if (
path === 'output.tar.gz' || path === 'output.tar.gz' ||
path === 'output.synctex.gz' || path === 'output.synctex.gz' ||
@@ -35,6 +35,7 @@ module.exports = {
process.env.PDFTOCAIRO_IMAGE || 'quay.io/sharelatex/pdftocairo:24.02', process.env.PDFTOCAIRO_IMAGE || 'quay.io/sharelatex/pdftocairo:24.02',
enablePdfConversions: process.env.ENABLE_PDF_CONVERSIONS === 'true', enablePdfConversions: process.env.ENABLE_PDF_CONVERSIONS === 'true',
maxUploadSize: 50 * 1024 * 1024, maxUploadSize: 50 * 1024 * 1024,
preciousFilePattern: process.env.PRECIOUS_FILE_PATTERN || '',
internal: { internal: {
clsi: { clsi: {
+1
View File
@@ -31,6 +31,7 @@
"dockerode": "^4.0.9", "dockerode": "^4.0.9",
"express": "4.22.1", "express": "4.22.1",
"lodash": "^4.18.1", "lodash": "^4.18.1",
"minimatch": "^10.2.5",
"multer": "2.1.1", "multer": "2.1.1",
"overleaf-editor-core": "workspace:*", "overleaf-editor-core": "workspace:*",
"p-limit": "^3.1.0", "p-limit": "^3.1.0",
@@ -19,6 +19,12 @@ describe('ResourceWriter', () => {
}), }),
})) }))
vi.doMock('@overleaf/settings', () => ({
default: (ctx.settings = {
preciousFilePattern: '{keepdir/**,.other/keepdir/**}',
}),
}))
vi.doMock('../../../app/js/ResourceStateManager', () => ({ vi.doMock('../../../app/js/ResourceStateManager', () => ({
default: (ctx.ResourceStateManager = {}), default: (ctx.ResourceStateManager = {}),
})) }))
@@ -246,6 +252,12 @@ describe('ResourceWriter', () => {
{ {
path: 'output.stderr', path: 'output.stderr',
}, },
{
path: 'keepdir/file',
},
{
path: '.other/keepdir/.subdir/file',
},
] ]
ctx.resources = 'mock-resources' ctx.resources = 'mock-resources'
ctx.request = { ctx.request = {
@@ -297,6 +309,18 @@ describe('ResourceWriter', () => {
.should.equal(true) .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 => { it('should not delete the extra aux files', ctx => {
return ctx.ResourceWriter._deleteFileIfNotDirectory return ctx.ResourceWriter._deleteFileIfNotDirectory
.calledWith(path.join(ctx.basePath, 'extra.aux')) .calledWith(path.join(ctx.basePath, 'extra.aux'))
+2 -1
View File
@@ -6531,6 +6531,7 @@ __metadata:
express: "npm:4.22.1" express: "npm:4.22.1"
form-data: "npm:^4.0.5" form-data: "npm:^4.0.5"
lodash: "npm:^4.18.1" lodash: "npm:^4.18.1"
minimatch: "npm:^10.2.5"
mocha: "npm:^11.1.0" mocha: "npm:^11.1.0"
mocha-junit-reporter: "npm:^2.2.1" mocha-junit-reporter: "npm:^2.2.1"
mocha-multi-reporters: "npm:^1.5.1" mocha-multi-reporters: "npm:^1.5.1"
@@ -24476,7 +24477,7 @@ __metadata:
languageName: node languageName: node
linkType: hard 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 version: 10.2.5
resolution: "minimatch@npm:10.2.5" resolution: "minimatch@npm:10.2.5"
dependencies: dependencies: