aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2025-02-12 13:46:43 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2025-02-12 13:46:43 -0500
commit75c46e42dd881a7f101560f23bd1b4c6a4e45cad (patch)
tree08e3fe413afc685d27353ec89845c6eab2f45c5c /src
parent89bd28eb5ac263d1753021f25e1bc62f48e7008d (diff)
downloadstasis-75c46e42dd881a7f101560f23bd1b4c6a4e45cad.tar.gz
Fix upstream file clobberingfix-parallel-clobbering
* When --overwrite is enabled and the delivery meta.rc is >1, stasis would download all files related to a delivery from the server * This change only downloads files relevant to the arch/platform of the current host system. * Addresses several memory leaks found in the delivery_series_sync function
Diffstat (limited to 'src')
-rw-r--r--src/lib/delivery/delivery_artifactory.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/lib/delivery/delivery_artifactory.c b/src/lib/delivery/delivery_artifactory.c
index e979b9a..97db752 100644
--- a/src/lib/delivery/delivery_artifactory.c
+++ b/src/lib/delivery/delivery_artifactory.c
@@ -193,11 +193,41 @@ int delivery_series_sync(struct Delivery *ctx) {
return -1; // error
}
+ char *r_fmt = strdup(ctx->rules.release_fmt);
+ if (!r_fmt) {
+ SYSERROR("%s", "Unable to allocate bytes for release format string");
+ return -1;
+ }
+
+ // Replace revision formatters with wildcards
+ const char *to_wild[] = {"%r", "%R"};
+ for (size_t i = 0; i < sizeof(to_wild) / sizeof(*to_wild); i++) {
+ const char *formatter = to_wild[i];
+ if (replace_text(r_fmt, formatter, "*", 0) < 0) {
+ SYSERROR("Failed to replace '%s' in delivery format string", formatter);
+ return -1;
+ }
+ }
+
+ char *release_pattern = NULL;
+ if (delivery_format_str(ctx, &release_pattern, r_fmt) < 0) {
+ SYSERROR("Unable to render delivery format string: %s", r_fmt);
+ guard_free(r_fmt);
+ return -1;
+ }
+ guard_free(r_fmt);
+
char *remote_dir = NULL;
- if (asprintf(&remote_dir, "%s/%s/%s/(*)", globals.jfrog.repo, ctx->meta.mission, ctx->info.build_name) < 0) {
+ if (asprintf(&remote_dir, "%s/%s/%s/(*/*%s*)",
+ globals.jfrog.repo,
+ ctx->meta.mission,
+ ctx->info.build_name,
+ release_pattern) < 0) {
SYSERROR("%s", "Unable to allocate bytes for remote directory path");
+ guard_free(release_pattern);
return -1;
}
+ guard_free(release_pattern);
char *dest_dir = NULL;
if (asprintf(&dest_dir, "%s/{1}", ctx->storage.output_dir) < 0) {
@@ -205,5 +235,8 @@ int delivery_series_sync(struct Delivery *ctx) {
return -1;
}
- return jfrog_cli_rt_download(&ctx->deploy.jfrog_auth, &dl, remote_dir, dest_dir);
+ int status = jfrog_cli_rt_download(&ctx->deploy.jfrog_auth, &dl, remote_dir, dest_dir);
+ guard_free(dest_dir);
+ guard_free(remote_dir);
+ return status;
}