aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-12-03 01:00:22 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-12-03 19:07:23 -0500
commit38e4789530a38ac9e7dfddfc0afcff178bd1647f (patch)
tree1a99157926302f0f2fa52f1a08b88839d3d6423f
parentcc6458bc5efffc9712bb0c731957dfe75d1ebca5 (diff)
downloadstasis-38e4789530a38ac9e7dfddfc0afcff178bd1647f.tar.gz
Simplify delivery_exists() function
* Returns DELIVERY_[NOT_]FOUND, or -1 on error
-rw-r--r--src/lib/core/delivery_init.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/lib/core/delivery_init.c b/src/lib/core/delivery_init.c
index 356a8ce..7e51f24 100644
--- a/src/lib/core/delivery_init.c
+++ b/src/lib/core/delivery_init.c
@@ -320,25 +320,27 @@ int delivery_exists(struct Delivery *ctx) {
}
struct JFRT_Search search = {.fail_no_op = true};
+ // release_exists error states:
+ // `jf rt search --fail_no_op` returns 2 on failure
+ // otherwise, search returns an empty list "[]" and returns 0
release_exists = jfrog_cli_rt_search(&ctx->deploy.jfrog_auth, &search, globals.jfrog.repo, release_pattern);
- if (release_exists != 2) {
- if (!globals.enable_overwrite && !release_exists) {
- // --fail_no_op returns 2 on failure
- // without: it returns an empty list "[]" and exit code 0
- return 1; // found
- }
- }
} else {
struct StrList *files = listdir(ctx->storage.delivery_dir);
for (size_t i = 0; i < strlist_count(files); i++) {
char *filename = strlist_item(files, i);
release_exists = fnmatch(release_pattern, filename, FNM_PATHNAME);
- if (!globals.enable_overwrite && !release_exists) {
- guard_strlist_free(&files);
- return 1; // found
+ if (!release_exists) {
+ break;
}
}
guard_strlist_free(&files);
}
- return 0; // not found
+
+ if (release_exists < 0) {
+ return -1; // error
+ }
+ if (release_exists >= 1) {
+ return DELIVERY_NOT_FOUND;
+ }
+ return DELIVERY_FOUND;
}