mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #12121 from overleaf/bg-fix-bad-offsets-in-history-migration
fix out of range offsets to avoid invalid history exports GitOrigin-RevId: d00e3e9e08feb6c3be671b5805102a66782b3f92
This commit is contained in:
parent
1f2c06b1d0
commit
9276ba87b2
3 changed files with 34 additions and 1 deletions
|
@ -63,6 +63,7 @@ module.exports = DiffGenerator = {
|
||||||
if (p > max_p) {
|
if (p > max_p) {
|
||||||
logger.warn({ max_p, p }, 'truncating position to content length')
|
logger.warn({ max_p, p }, 'truncating position to content length')
|
||||||
p = max_p
|
p = max_p
|
||||||
|
op.p = p // fix out of range offsets to avoid invalid history exports in ZipManager
|
||||||
}
|
}
|
||||||
|
|
||||||
const textToBeRemoved = content.slice(p, p + op.i.length)
|
const textToBeRemoved = content.slice(p, p + op.i.length)
|
||||||
|
@ -74,6 +75,9 @@ module.exports = DiffGenerator = {
|
||||||
|
|
||||||
return content.slice(0, p) + content.slice(p + op.i.length)
|
return content.slice(0, p) + content.slice(p + op.i.length)
|
||||||
} else if (op.d != null) {
|
} else if (op.d != null) {
|
||||||
|
if (op.p > content.length) {
|
||||||
|
op.p = content.length // fix out of range offsets to avoid invalid history exports in ZipManager
|
||||||
|
}
|
||||||
return content.slice(0, op.p) + op.d + content.slice(op.p)
|
return content.slice(0, op.p) + op.d + content.slice(op.p)
|
||||||
} else {
|
} else {
|
||||||
return content
|
return content
|
||||||
|
|
|
@ -107,6 +107,15 @@ async function upgradeProject(project, options) {
|
||||||
if (!upgradeFn) {
|
if (!upgradeFn) {
|
||||||
return { error: 'unsupported history type' }
|
return { error: 'unsupported history type' }
|
||||||
}
|
}
|
||||||
|
if (options.forceClean) {
|
||||||
|
try {
|
||||||
|
const projectId = project._id
|
||||||
|
// delete any existing history stored in the mongo backend
|
||||||
|
await HistoryManager.promises.deleteProject(projectId, projectId)
|
||||||
|
} catch (err) {
|
||||||
|
// failed to delete existing history, but we can try to continue
|
||||||
|
}
|
||||||
|
}
|
||||||
const result = await upgradeFn(project, options)
|
const result = await upgradeFn(project, options)
|
||||||
result.historyType = historyType
|
result.historyType = historyType
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -2,6 +2,25 @@
|
||||||
process.env.MONGO_SOCKET_TIMEOUT =
|
process.env.MONGO_SOCKET_TIMEOUT =
|
||||||
parseInt(process.env.MONGO_SOCKET_TIMEOUT, 10) || 3600000
|
parseInt(process.env.MONGO_SOCKET_TIMEOUT, 10) || 3600000
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
|
if (fs.existsSync('/etc/container_environment.json')) {
|
||||||
|
try {
|
||||||
|
const envData = JSON.parse(
|
||||||
|
fs.readFileSync('/etc/container_environment.json', 'utf8')
|
||||||
|
)
|
||||||
|
for (const [key, value] of Object.entries(envData)) {
|
||||||
|
process.env[key] = value
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(
|
||||||
|
'cannot read /etc/container_environment.json, the script needs to be run as root',
|
||||||
|
err
|
||||||
|
)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const VERSION = '0.9.0-cli'
|
const VERSION = '0.9.0-cli'
|
||||||
const {
|
const {
|
||||||
countProjects,
|
countProjects,
|
||||||
|
@ -11,7 +30,6 @@ const {
|
||||||
} = require('../../modules/history-migration/app/src/HistoryUpgradeHelper')
|
} = require('../../modules/history-migration/app/src/HistoryUpgradeHelper')
|
||||||
const { waitForDb } = require('../../app/src/infrastructure/mongodb')
|
const { waitForDb } = require('../../app/src/infrastructure/mongodb')
|
||||||
const minimist = require('minimist')
|
const minimist = require('minimist')
|
||||||
const fs = require('fs')
|
|
||||||
const util = require('util')
|
const util = require('util')
|
||||||
const pLimit = require('p-limit')
|
const pLimit = require('p-limit')
|
||||||
const logger = require('@overleaf/logger')
|
const logger = require('@overleaf/logger')
|
||||||
|
@ -34,6 +52,7 @@ const argv = minimist(process.argv.slice(2), {
|
||||||
'use-query-hint',
|
'use-query-hint',
|
||||||
'retry-failed',
|
'retry-failed',
|
||||||
'archive-on-failure',
|
'archive-on-failure',
|
||||||
|
'force-clean',
|
||||||
],
|
],
|
||||||
string: ['output', 'user-id'],
|
string: ['output', 'user-id'],
|
||||||
alias: {
|
alias: {
|
||||||
|
@ -168,6 +187,7 @@ async function migrateProjects(projectsToMigrate) {
|
||||||
convertLargeDocsToFile: argv['convert-large-docs-to-file'],
|
convertLargeDocsToFile: argv['convert-large-docs-to-file'],
|
||||||
userId: argv['user-id'],
|
userId: argv['user-id'],
|
||||||
reason: VERSION,
|
reason: VERSION,
|
||||||
|
forceClean: argv['force-clean'],
|
||||||
}
|
}
|
||||||
async function _migrateProject(project) {
|
async function _migrateProject(project) {
|
||||||
if (INTERRUPT) {
|
if (INTERRUPT) {
|
||||||
|
|
Loading…
Reference in a new issue