aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-11-12 00:59:47 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-11-12 00:59:47 -0500
commite15448666cec18570001f2857276d74a8595d1a3 (patch)
tree67be987f70a7874cfd61f3363233b940c681a7df
parent5a8efc84f7a3c2264926b393aafd5585deaa7195 (diff)
downloadstasis-e15448666cec18570001f2857276d74a8595d1a3.tar.gz
Use path_manip function
* Add conda_prepend_condabin helper
-rw-r--r--src/lib/core/conda.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/lib/core/conda.c b/src/lib/core/conda.c
index a696744..4533803 100644
--- a/src/lib/core/conda.c
+++ b/src/lib/core/conda.c
@@ -208,23 +208,26 @@ int conda_exec(const char *args) {
}
static int conda_prepend_bin(const char *root) {
- const char *system_path_old = getenv("PATH");
char conda_bin[PATH_MAX] = {0};
- snprintf(conda_bin, sizeof(conda_bin) - 1, "%s/bin:%s/condabin", root, root);
+ snprintf(conda_bin, sizeof(conda_bin) - 1, "%s/bin", root);
+ if (path_manip(conda_bin, PM_PREPEND | PM_ONCE)) {
+ return -1;
+ }
+ return 0;
+}
- if (!strstr(system_path_old, conda_bin)) {
- // conda_bin is not present in PATH. Add it to the head.
- char system_path_new[STASIS_BUFSIZ];
- sprintf(system_path_new, "%s:%s", conda_bin, system_path_old);
- if (setenv("PATH", system_path_new, 1) < 0) {
- SYSERROR("Unable to prepend to PATH: %s", conda_bin);
- return -1;
- }
+static int conda_prepend_condabin(const char *root) {
+ char conda_condabin[PATH_MAX] = {0};
+
+ snprintf(conda_condabin, sizeof(conda_condabin) - 1, "%s/condabin", root);
+ if (path_manip(conda_condabin, PM_PREPEND | PM_ONCE)) {
+ return -1;
}
return 0;
}
+
int conda_activate(const char *root, const char *env_name) {
FILE *fp = NULL;
const char *init_script_conda = "/etc/profile.d/conda.sh";
@@ -274,6 +277,11 @@ int conda_activate(const char *root, const char *env_name) {
conda_shlvl = strtol(conda_shlvl_str, NULL, 10);
}
+ if (conda_prepend_condabin(root)) {
+ remove(logfile);
+ return -1;
+ }
+
if (conda_prepend_bin(root)) {
remove(logfile);
return -1;