Cleanup/fix order of toc entries

- Make sure we always sort the list when reading it from a package
 - Cleanup and clarify order of elements

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2019-02-04 18:08:32 +01:00
parent 16bf7172fe
commit 27c802fed0
3 changed files with 27 additions and 19 deletions

View File

@ -5,29 +5,39 @@
static int compare_ent(image_entry_t *a, image_entry_t *b)
{
if (S_ISDIR(a->mode)) {
/* directories < .. < symlinks < devices < .. < files */
switch (a->mode & S_IFMT) {
case S_IFDIR:
if (S_ISDIR(b->mode))
goto out_len;
return -1;
}
case S_IFREG:
if (S_ISREG(b->mode))
goto out_fsize;
return 1;
case S_IFLNK:
if (S_ISLNK(b->mode))
goto out_len;
if (S_ISDIR(b->mode))
return 1;
if (S_ISREG(a->mode)) {
if (S_ISREG(b->mode)) {
return -1;
case S_IFBLK:
case S_IFCHR:
if (S_ISDIR(b->mode) || S_ISLNK(b->mode))
return 1;
if (S_ISBLK(b->mode) || S_ISCHR(b->mode))
goto out_len;
return -1;
}
out_len:
return (int)strlen(a->name) - (int)strlen(b->name);
out_fsize:
if (a->data.file.size > b->data.file.size)
return 1;
if (a->data.file.size < b->data.file.size)
return -1;
return 0;
}
return 1;
}
if (S_ISREG(b->mode))
return 1;
out_len:
return (int)strlen(a->name) - (int)strlen(b->name);
}
static image_entry_t *insert_sorted(image_entry_t *list, image_entry_t *ent)
{

View File

@ -202,8 +202,6 @@ int pkg_unpack(int rootfd, int flags, pkg_reader_t *rd)
if (list == NULL)
return -1;
list = image_entry_sort(list);
if (pkg_reader_rewind(rd))
goto fail;

View File

@ -170,7 +170,7 @@ image_entry_t *image_entry_list_from_package(pkg_reader_t *pkg)
goto fail_multi;
}
return list;
return image_entry_sort(list);
fail_oom:
fputs("out of memory\n", stderr);
goto fail;