aboutsummaryrefslogtreecommitdiff
path: root/src/lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.c')
-rw-r--r--src/lib.c73
1 files changed, 37 insertions, 36 deletions
diff --git a/src/lib.c b/src/lib.c
index 4912a96..82d2720 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -1,4 +1,5 @@
#include "config.h"
+#include "logerr.h"
#include "tar.h"
#include "gistatic.h"
@@ -296,16 +297,12 @@ static const char *const PROJECT_HOMEPAGE_LINK =
"<a href=\"https://euandreh.xyz/" PROGNAME "\">" PROGNAME "</a>.";
-static void logerr(const char *const s, const char *const msg, int lineno) {
- fprintf(
- stderr,
- "%s:%s:%d: %s: %s\n",
- PROGNAME,
- __FILE__,
- lineno,
- s,
- msg
- );
+static void logerr(
+ const char *const s,
+ const char *const msg,
+ const int lineno
+) {
+ logerr_file(s, msg, __FILE__, lineno);
}
static void logerrs(
@@ -313,19 +310,9 @@ static void logerrs(
const char *const mid,
const char *const post,
const char *const msg,
- int lineno
+ const int lineno
) {
- fprintf(
- stderr,
- "%s:%s:%d: %s%s%s: %s\n",
- PROGNAME,
- __FILE__,
- lineno,
- pre,
- mid,
- post,
- msg
- );
+ logerrs_file(pre, mid, post, msg, __FILE__, lineno);
}
static void logerrl(
@@ -333,21 +320,12 @@ static void logerrl(
const size_t mid,
const char *const post,
const char *const msg,
- int lineno
+ const int lineno
) {
- fprintf(
- stderr,
- "%s:%s:%d: %s%ld%s: %s\n",
- PROGNAME,
- __FILE__,
- lineno,
- pre,
- mid,
- post,
- msg
- );
+ logerrl_file(pre, mid, post, msg, __FILE__, lineno);
}
+
static const char *_(int msg_id) {
if (!catalog_descriptor || catalog_descriptor == (nl_catd)-1) {
return MSGS[msg_id];
@@ -1960,12 +1938,15 @@ cleanup:
static int repo_tarballs_refs_each(
struct git_repository *const repo,
struct git_reference *const ref,
+ const char *const tarballs_dir,
const char *const project_name
) {
int ret = 0;
char *out = NULL;
struct git_commit *commit = NULL;
struct git_tree *tree = NULL;
+ char *tar_path = NULL;
+ FILE *tar_fd = NULL;
const bool is_tag = git_reference_is_tag(ref);
const bool is_branch = git_reference_is_branch(ref);
@@ -2026,12 +2007,31 @@ static int repo_tarballs_refs_each(
goto cleanup;
}
- if (tarball_write_from_directory(out)) {
+ tar_path = strsjoin((const char *const [])
+ { tarballs_dir, "/", project_name, "-", name, ".tar", NULL });
+ if (!tar_path) {
+ ret = -1;
+ goto cleanup;
+ }
+
+ if (!(tar_fd = fopen(tar_path, "w"))) {
+ logerrs("fopen(\"", tar_path, "\")", strerror(errno), __LINE__);
+ ret = -1;
+ goto cleanup;
+ }
+
+ if (tarball_write_from_directory(tar_fd, out)) {
ret = -1;
goto cleanup;
}
cleanup:
+ if (tar_fd && fclose(tar_fd)) {
+ logerrs("fclose(\"", tar_path, "\")", strerror(errno),
+ __LINE__);
+ ret = -1;
+ }
+ free(tar_path);
git_tree_free(tree);
git_commit_free(commit);
free(out);
@@ -2073,7 +2073,8 @@ static int repo_tarballs_write(
struct git_reference *ref;
while (!(e = git_reference_next(&ref, ref_iter))) {
- e = repo_tarballs_refs_each(repo, ref, project_name);
+ e = repo_tarballs_refs_each(repo, ref,
+ tarballs_dir, project_name);
git_reference_free(ref);
if (e == -1) {
ret = -1;