Skip to content

Commit 2e044dc

Browse files
author
Martin Vogel
committed
Normalize temp-dir paths to forward slashes for the Windows test build
cbm_mkdtemp on msys2 yields a backslash Windows path; embedding it in the JSON repo_path produced invalid escapes so index_repository failed (count=-1) for every harness contract, plus mixed-separator git -C args. Normalize to forward slashes after mkdtemp — valid in JSON and accepted by Windows file APIs and git.
1 parent 943eb16 commit 2e044dc

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

tests/test_lang_contract.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ typedef struct {
5252
* index_repository flow and open the resulting graph DB (NULL on failure).
5353
* Split out of lang_index_files so a caller can interpose between writing files
5454
* and indexing (e.g. the FILE_CHANGES_WITH test git-inits + commits first). */
55+
56+
/* Normalize backslashes to forward slashes in place. cbm_mkdtemp on Windows
57+
* (msys2) yields a native path with backslashes (e.g. D:\a\_temp\...); those
58+
* break the JSON repo_path ("\a"/"\t" are invalid JSON escapes → index fails →
59+
* count=-1) and produce mixed-separator paths in git -C args. Forward slashes
60+
* are valid in JSON and accepted by Windows file APIs and git. */
61+
static void lc_to_fwd_slashes(char *p) {
62+
for (; *p; p++) {
63+
if (*p == '\\') {
64+
*p = '/';
65+
}
66+
}
67+
}
68+
5569
static cbm_store_t *lang_open_indexed(LangProj *lp) {
5670
lp->project = cbm_project_name_from_path(lp->tmpdir);
5771
if (!lp->project) {
@@ -88,6 +102,7 @@ static cbm_store_t *lang_index_files(LangProj *lp, const LangFile *files, int nf
88102
if (!cbm_mkdtemp(lp->tmpdir)) {
89103
return NULL;
90104
}
105+
lc_to_fwd_slashes(lp->tmpdir);
91106
for (int i = 0; i < nfiles; i++) {
92107
char path[700];
93108
snprintf(path, sizeof(path), "%s/%s", lp->tmpdir, files[i].name);
@@ -1175,6 +1190,7 @@ TEST(contract_edge_file_changes_with) {
11751190
memset(&lp, 0, sizeof(lp));
11761191
snprintf(lp.tmpdir, sizeof(lp.tmpdir), "/tmp/cbm_fcw_XXXXXX");
11771192
ASSERT_NOT_NULL(cbm_mkdtemp(lp.tmpdir));
1193+
lc_to_fwd_slashes(lp.tmpdir);
11781194

11791195
char a[700];
11801196
char b[700];

0 commit comments

Comments
 (0)