fix: handle bad access when accessing paths (#2375)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user