From e95f6811f7e11479a1799851845dc528e21e2b97 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Tue, 31 Jan 2023 07:14:25 +0100 Subject: [PATCH] Add support for symlinked database files (#3129) --- src/datastores/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/datastores/index.js b/src/datastores/index.js index a54fd0b4a..2f1485cf9 100644 --- a/src/datastores/index.js +++ b/src/datastores/index.js @@ -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` }