diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-12-03 09:26:32 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-12-03 19:07:23 -0500 |
commit | 9098abc13882e6b665e46361721d3bcba7da55eb (patch) | |
tree | ed45ff9ec78412be2ac12e2a6d4eb9fa96394274 | |
parent | d18249abd2e45b345fc8c5dc61bab11530e9dccf (diff) | |
download | stasis-9098abc13882e6b665e46361721d3bcba7da55eb.tar.gz |
delivery_exists() returns DELIVERY_NOT_FOUND by default
-rw-r--r-- | src/cli/stasis/stasis_main.c | 4 | ||||
-rw-r--r-- | src/lib/core/delivery_init.c | 24 |
2 files changed, 13 insertions, 15 deletions
diff --git a/src/cli/stasis/stasis_main.c b/src/cli/stasis/stasis_main.c index adc3cd7..807dbbd 100644 --- a/src/cli/stasis/stasis_main.c +++ b/src/cli/stasis/stasis_main.c @@ -220,9 +220,7 @@ int main(int argc, char *argv[]) { // Safety gate: Avoid clobbering a delivered release unless the user wants that behavior msg(STASIS_MSG_L1, "Checking release history\n"); - const int found_delivery = delivery_exists(&ctx); - - if (!globals.enable_overwrite && found_delivery) { + if (!globals.enable_overwrite && delivery_exists(&ctx) == DELIVERY_FOUND) { msg(STASIS_MSG_ERROR | STASIS_MSG_L1, "Refusing to overwrite release: %s\nUse --overwrite to enable release clobbering.\n", ctx.info.release_name); exit(1); } diff --git a/src/lib/core/delivery_init.c b/src/lib/core/delivery_init.c index 7e51f24..2fced03 100644 --- a/src/lib/core/delivery_init.c +++ b/src/lib/core/delivery_init.c @@ -309,7 +309,7 @@ int bootstrap_build_info(struct Delivery *ctx) { } int delivery_exists(struct Delivery *ctx) { - int release_exists = 0; + int release_exists = DELIVERY_NOT_FOUND; char release_pattern[PATH_MAX] = {0}; sprintf(release_pattern, "*%s*", ctx->info.release_name); @@ -323,24 +323,24 @@ int delivery_exists(struct Delivery *ctx) { // 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); + const int match = jfrog_cli_rt_search(&ctx->deploy.jfrog_auth, &search, globals.jfrog.repo, release_pattern); + if (!match) { + release_exists = DELIVERY_FOUND; + } } else { struct StrList *files = listdir(ctx->storage.delivery_dir); - for (size_t i = 0; i < strlist_count(files); i++) { + const size_t files_count = strlist_count(files); + + for (size_t i = 0; i < files_count; i++) { char *filename = strlist_item(files, i); - release_exists = fnmatch(release_pattern, filename, FNM_PATHNAME); - if (!release_exists) { + const int match = fnmatch(release_pattern, filename, FNM_PATHNAME); + if (match == 0) { + release_exists = DELIVERY_FOUND; break; } } guard_strlist_free(&files); } - if (release_exists < 0) { - return -1; // error - } - if (release_exists >= 1) { - return DELIVERY_NOT_FOUND; - } - return DELIVERY_FOUND; + return release_exists; } |