diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-11-13 11:30:34 -0500 | 
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-11-13 11:30:34 -0500 | 
| commit | 35471289b619994c4f04fd2b6cb6d04a16cb1b33 (patch) | |
| tree | 5631311b89b2b8e82be59aa8565f08301f5360ae /src | |
| parent | 8af575409e01bf4e539c73bd3490a7885d9f79a9 (diff) | |
| download | stasis-35471289b619994c4f04fd2b6cb6d04a16cb1b33.tar.gz | |
Rename path_manip() to env_manipulate_pathstr()
* Add key argument to generalize the function
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/core/conda.c | 4 | ||||
| -rw-r--r-- | src/lib/core/utils.c | 11 | 
2 files changed, 7 insertions, 8 deletions
| diff --git a/src/lib/core/conda.c b/src/lib/core/conda.c index 94653c4..c98be1c 100644 --- a/src/lib/core/conda.c +++ b/src/lib/core/conda.c @@ -211,7 +211,7 @@ static int conda_prepend_bin(const char *root) {      char conda_bin[PATH_MAX] = {0};      snprintf(conda_bin, sizeof(conda_bin) - 1, "%s/bin", root); -    if (path_manip(conda_bin, PM_PREPEND | PM_ONCE)) { +    if (env_manipulate_pathstr("PATH", conda_bin, PM_PREPEND | PM_ONCE)) {          return -1;      }      return 0; @@ -221,7 +221,7 @@ 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)) { +    if (env_manipulate_pathstr("PATH", conda_condabin, PM_PREPEND | PM_ONCE)) {          return -1;      }      return 0; diff --git a/src/lib/core/utils.c b/src/lib/core/utils.c index 793b445..18731e6 100644 --- a/src/lib/core/utils.c +++ b/src/lib/core/utils.c @@ -809,7 +809,7 @@ char *find_version_spec(char *str) {      return strpbrk(str, "@~=<>!");  } -int path_manip(char *path, int mode) { +int env_manipulate_pathstr(const char *key, char *path, int mode) {      if (isempty(path)) {          SYSERROR("%s", "New PATH element cannot be zero-length or NULL");          return -1; @@ -824,9 +824,9 @@ int path_manip(char *path, int mode) {      char *system_path_new = NULL;      if (mode & PM_APPEND) { -        asprintf(&system_path_new, "%s:%s", system_path_old, path); +        asprintf(&system_path_new, "%s%s%s", system_path_old, PATH_SEP, path);      } else if (mode & PM_PREPEND) { -        asprintf(&system_path_new, "%s:%s", path, system_path_old); +        asprintf(&system_path_new, "%s%s%s", path, PATH_SEP, system_path_old);      }      if (!system_path_new) { @@ -840,9 +840,8 @@ int path_manip(char *path, int mode) {              return 0;          }      } - -    if (setenv("PATH", system_path_new, 1) < 0) { -        SYSERROR("Unable to prepend to PATH: %s", path); +    if (setenv(key, system_path_new, 1) < 0) { +        SYSERROR("Unable to %s to PATH: %s", mode & PM_APPEND ? "append" : "prepend", path);          guard_free(system_path_new);          return -1;      } | 
