aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-11-13 12:13:34 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-11-13 12:13:34 -0500
commit836cc753ea22fd8a3d152f2b00dae971ee3dc943 (patch)
tree7adbd4a95963d61b02c652a27de855a0d538a9bd
parent35471289b619994c4f04fd2b6cb6d04a16cb1b33 (diff)
downloadstasis-836cc753ea22fd8a3d152f2b00dae971ee3dc943.tar.gz
Attempt conda environment removal only when its present on-diskworkaround-shebang-nightmare
-rw-r--r--include/conda.h2
-rw-r--r--src/cli/stasis/stasis_main.c4
-rw-r--r--src/lib/core/conda.c6
3 files changed, 10 insertions, 2 deletions
diff --git a/include/conda.h b/include/conda.h
index f031479..b8d0caa 100644
--- a/include/conda.h
+++ b/include/conda.h
@@ -229,4 +229,6 @@ const char *pkg_index_provides_strerror(int code);
char *conda_get_active_environment();
+int conda_env_exists(const char *root, const char *name);
+
#endif //STASIS_CONDA_H
diff --git a/src/cli/stasis/stasis_main.c b/src/cli/stasis/stasis_main.c
index 2a2ed3b..093e32e 100644
--- a/src/cli/stasis/stasis_main.c
+++ b/src/cli/stasis/stasis_main.c
@@ -310,7 +310,7 @@ int main(int argc, char *argv[]) {
}
if (!isempty(ctx.meta.based_on)) {
- if (conda_env_remove(env_name)) {
+ if (conda_env_exists(ctx.storage.conda_install_prefix, env_name) && conda_env_remove(env_name)) {
msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "failed to remove release environment: %s\n", env_name);
exit(1);
}
@@ -321,7 +321,7 @@ int main(int argc, char *argv[]) {
exit(1);
}
- if (conda_env_remove(env_name_testing)) {
+ if (conda_env_exists(ctx.storage.conda_install_prefix, env_name_testing) && conda_env_remove(env_name_testing)) {
msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "failed to remove testing environment %s\n", env_name_testing);
exit(1);
}
diff --git a/src/lib/core/conda.c b/src/lib/core/conda.c
index c98be1c..b2caa63f 100644
--- a/src/lib/core/conda.c
+++ b/src/lib/core/conda.c
@@ -542,3 +542,9 @@ int conda_index(const char *path) {
sprintf(command, "index %s", path);
return conda_exec(command);
}
+
+int conda_env_exists(const char *root, const char *name) {
+ char path[PATH_MAX] = {0};
+ snprintf(path, sizeof(path) - 1 - 6, "%s/envs/%s", root, name);
+ return access(path, F_OK) == 0;
+}