fix: handle bad access when accessing paths (#2375)

This commit is contained in:
Mo
2023-07-27 13:09:03 -05:00
committed by GitHub
parent bfd2b14264
commit 804a39dabc
10 changed files with 63 additions and 44 deletions

View File

@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { app, ipcMain, shell } from 'electron'
import log from 'electron-log'
import fs from 'fs-extra'
@@ -9,8 +10,6 @@ import { Store } from './javascripts/Main/Store/Store'
import { StoreKeys } from './javascripts/Main/Store/StoreKeys'
import { isSnap } from './javascripts/Main/Types/Constants'
import { Paths } from './javascripts/Main/Types/Paths'
import { setupTesting } from './javascripts/Main/Utils/Testing'
import { isTesting } from './javascripts/Main/Utils/Utils'
import { CommandLineArgs } from './javascripts/Shared/CommandLineArgs'
enableExperimentalFeaturesForFileAccessFix()
@@ -39,10 +38,6 @@ if (userDataPathIndex > 0) {
migrateSnapStorage()
}
if (isTesting()) {
setupTesting()
}
log.transports.file.level = 'info'
process.on('uncaughtException', (err) => {
@@ -96,8 +91,12 @@ function migrateSnapStorage() {
fs.moveSync(fullFilePath, path.join(dest, fileName), {
overwrite: false,
})
} catch (error: any) {
console.error(`Migration: error occured while moving ${fullFilePath} to ${dest}:`, error?.message ?? error)
} catch (error) {
console.error(
`Migration: error occured while moving ${fullFilePath} to ${dest}:`,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(error as any)?.message ?? error,
)
}
}
@@ -110,18 +109,22 @@ function migrateSnapStorage() {
* Backups location has not been altered by the user. Move it to the
* user documents directory
*/
console.log(`Migration: moving ${store.data.backupsLocation} to ${Paths.documentsDir}`)
const newLocation = path.join(Paths.documentsDir, path.basename(store.data.backupsLocation))
try {
fs.copySync(store.data.backupsLocation, newLocation)
} catch (error: any) {
console.error(
`Migration: error occured while moving ${store.data.backupsLocation} to ${Paths.documentsDir}:`,
error?.message ?? error,
)
const documentsDir = Paths.documentsDir
console.log(`Migration: moving ${store.data.backupsLocation} to ${documentsDir}`)
if (documentsDir) {
const newLocation = path.join(documentsDir, path.basename(store.data.backupsLocation))
try {
fs.copySync(store.data.backupsLocation, newLocation)
} catch (error) {
console.error(
`Migration: error occured while moving ${store.data.backupsLocation} to ${documentsDir}:`,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(error as any)?.message ?? error,
)
}
store.set(StoreKeys.LegacyTextBackupsLocation, newLocation)
console.log('Migration: finished moving backups directory.')
}
store.set(StoreKeys.LegacyTextBackupsLocation, newLocation)
console.log('Migration: finished moving backups directory.')
}
}
}