Skip to content

Commit 109acd9

Browse files
kriszypclaude
andauthored
fix: overwrite stale boot props when settings_path no longer exists (#1108)
* fix: overwrite stale boot props when settings_path no longer exists If a previous install directory was deleted (e.g. a temp CI dir), the boot props file persists pointing at a dead path. A reinstall with ROOTPATH set would silently skip updating it, leaving every `harper` invocation triggering the interactive wizard because isHdbInstalled() fails against the missing path. Now also rewrite boot props when the existing file's settings_path resolves to a non-existent directory, regardless of ROOTPATH. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor: anchor settings_path regex, strip quotes, flatten IIFE Cross-model review flagged: - regex without /m and line-start anchor could match commented-out settings_path lines and falsely flag a valid install as stale - extracted path could include surrounding quotes if file was hand-edited - IIFE was harder to follow and ran existsSync twice Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 185b896 commit 109acd9

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

utility/install/installer.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,28 @@ async function createBootPropertiesFile() {
441441
const homeDirPath = path.join(homeDir, hdbTerms.HDB_HOME_DIR_NAME);
442442
const homeDirKeysDirPath = path.join(homeDirPath, hdbTerms.LICENSE_KEY_DIR_NAME);
443443
const propsFilePath = path.join(homeDirPath, hdbTerms.BOOT_PROPS_FILE_NAME);
444-
// if the properties file already exists, and we have an explicit ROOTPATH, we don't overwrite the existing
445-
// properties file
446-
if (!fs.existsSync(propsFilePath) || !hdbUtils.getEnvCliRootPath()) {
444+
// Write boot props when: file doesn't exist, OR no explicit ROOTPATH was given (caller
445+
// accepts whatever path this install produces), OR the existing file points to a
446+
// settings_path that no longer exists (stale from a deleted previous install dir).
447+
let shouldWriteBootProps = !fs.existsSync(propsFilePath) || !hdbUtils.getEnvCliRootPath();
448+
if (!shouldWriteBootProps) {
449+
try {
450+
const content = fs.readFileSync(propsFilePath, 'utf8');
451+
// Anchor to line start (with /m) to avoid matching commented-out lines.
452+
const match = content.match(/^[ \t]*settings_path\s*=\s*(.+)/m);
453+
if (match) {
454+
const settingsPath = match[1].trim().replace(/^["']|["']$/g, '');
455+
if (!fs.existsSync(settingsPath)) {
456+
shouldWriteBootProps = true;
457+
}
458+
} else {
459+
shouldWriteBootProps = true;
460+
}
461+
} catch {
462+
shouldWriteBootProps = true;
463+
}
464+
}
465+
if (shouldWriteBootProps) {
447466
try {
448467
fs.mkdirpSync(homeDirPath, { mode: hdbTerms.HDB_FILE_PERMISSIONS });
449468
fs.mkdirpSync(homeDirKeysDirPath, { mode: hdbTerms.HDB_FILE_PERMISSIONS });

0 commit comments

Comments
 (0)