mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #7417 from overleaf/em-find-bad-file-trees
Script for finding malformed filetrees GitOrigin-RevId: 256f724ec61c0a88a8904f9a4c028cfc78d6d0bb
This commit is contained in:
parent
c776bf208c
commit
9c036b1d90
1 changed files with 51 additions and 0 deletions
51
services/web/scripts/find_malformed_filetrees.js
Normal file
51
services/web/scripts/find_malformed_filetrees.js
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
const { ReadPreference } = require('mongodb')
|
||||||
|
const { db, waitForDb } = require('../app/src/infrastructure/mongodb')
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
await waitForDb()
|
||||||
|
const projects = db.projects.find(
|
||||||
|
{},
|
||||||
|
{ projection: { rootFolder: 1 }, readPreference: ReadPreference.SECONDARY }
|
||||||
|
)
|
||||||
|
let projectsProcessed = 0
|
||||||
|
for await (const project of projects) {
|
||||||
|
projectsProcessed += 1
|
||||||
|
if (projectsProcessed % 100000 === 0) {
|
||||||
|
console.log(projectsProcessed, 'projects processed')
|
||||||
|
}
|
||||||
|
processProject(project)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function processProject(project) {
|
||||||
|
const badPaths = findBadPaths(project.rootFolder[0])
|
||||||
|
for (const path of badPaths) {
|
||||||
|
console.log('BAD PATH:', project._id, `rootFolder.0.${path}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function findBadPaths(folder) {
|
||||||
|
const result = []
|
||||||
|
for (const attr of ['docs', 'fileRefs', 'folders']) {
|
||||||
|
if (folder[attr] && !Array.isArray(folder[attr])) {
|
||||||
|
result.push(attr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (folder.folders && Array.isArray(folder.folders)) {
|
||||||
|
for (const [i, subfolder] of folder.folders.entries()) {
|
||||||
|
for (const badPath of findBadPaths(subfolder)) {
|
||||||
|
result.push(`folders.${i}.${badPath}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
.then(() => {
|
||||||
|
process.exit(0)
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err)
|
||||||
|
process.exit(1)
|
||||||
|
})
|
Loading…
Reference in a new issue