Skip to content

Commit 0a8564f

Browse files
committed
Update 1 code files
Modified: • src/omnipkg/dispatcher.c (+28/-16 lines) [gitship-generated]
1 parent d40e853 commit 0a8564f

1 file changed

Lines changed: 26 additions & 14 deletions

File tree

src/omnipkg/dispatcher.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -970,26 +970,37 @@ static int try_daemon_cli(const char *target_python, int argc, char **argv,
970970

971971
static void fallback_to_python_v(const char *self_dir, char **argv,
972972
const char *inject_version) {
973-
/*
974-
* Find the Python that owns this venv/bin dir and re-exec
975-
* the original dispatcher.py via python -m omnipkg.dispatcher
976-
*/
977973
char py[MAX_PATH];
974+
int found = 0;
978975

979-
/* Try the config first */
980-
if (!read_self_config(self_dir, py, sizeof(py)) || !file_exists(py)) {
981-
/* Try common names in self_dir */
982-
const char *names[] = {"python3.11","python3.10","python3.9",
983-
"python3","python",NULL};
984-
int found = 0;
976+
/* 1. Try the config first */
977+
if (read_self_config(self_dir, py, sizeof(py)) && file_exists(py)) {
978+
found = 1;
979+
} else {
980+
/* 2. Try common names in both the current directory AND the parent directory */
981+
const char *names[] = {"python3.11", "python3.10", "python3.9",
982+
"python3", "python", "python.exe", NULL};
983+
984+
/* We check the current dir (self_dir) and the parent dir (self_dir/..) */
985+
const char *search_paths[] = {self_dir, NULL}; // We will handle parent manually for safety
986+
985987
for (int i = 0; names[i]; i++) {
988+
// Try current directory: .../Scripts/python.exe
986989
snprintf(py, sizeof(py), "%s/%s", self_dir, names[i]);
987990
if (file_exists(py)) { found = 1; break; }
991+
992+
// Try parent directory: .../Scripts/../python.exe
993+
snprintf(py, sizeof(py), "%s/../%s", self_dir, names[i]);
994+
if (file_exists(py)) { found = 1; break; }
988995
}
989-
if (!found) {
990-
fprintf(stderr, "omnipkg: cannot find host Python for fallback\n");
991-
exit(1);
992-
}
996+
}
997+
998+
if (!found) {
999+
/* VERBOSE DIAGNOSTICS: Tell the user EXACTLY where we looked */
1000+
fprintf(stderr, "omnipkg: cannot find host Python for fallback\n");
1001+
fprintf(stderr, " Checked directory: %s\n", self_dir);
1002+
fprintf(stderr, " Tried common names in current and parent dirs\n");
1003+
exit(1);
9931004
}
9941005

9951006
/* Build new argv: python -m omnipkg.dispatcher <original args> */
@@ -1007,6 +1018,7 @@ static void fallback_to_python_v(const char *self_dir, char **argv,
10071018
for (int i = 1; i < argc; i++)
10081019
new_argv[i + out - 1] = argv[i];
10091020
new_argv[argc + out - 1] = NULL;
1021+
10101022
execv(py, new_argv);
10111023
perror("omnipkg: execv fallback failed");
10121024
exit(1);

0 commit comments

Comments
 (0)