Skip to content

Commit ba91c6c

Browse files
committed
fix(cli): resolve msys-form profile paths and create the staging-root chain
cli_windows_staging_root builds the per-user install staging root from LOCALAPPDATA/USERPROFILE, but msys and CI harnesses export those in POSIX drive form ("/c/Users/..."), which the CRT cannot resolve, and the target's AppData\Local ancestors may not exist yet on a fake-profile fixture. Rewrite a leading "/c/" to native "C:/" before use, create the whole ancestor chain (a single mkdir left the root missing), and fall back to the temp root only after verifying the directory exists. Also name the failing sub-step when private staging cannot even create its directory, so the opaque "did not remain runnable" message is no longer the only signal. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 85c2d99 commit ba91c6c

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎src/cli/cli.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9556,11 +9556,38 @@ static const char *cli_windows_staging_root(char root_out[CLI_BUF_1K]) {
95569556
return cbm_tmpdir();
95579557
}
95589558
}
9559+
/* msys/CI harnesses export profile variables in POSIX drive form
9560+
* ("/c/Users/..."); the CRT cannot resolve that, so rewrite it to the
9561+
* native "C:/Users/..." form before building the root. */
9562+
if (base[0] == '/' &&
9563+
((base[1] >= 'a' && base[1] <= 'z') || (base[1] >= 'A' && base[1] <= 'Z')) &&
9564+
(base[2] == '/' || base[2] == '\0')) {
9565+
char drive = base[1];
9566+
char rest[CLI_BUF_1K];
9567+
(void)snprintf(rest, sizeof(rest), "%s", base + 2);
9568+
(void)snprintf(base, sizeof(base), "%c:%s", drive, rest[0] ? rest : "/");
9569+
}
95599570
int written = snprintf(root_out, CLI_BUF_1K, "%s/codebase-memory-mcp", base);
95609571
if (written <= 0 || written >= CLI_BUF_1K) {
95619572
return cbm_tmpdir();
95629573
}
9574+
/* Create the whole chain: harness environments point LOCALAPPDATA at a
9575+
* fake profile whose AppData\Local ancestors do not exist on disk yet,
9576+
* and a single-level mkdir silently leaves the root missing. */
9577+
for (int index = 3; root_out[index] != '\0'; index++) {
9578+
if (root_out[index] != '/' && root_out[index] != '\\') {
9579+
continue;
9580+
}
9581+
char saved = root_out[index];
9582+
root_out[index] = '\0';
9583+
(void)_mkdir(root_out);
9584+
root_out[index] = saved;
9585+
}
95639586
(void)_mkdir(root_out);
9587+
DWORD attributes = GetFileAttributesA(root_out);
9588+
if (attributes == INVALID_FILE_ATTRIBUTES || (attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
9589+
return cbm_tmpdir();
9590+
}
95649591
return root_out;
95659592
}
95669593

@@ -9577,6 +9604,10 @@ static bool cli_windows_prepare_install_pair(const wchar_t *launcher_source,
95779604
cli_windows_staging_root(staging_root));
95789605
bool ready = launcher_source_utf8 && payload_source_utf8 && directory_length > 0 &&
95799606
directory_length < CLI_BUF_1K && cbm_mkdtemp(directory_out);
9607+
if (!ready) {
9608+
(void)fprintf(stderr, "error: could not create the private staging directory (%s)\n",
9609+
directory_out);
9610+
}
95809611
char launcher_target[CLI_BUF_1K];
95819612
char payload_target[CLI_BUF_1K];
95829613
int launcher_length = ready ? snprintf(launcher_target, sizeof(launcher_target),
@@ -9679,6 +9710,10 @@ static bool cli_windows_prepare_update_pair(const cbm_windows_release_pair_t *pa
96799710
cli_windows_staging_root(staging_root));
96809711
bool ready =
96819712
directory_length > 0 && directory_length < CLI_BUF_1K && cbm_mkdtemp(directory_out);
9713+
if (!ready) {
9714+
(void)fprintf(stderr, "error: could not create the private staging directory (%s)\n",
9715+
directory_out);
9716+
}
96829717
char launcher_target[CLI_BUF_1K];
96839718
char payload_target[CLI_BUF_1K];
96849719
int launcher_length = ready ? snprintf(launcher_target, sizeof(launcher_target),

0 commit comments

Comments
 (0)