database: Propagate errors when loading an APKINDEX

In case of failure when loading an APKINDEX, no errors are
propagated to the user which may uncorrectly interpret the
current problem.
cute-signatures
thibault.ferrante 2021-01-07 17:21:36 +01:00 committed by Timo Teräs
parent b58d79e78f
commit 0fb0d30477
8 changed files with 19812 additions and 19 deletions

View File

@ -517,8 +517,9 @@ int main(int argc, char **argv)
name = spec;
}
if (apk_db_index_read(&db, apk_istream_from_file(AT_FDCWD, name.ptr), repo) != 0) {
apk_err(out, "Failed to open repository: " BLOB_FMT, BLOB_PRINTF(name));
r = apk_db_index_read(&db, apk_istream_from_file(AT_FDCWD, name.ptr), repo);
if (r != 0) {
apk_err(out, "Failed to open repository " BLOB_FMT " : %s", BLOB_PRINTF(name), apk_error_str(r));
goto err;
}

View File

@ -60,7 +60,7 @@ struct apk_ostream;
struct apk_istream_ops {
void (*get_meta)(struct apk_istream *is, struct apk_file_meta *meta);
ssize_t (*read)(struct apk_istream *is, void *ptr, size_t size);
void (*close)(struct apk_istream *is);
int (*close)(struct apk_istream *is);
};
#define APK_ISTREAM_SINGLE_READ 0x0001
@ -103,9 +103,9 @@ static inline void apk_istream_get_meta(struct apk_istream *is, struct apk_file_
{
is->ops->get_meta(is, meta);
}
static inline void apk_istream_close(struct apk_istream *is)
static inline int apk_istream_close(struct apk_istream *is)
{
is->ops->close(is);
return is->ops->close(is);
}
#define APK_MPART_DATA 1 /* data processed so far */

View File

@ -883,17 +883,18 @@ int apk_db_index_read(struct apk_database *db, struct apk_istream *is, int repo)
}
if (APK_BLOB_IS_NULL(l)) goto bad_entry;
}
apk_istream_close(is);
return 0;
return apk_istream_close(is);
old_apk_tools:
/* Installed db should not have unsupported fields */
apk_err(out, "This apk-tools is too old to handle installed packages");
is->err = -EAPKFORMAT;
goto err;
bad_entry:
apk_err(out, "FDB format error (line %d, entry '%c')", lineno, field);
is->err = -EAPKFORMAT;
err:
apk_istream_close(is);
return -1;
return apk_istream_close(is);
}
static void apk_blob_push_db_acl(apk_blob_t *b, char field, struct apk_db_acl *acl)
@ -2143,10 +2144,10 @@ static int load_apkindex(void *sctx, const struct apk_file_info *fi,
repo->description = apk_blob_from_istream(is, fi->size);
} else if (strcmp(fi->name, "APKINDEX") == 0) {
ctx->found = 1;
apk_db_index_read(ctx->db, is, ctx->repo);
r = apk_db_index_read(ctx->db, is, ctx->repo);
}
return 0;
return r;
}
static int load_index(struct apk_database *db, struct apk_istream *is,

View File

@ -207,14 +207,16 @@ static ssize_t segment_read(struct apk_istream *is, void *ptr, size_t size)
return r;
}
static void segment_close(struct apk_istream *is)
static int segment_close(struct apk_istream *is)
{
int r = is->err;
struct apk_segment_istream *sis = container_of(is, struct apk_segment_istream, is);
if (sis->bytes_left) {
apk_istream_read(sis->pis, NULL, sis->bytes_left);
sis->bytes_left = 0;
}
return r < 0 ? r : 0;
}
static const struct apk_istream_ops segment_istream_ops = {
@ -283,8 +285,9 @@ static ssize_t tee_read(struct apk_istream *is, void *ptr, size_t size)
return __tee_write(tee, ptr, r);
}
static void tee_close(struct apk_istream *is)
static int tee_close(struct apk_istream *is)
{
int r;
struct apk_tee_istream *tee = container_of(is, struct apk_tee_istream, is);
struct apk_file_meta meta;
@ -293,9 +296,10 @@ static void tee_close(struct apk_istream *is)
apk_file_meta_to_fd(tee->fd, &meta);
}
apk_istream_close(tee->inner_is);
r = apk_istream_close(tee->inner_is);
close(tee->fd);
free(tee);
return r;
}
static const struct apk_istream_ops tee_istream_ops = {
@ -368,13 +372,15 @@ static ssize_t mmap_read(struct apk_istream *is, void *ptr, size_t size)
return 0;
}
static void mmap_close(struct apk_istream *is)
static int mmap_close(struct apk_istream *is)
{
int r = is->err;
struct apk_mmap_istream *mis = container_of(is, struct apk_mmap_istream, is);
munmap(mis->is.buf, mis->is.buf_size);
close(mis->fd);
free(mis);
return r < 0 ? r : 0;
}
static const struct apk_istream_ops mmap_istream_ops = {
@ -434,12 +440,14 @@ static ssize_t fdi_read(struct apk_istream *is, void *ptr, size_t size)
return r;
}
static void fdi_close(struct apk_istream *is)
static int fdi_close(struct apk_istream *is)
{
int r = is->err;
struct apk_fd_istream *fis = container_of(is, struct apk_fd_istream, is);
close(fis->fd);
free(fis);
return r < 0 ? r : 0;
}
static const struct apk_istream_ops fd_istream_ops = {

View File

@ -118,13 +118,15 @@ ret:
return size - gis->zs.avail_out;
}
static void gzi_close(struct apk_istream *is)
static int gzi_close(struct apk_istream *is)
{
int r;
struct apk_gzip_istream *gis = container_of(is, struct apk_gzip_istream, is);
inflateEnd(&gis->zs);
apk_istream_close(gis->zis);
r = apk_istream_close(gis->zis);
free(gis);
return r;
}
static const struct apk_istream_ops gunzip_istream_ops = {

View File

@ -85,12 +85,14 @@ static ssize_t fetch_read(struct apk_istream *is, void *ptr, size_t size)
return r;
}
static void fetch_close(struct apk_istream *is)
static int fetch_close(struct apk_istream *is)
{
int r = is->err;
struct apk_fetch_istream *fis = container_of(is, struct apk_fetch_istream, is);
fetchIO_close(fis->fetchIO);
free(fis);
return r < 0 ? r : 0;
}
static const struct apk_istream_ops fetch_istream_ops = {

19774
test/iolimit.repo Normal file

File diff suppressed because one or more lines are too long

5
test/iolimit1.test Normal file
View File

@ -0,0 +1,5 @@
@ARGS
--test-repo iolimit.repo
add test-f
@EXPECT
ERROR: Failed to open repository iolimit.repo : No buffer space available