mirror of
https://github.com/heyman/heynote.git
synced 2024-12-27 17:18:53 +01:00
f532c7939b
* Add bufferPath to config, support bufferPath symlink * defaultPath before checking realpath * Move code for retrieving buffer path into its own file * Do the realpathSync() call for the whole final file path, to allow the buffer file to be a symlink --------- Co-authored-by: Jonatan Heyman <jonatan@heyman.info>
24 lines
803 B
JavaScript
24 lines
803 B
JavaScript
import fs from "fs"
|
|
import { join } from "path"
|
|
import { app } from "electron"
|
|
import CONFIG from "../config"
|
|
import { isDev } from "../detect-platform"
|
|
|
|
|
|
export function getBufferFilePath() {
|
|
let defaultPath = app.getPath("userData")
|
|
let configPath = CONFIG.get("settings.bufferPath")
|
|
let bufferPath = configPath.length ? configPath : defaultPath
|
|
let bufferFilePath = join(bufferPath, isDev ? "buffer-dev.txt" : "buffer.txt")
|
|
try {
|
|
// use realpathSync to resolve a potential symlink
|
|
return fs.realpathSync(bufferFilePath)
|
|
} catch (err) {
|
|
// realpathSync will fail if the file does not exist, but that doesn't matter since the file will be created
|
|
if (err.code !== "ENOENT") {
|
|
throw err
|
|
}
|
|
return bufferFilePath
|
|
}
|
|
}
|