Commit bb1ac255 authored by Timo Teräs's avatar Timo Teräs
Browse files

db: improve and unify fdb error messages

parent 82713dc3
...@@ -743,9 +743,11 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo) ...@@ -743,9 +743,11 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo)
mode_t mode; mode_t mode;
uid_t uid; uid_t uid;
gid_t gid; gid_t gid;
int field, r; int field, r, lineno = 0;
while (!APK_BLOB_IS_NULL(l = bs->read(bs, token))) { while (!APK_BLOB_IS_NULL(l = bs->read(bs, token))) {
lineno++;
if (l.len < 2 || l.ptr[1] != ':') { if (l.len < 2 || l.ptr[1] != ':') {
if (pkg == NULL) if (pkg == NULL)
continue; continue;
...@@ -783,9 +785,8 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo) ...@@ -783,9 +785,8 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo)
/* Standard index line? */ /* Standard index line? */
r = apk_pkg_add_info(db, pkg, field, l); r = apk_pkg_add_info(db, pkg, field, l);
if (r == 0) { if (r == 0)
continue; continue;
}
if (r == 1 && repo == -1 && ipkg == NULL) { if (r == 1 && repo == -1 && ipkg == NULL) {
/* Instert to installed database; this needs to /* Instert to installed database; this needs to
* happen after package name has been read, but * happen after package name has been read, but
...@@ -799,23 +800,14 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo) ...@@ -799,23 +800,14 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo)
/* Check FDB special entries */ /* Check FDB special entries */
switch (field) { switch (field) {
case 'F': case 'F':
if (pkg->name == NULL) { if (pkg->name == NULL) goto bad_entry;
apk_error("FDB directory entry before package entry");
return -1;
}
diri = apk_db_diri_new(db, pkg, l, &diri_node); diri = apk_db_diri_new(db, pkg, l, &diri_node);
file_diri_node = &diri->owned_files.first; file_diri_node = &diri->owned_files.first;
break; break;
case 'a': case 'a':
if (file == NULL) { if (file == NULL) goto bad_entry;
apk_error("FDB file attribute metadata entry before file entry");
return -1;
}
case 'M': case 'M':
if (diri == NULL) { if (diri == NULL) goto bad_entry;
apk_error("FDB directory metadata entry before directory entry");
return -1;
}
uid = apk_blob_pull_uint(&l, 10); uid = apk_blob_pull_uint(&l, 10);
apk_blob_pull_char(&l, ':'); apk_blob_pull_char(&l, ':');
gid = apk_blob_pull_uint(&l, 10); gid = apk_blob_pull_uint(&l, 10);
...@@ -827,17 +819,11 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo) ...@@ -827,17 +819,11 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo)
apk_db_file_set(file, mode, uid, gid); apk_db_file_set(file, mode, uid, gid);
break; break;
case 'R': case 'R':
if (diri == NULL) { if (diri == NULL) goto bad_entry;
apk_error("FDB file entry before directory entry");
return -1;
}
file = apk_db_file_get(db, diri, l, &file_diri_node); file = apk_db_file_get(db, diri, l, &file_diri_node);
break; break;
case 'Z': case 'Z':
if (file == NULL) { if (file == NULL) goto bad_entry;
apk_error("FDB checksum entry before file entry");
return -1;
}
apk_blob_pull_csum(&l, &file->csum); apk_blob_pull_csum(&l, &file->csum);
break; break;
case 'r': case 'r':
...@@ -868,16 +854,16 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo) ...@@ -868,16 +854,16 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo)
pkg->filename = NULL; pkg->filename = NULL;
continue; continue;
} }
if (APK_BLOB_IS_NULL(l)) { if (APK_BLOB_IS_NULL(l)) goto bad_entry;
apk_error("FDB format error in entry '%c'", field);
return -1;
}
} }
return 0; return 0;
old_apk_tools: old_apk_tools:
/* Installed db should not have unsupported fields */ /* Installed db should not have unsupported fields */
apk_error("This apk-tools is too old to handle installed packages"); apk_error("This apk-tools is too old to handle installed packages");
return -1; return -1;
bad_entry:
apk_error("FDB format error (line %d, entry '%c')", lineno, field);
return -1;
} }
static int apk_db_write_fdb(struct apk_database *db, struct apk_ostream *os) static int apk_db_write_fdb(struct apk_database *db, struct apk_ostream *os)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment