1
0
Fork 0
mirror of https://github.com/pygos/pkg-utils.git synced 2024-11-22 12:59:46 +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:
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,28 +5,38 @@
static int compare_ent(image_entry_t *a, image_entry_t *b) 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)) if (S_ISDIR(b->mode))
goto out_len; goto out_len;
return -1; 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)) if (S_ISDIR(b->mode))
return 1; return 1;
return -1;
if (S_ISREG(a->mode)) { case S_IFBLK:
if (S_ISREG(b->mode)) { 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) if (a->data.file.size > b->data.file.size)
return 1; return 1;
if (a->data.file.size < b->data.file.size) if (a->data.file.size < b->data.file.size)
return -1; return -1;
return 0; 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) 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) if (list == NULL)
return -1; return -1;
list = image_entry_sort(list);
if (pkg_reader_rewind(rd)) if (pkg_reader_rewind(rd))
goto fail; goto fail;

View file

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