4 * Small helper to convert diskusage data from sustags or rpmmd
6 * Copyright (c) 2017, Novell Inc.
8 * This program is licensed under the BSD license, read LICENSE.BSD
9 * for further information
12 #include <sys/types.h>
20 #include "repodata_diskusage.h"
22 /* The queue contains (dirid, kbytes, inodes) triplets */
25 add_diskusage_sortfn(const void *ap, const void *bp, void *dp)
27 return *(Id *)ap - *(Id *)bp;
31 repodata_add_diskusage(Repodata *data, Id handle, Queue *q)
34 Dirpool *dp = &data->dirpool;
36 /* Sort in dirid order. This ensures that parents come before
39 solv_sort(q->elements, q->count / 3, 3 * sizeof(Id), add_diskusage_sortfn, 0);
40 for (i = 3; i < q->count; i += 3)
42 /* subtract data from parent */
43 Id did = q->elements[i];
44 if (i + 3 < q->count && q->elements[i + 3] == did)
46 /* identical directory entry! zero this one */
47 q->elements[i + 1] = 0;
48 q->elements[i + 2] = 0;
53 did = dirpool_parent(dp, did);
54 for (j = i - 3; j >= 0; j -= 3)
55 if (q->elements[j] == did)
59 if ((unsigned int)q->elements[j + 1] > (unsigned int)q->elements[i + 1])
60 q->elements[j + 1] -= q->elements[i + 1];
62 q->elements[j + 1] = 0;
63 if ((unsigned int)q->elements[j + 2] > (unsigned int)q->elements[i + 2])
64 q->elements[j + 2] -= q->elements[i + 2];
66 q->elements[j + 2] = 0;
72 for (i = 0; i < q->count; i += 3)
73 if (q->elements[i + 1] || q->elements[i + 2])
74 repodata_add_dirnumnum(data, handle, SOLVABLE_DISKUSAGE, q->elements[i], q->elements[i + 1], q->elements[i + 2]);