From b21010c3aaf60fcf695f2541c6523a75337b1c9f Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 16 Dec 2024 12:45:56 -0500 Subject: git_clone return NULL on checkout error --- src/lib/core/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/core/utils.c b/src/lib/core/utils.c index aa4173c..96c89bb 100644 --- a/src/lib/core/utils.c +++ b/src/lib/core/utils.c @@ -331,7 +331,7 @@ int git_clone(struct Process *proc, char *url, char *destdir, char *gitref) { { memset(command, 0, sizeof(command)); sprintf(command, "%s fetch --all", program); - result += shell(proc, command); + result = shell(proc, command); if (gitref != NULL) { memset(command, 0, sizeof(command)); -- cgit From c29147a267542750c90ea8fc4905e6a7708b3b55 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 16 Dec 2024 12:46:36 -0500 Subject: delivery_build_wheels return NULL on checkout error --- src/lib/delivery/delivery_build.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/delivery/delivery_build.c b/src/lib/delivery/delivery_build.c index fa19f95..03f2d4c 100644 --- a/src/lib/delivery/delivery_build.c +++ b/src/lib/delivery/delivery_build.c @@ -154,7 +154,11 @@ struct StrList *delivery_build_wheels(struct Delivery *ctx) { memset(wheeldir, 0, sizeof(wheeldir)); sprintf(srcdir, "%s/%s", ctx->storage.build_sources_dir, ctx->tests[i].name); - git_clone(&proc, ctx->tests[i].repository, srcdir, ctx->tests[i].version); + if (git_clone(&proc, ctx->tests[i].repository, srcdir, ctx->tests[i].version)) { + SYSERROR("Unable to checkout tag '%s' for package '%s' from repository '%s'\n", + ctx->tests[i].version, ctx->tests[i].name, ctx->tests[i].repository); + return NULL; + } if (ctx->tests[i].repository_remove_tags && strlist_count(ctx->tests[i].repository_remove_tags)) { filter_repo_tags(srcdir, ctx->tests[i].repository_remove_tags); -- cgit From d664bef4e570647f85d6000170dba7e63807facc Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 16 Dec 2024 15:15:34 -0500 Subject: git_clone: rework the error handler to return the proper exit code * Use goto to drop out for different failure conditions --- src/lib/core/utils.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/lib/core/utils.c b/src/lib/core/utils.c index 96c89bb..621831c 100644 --- a/src/lib/core/utils.c +++ b/src/lib/core/utils.c @@ -307,39 +307,64 @@ int touch(const char *filename) { } int git_clone(struct Process *proc, char *url, char *destdir, char *gitref) { - int result = -1; + int result = 0; char *chdir_to = NULL; char *program = find_program("git"); if (!program) { - return result; + result = -1; + goto die_quick; } - static char command[PATH_MAX]; + static char command[PATH_MAX] = {0}; sprintf(command, "%s clone -c advice.detachedHead=false --recursive %s", program, url); + if (destdir && access(destdir, F_OK) < 0) { + // Destination directory does not exist sprintf(command + strlen(command), " %s", destdir); + // Clone the repo result = shell(proc, command); + if (result) { + goto die_quick; + } } if (destdir) { chdir_to = destdir; } else { + // Assume the name of the directory to be the basename of the URL + // like it is when executed in a shell session chdir_to = path_basename(url); } - pushd(chdir_to); - { + if (!pushd(chdir_to)) { memset(command, 0, sizeof(command)); sprintf(command, "%s fetch --all", program); result = shell(proc, command); + if (result) { + goto die_pop; + } if (gitref != NULL) { memset(command, 0, sizeof(command)); sprintf(command, "%s checkout %s", program, gitref); - result += shell(proc, command); + + result = shell(proc, command); + if (result) { + goto die_pop; + } } popd(); + } else { + result = -1; + goto die_quick; } + return 0; + + die_pop: + // close out last pushd() call + popd(); + + die_quick: return result; } -- cgit