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

@@ -88,7 +88,7 @@ export class FilesBackupManager implements FileBackupsDevice {
return value === true
}
async getUserDocumentsDirectory(): Promise<string> {
async getUserDocumentsDirectory(): Promise<string | undefined> {
return Paths.documentsDir
}
@@ -103,7 +103,12 @@ export class FilesBackupManager implements FileBackupsDevice {
}
const LegacyTextBackupsDirectory = 'Standard Notes Backups'
return path.join(Paths.homeDir, LegacyTextBackupsDirectory)
const homeDir = Paths.homeDir
if (homeDir) {
return path.join(homeDir, LegacyTextBackupsDirectory)
}
return undefined
}
private getFileBackupsMappingFilePath(backupsLocation: string): string {

View File

@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { compareVersions } from 'compare-versions'
import log from 'electron-log'
import fs from 'fs'

View File

@@ -247,7 +247,7 @@ export class RemoteBridge implements CrossProcessBridge {
return this.fileBackups.migrateLegacyFileBackupsToNewStructure(newPath)
}
getUserDocumentsDirectory(): Promise<string> {
getUserDocumentsDirectory(): Promise<string | undefined> {
return this.fileBackups.getUserDocumentsDirectory()
}

View File

@@ -36,11 +36,19 @@ export const Paths = {
get userDataDir(): string {
return app.getPath('userData')
},
get homeDir(): string {
return app.getPath('home')
get homeDir(): string | undefined {
try {
return app.getPath('home')
} catch (error) {
return undefined
}
},
get documentsDir(): string {
return app.getPath('documents')
get documentsDir(): string | undefined {
try {
return app.getPath('documents')
} catch (error) {
return undefined
}
},
get tempDir(): string {
return app.getPath('temp')

View File

@@ -152,7 +152,7 @@ export class DesktopDevice extends WebOrDesktopDevice implements DesktopDeviceIn
return this.remoteBridge.wasLegacyTextBackupsExplicitlyDisabled()
}
getUserDocumentsDirectory(): Promise<string> {
getUserDocumentsDirectory(): Promise<string | undefined> {
return this.remoteBridge.getUserDocumentsDirectory()
}