🐛 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:
Michael Clark
2025-04-18 10:11:34 +01:00
committed by GitHub
parent e28db52c70
commit 153eaeecc5
2 changed files with 45 additions and 10 deletions

View File

@@ -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

View 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