mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-09 03:32:54 -05:00
🐛 CLI: Fix ACTUAL_DATA_DIR env variable not respected in some cases (#4825)
* fix issue with default data directory not respecting env variables
This commit is contained in:
@@ -59,7 +59,30 @@ if (values.version) {
|
||||
process.exit();
|
||||
}
|
||||
|
||||
// Read the config argument if specified
|
||||
const setupDataDir = (dataDir = undefined) => {
|
||||
if (process.env.ACTUAL_DATA_DIR) {
|
||||
return; // Env variables must not be overwritten
|
||||
}
|
||||
|
||||
if (dataDir) {
|
||||
process.env.ACTUAL_DATA_DIR = dataDir; // Use the dir specified
|
||||
} else {
|
||||
// Setup defaults
|
||||
if (existsSync('./data')) {
|
||||
// The default data directory exists - use it
|
||||
console.info('Found existing data directory');
|
||||
process.env.ACTUAL_DATA_DIR = './data';
|
||||
} else {
|
||||
console.info(
|
||||
'Using default data directory. You can specify a custom config with --config',
|
||||
);
|
||||
process.env.ACTUAL_DATA_DIR = './';
|
||||
}
|
||||
|
||||
console.info(`Data directory: ${process.env.ACTUAL_DATA_DIR}`);
|
||||
}
|
||||
};
|
||||
|
||||
if (values.config) {
|
||||
const configExists = existsSync(values.config);
|
||||
|
||||
@@ -69,19 +92,25 @@ if (values.config) {
|
||||
);
|
||||
|
||||
process.exit();
|
||||
} else if (values.config) {
|
||||
} else {
|
||||
console.log(`Loading config from ${values.config}`);
|
||||
const configJson = JSON.parse(readFileSync(values.config, 'utf-8'));
|
||||
process.env.ACTUAL_CONFIG_PATH = values.config;
|
||||
setupDataDir(configJson.dataDir);
|
||||
}
|
||||
} else {
|
||||
// No config specified, use reasonable defaults
|
||||
console.info(
|
||||
'Using default config. You can specify a custom config with --config',
|
||||
);
|
||||
process.env.ACTUAL_DATA_DIR = './';
|
||||
console.info(
|
||||
'user-files and server-files will be created in the current directory',
|
||||
);
|
||||
// If no config is specified, check for a default config in the current directory
|
||||
const defaultConfigJsonFile = './config.json';
|
||||
const configExists = existsSync(defaultConfigJsonFile);
|
||||
|
||||
if (configExists) {
|
||||
console.info('Found config.json in the current directory');
|
||||
const configJson = JSON.parse(readFileSync(defaultConfigJsonFile, 'utf-8'));
|
||||
process.env.ACTUAL_CONFIG_PATH = defaultConfigJsonFile;
|
||||
setupDataDir(configJson.dataDir);
|
||||
} else {
|
||||
setupDataDir(); // No default config exists - setup data dir with defaults
|
||||
}
|
||||
}
|
||||
|
||||
// start the sync server
|
||||
|
||||
6
upcoming-release-notes/4825.md
Normal file
6
upcoming-release-notes/4825.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Bugfix
|
||||
authors: [MikesGlitch]
|
||||
---
|
||||
|
||||
Fix CLI issue where ACTAUL_DATA_DIR env variable was not being respected when no config is present
|
||||
Reference in New Issue
Block a user