Skip to content

Commit 8a03a5b

Browse files
committed
bin/xbps-rindex: cleanup error returns
1 parent 6b9527f commit 8a03a5b

2 files changed

Lines changed: 26 additions & 26 deletions

File tree

bin/xbps-rindex/repoflush.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,10 @@ archive_dict(struct archive *ar, const char *filename, xbps_dictionary_t dict)
110110
errno = 0;
111111
buf = xbps_dictionary_externalize(dict);
112112
if (!buf) {
113-
r = -errno;
114-
xbps_error_printf("failed to externalize dictionary for: %s\n",
115-
filename);
116-
if (r == 0)
117-
return -EINVAL;
118-
return 0;
113+
if (errno == 0)
114+
errno = EINVAL;
115+
return xbps_error_errno(errno,
116+
"failed to externalize dictionary for: %s\n", filename);
119117
}
120118

121119
r = xbps_archive_append_buf(ar, buf, strlen(buf), filename, 0644,
@@ -147,23 +145,23 @@ repodata_flush(const char *repodir,
147145

148146
r = snprintf(path, sizeof(path), "%s/%s-repodata", repodir, arch);
149147
if (r < 0 || (size_t)r >= sizeof(tmp)) {
150-
xbps_error_printf("repodata path too long: %s: %s\n", path,
148+
return xbps_error_errno(ENAMETOOLONG,
149+
"repodata path too long: %s: %s\n", path,
151150
strerror(ENAMETOOLONG));
152-
return -ENAMETOOLONG;
153151
}
154152

155153
r = snprintf(tmp, sizeof(tmp), "%s.XXXXXXX", path);
156154
if (r < 0 || (size_t)r >= sizeof(tmp)) {
157-
xbps_error_printf("repodata tmp path too long: %s: %s\n", path,
155+
return xbps_error_errno(ENAMETOOLONG,
156+
"repodata tmp path too long: %s: %s\n", path,
158157
strerror(ENAMETOOLONG));
159-
return -ENAMETOOLONG;
160158
}
161159

162160
prevumask = umask(S_IXUSR|S_IRWXG|S_IRWXO);
163161
fd = mkstemp(tmp);
164162
if (fd == -1) {
165-
r = -errno;
166-
xbps_error_printf("failed to open temp file: %s: %s", tmp, strerror(-r));
163+
r = xbps_error_errno(errno, "failed to open temp file: %s: %s",
164+
tmp, strerror(-r));
167165
umask(prevumask);
168166
goto err;
169167
}
@@ -194,8 +192,7 @@ repodata_flush(const char *repodir,
194192
goto err;
195193
}
196194
if (archive_write_free(ar) == ARCHIVE_FATAL) {
197-
r = -errno;
198-
xbps_error_printf("failed to free archive: %s\n", strerror(-r));
195+
r = xbps_error_errno(errno, "failed to free archive: %s\n", strerror(errno));
199196
goto err;
200197
}
201198

@@ -206,19 +203,18 @@ repodata_flush(const char *repodir,
206203
#endif
207204

208205
if (fchmod(fd, 0664) == -1) {
209-
errno = -r;
210-
xbps_error_printf("failed to set mode: %s: %s\n",
211-
tmp, strerror(-r));
206+
r = xbps_error_errno(errno, "failed to set mode: %s: %s\n", tmp,
207+
strerror(errno));
212208
close(fd);
213209
unlink(tmp);
214210
return r;
215211
}
216212
close(fd);
217213

218214
if (rename(tmp, path) == -1) {
219-
r = -errno;
220-
xbps_error_printf("failed to rename repodata: %s: %s: %s\n",
221-
tmp, path, strerror(-r));
215+
r = xbps_error_errno(errno,
216+
"failed to rename repodata: %s: %s: %s\n", tmp, path,
217+
strerror(errno));
222218
unlink(tmp);
223219
return r;
224220
}

bin/xbps-rindex/sign.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,14 @@ sign_repo(struct xbps_handle *xhp, const char *repodir,
168168
*/
169169
repo = xbps_repo_open(xhp, repodir);
170170
if (repo == NULL) {
171-
r = -errno;
172-
xbps_error_printf("%s: cannot read repository data: %s\n",
173-
_XBPS_RINDEX, strerror(errno));
171+
r = xbps_error_errno(errno,
172+
"%s: cannot read repository data: %s\n", _XBPS_RINDEX,
173+
strerror(errno));
174174
goto out;
175175
}
176176
if (xbps_dictionary_count(repo->idx) == 0) {
177-
r = -EINVAL;
178-
xbps_error_printf("%s: invalid repository, exiting!\n", _XBPS_RINDEX);
177+
r = xbps_error_errno(
178+
EINVAL, "%s: invalid repository, exiting!\n", _XBPS_RINDEX);
179179
goto out;
180180
}
181181

@@ -193,11 +193,15 @@ sign_repo(struct xbps_handle *xhp, const char *repodir,
193193

194194
meta = xbps_dictionary_create();
195195
if (!meta) {
196-
r = -ENOMEM;
196+
r = xbps_error_oom();
197197
goto out;
198198
}
199199

200200
data = xbps_data_create_data(buf, strlen(buf));
201+
if (!data) {
202+
r = xbps_error_oom();
203+
goto out;
204+
}
201205
rpubkey = xbps_dictionary_get(repo->idxmeta, "public-key");
202206
if (!xbps_data_equals(rpubkey, data))
203207
flush = true;

0 commit comments

Comments
 (0)