Skip to content

Commit

Permalink
refactor(data_dir): pass DIR_NAME as argument to getTriliumDir
Browse files Browse the repository at this point in the history
makes it a bit cleaner and easier to test in the future,
as it is one thing less that'd need mocking :-)
  • Loading branch information
pano9000 committed Jan 6, 2025
1 parent 9d3085f commit e223cb8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/services/data_dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ function createDirIfNotExisting(path: fs.PathLike, permissionMode: fs.Mode = FOL
}
}

export function getTriliumDataDir() {
export function getTriliumDataDir(dataDirName: string) {
// case A
if (process.env.TRILIUM_DATA_DIR) {
createDirIfNotExisting(process.env.TRILIUM_DATA_DIR);
return process.env.TRILIUM_DATA_DIR;
}

// case B
const homePath = pathJoin(os.homedir(), DIR_NAME);
const homePath = pathJoin(os.homedir(), dataDirName);
if (fs.existsSync(homePath)) {
return homePath;
}

// case C
const platformAppDataDir = getPlatformAppDataDir(os.platform(), process.env.APPDATA);
if (platformAppDataDir && fs.existsSync(platformAppDataDir)) {
const appDataDirPath = pathJoin(platformAppDataDir, DIR_NAME);
const appDataDirPath = pathJoin(platformAppDataDir, dataDirName);
createDirIfNotExisting(appDataDirPath);
return appDataDirPath;
}
Expand Down Expand Up @@ -87,7 +87,7 @@ export function getDataDirs(TRILIUM_DATA_DIR: string) {

}

const TRILIUM_DATA_DIR = getTriliumDataDir();
const TRILIUM_DATA_DIR = getTriliumDataDir(DIR_NAME);
const dataDirs = getDataDirs(TRILIUM_DATA_DIR);

export default dataDirs;

0 comments on commit e223cb8

Please sign in to comment.