mirror of
https://github.com/pygos/pkg-utils.git
synced 2024-11-24 13:40:41 +01:00
file list sort: remove duplicate directory entries
Can happen when merging multiple packages. But make sure they actually are duplicates. Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
parent
96d4d353d4
commit
00db5541e9
1 changed files with 30 additions and 0 deletions
|
@ -68,6 +68,34 @@ static image_entry_t *insert_sorted(image_entry_t *list, image_entry_t *ent)
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void remove_duplicates(image_entry_t *list)
|
||||||
|
{
|
||||||
|
image_entry_t *it = list, *old;
|
||||||
|
int equal;
|
||||||
|
|
||||||
|
if (it == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while (it->next != NULL) {
|
||||||
|
equal = 0;
|
||||||
|
|
||||||
|
if (S_ISDIR(it->mode) && S_ISDIR(it->next->mode)) {
|
||||||
|
equal = (strcmp(it->name, it->next->name) == 0);
|
||||||
|
equal = equal && (it->mode == it->next->mode);
|
||||||
|
equal = equal && (it->uid == it->next->uid);
|
||||||
|
equal = equal && (it->gid == it->next->gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (equal) {
|
||||||
|
old = it->next;
|
||||||
|
it->next = old->next;
|
||||||
|
image_entry_free(old);
|
||||||
|
} else {
|
||||||
|
it = it->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
image_entry_t *image_entry_sort(image_entry_t *list)
|
image_entry_t *image_entry_sort(image_entry_t *list)
|
||||||
{
|
{
|
||||||
image_entry_t *sorted = NULL, *ent;
|
image_entry_t *sorted = NULL, *ent;
|
||||||
|
@ -79,5 +107,7 @@ image_entry_t *image_entry_sort(image_entry_t *list)
|
||||||
sorted = insert_sorted(sorted, ent);
|
sorted = insert_sorted(sorted, ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove_duplicates(sorted);
|
||||||
|
|
||||||
return sorted;
|
return sorted;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue