Add support for symlinked database files (#3129)

This commit is contained in:
absidue 2023-01-31 07:14:25 +01:00 committed by GitHub
parent 8dab58f2b4
commit e95f6811f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,8 +5,18 @@ let dbPath = null
if (process.env.IS_ELECTRON_MAIN) {
const { app } = require('electron')
const { join } = require('path')
// this code only runs in the electron main process, so hopefully using sync fs code here should be fine 😬
const { existsSync, statSync, realpathSync } = require('fs')
const userDataPath = app.getPath('userData') // This is based on the user's OS
dbPath = (dbName) => join(userDataPath, `${dbName}.db`)
dbPath = (dbName) => {
let path = join(userDataPath, `${dbName}.db`)
if (existsSync(path) && statSync(path).isSymbolicLink) {
path = realpathSync(path)
}
return path
}
} else {
dbPath = (dbName) => `${dbName}.db`
}