mirror of
https://github.com/pygos/pkg-utils.git
synced 2024-12-22 01:40:49 +01:00
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:
parent
16bf7172fe
commit
27c802fed0
3 changed files with 27 additions and 19 deletions
|
@ -5,28 +5,38 @@
|
|||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
if (S_ISDIR(b->mode))
|
||||
return 1;
|
||||
|
||||
if (S_ISREG(a->mode)) {
|
||||
if (S_ISREG(b->mode)) {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
static image_entry_t *insert_sorted(image_entry_t *list, image_entry_t *ent)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue