From 01180f9cb60893c4a57935fda106b1d5f77e2b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Rolim?= Date: Tue, 10 Nov 2020 00:11:16 -0300 Subject: [PATCH] lib/repo: change some error handling in repo_open_local. - use less intermediate variables - assert that archive_read_new managed to allocate memory for itself: not ideal, but if we ever want to move from assertions it shows us where we need to change things - use libarchive's archive_error_string for better error messages Closes: #345 [via git-merge-pr] --- lib/repo.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/repo.c b/lib/repo.c index 4547d0cd9..b381c9b3d 100644 --- a/lib/repo.c +++ b/lib/repo.c @@ -134,16 +134,15 @@ static bool repo_open_local(struct xbps_repo *repo, const char *repofile) { struct stat st; - int rv = 0; if (fstat(repo->fd, &st) == -1) { - rv = errno; xbps_dbg_printf(repo->xhp, "[repo] `%s' fstat repodata %s\n", - repofile, strerror(rv)); + repofile, strerror(errno)); return false; } repo->ar = archive_read_new(); + assert(repo->ar); archive_read_support_filter_gzip(repo->ar); archive_read_support_filter_bzip2(repo->ar); archive_read_support_filter_xz(repo->ar); @@ -152,10 +151,9 @@ repo_open_local(struct xbps_repo *repo, const char *repofile) archive_read_support_format_tar(repo->ar); if (archive_read_open_fd(repo->ar, repo->fd, st.st_blksize) == ARCHIVE_FATAL) { - rv = archive_errno(repo->ar); xbps_dbg_printf(repo->xhp, "[repo] `%s' failed to open repodata archive %s\n", - repofile, strerror(rv)); + repofile, archive_error_string(repo->ar)); return false; } if ((repo->idx = repo_get_dict(repo)) == NULL) {