diff --git a/Makefile b/Makefile index 4907163..6c02db1 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ build-test: $(BINS_TEST) # For simplicity, we link every object file to each of the test files. This # might be changed later if this starts to become too slow. $(BINS_TEST): %: %.c.o $(OBJS) - $(CC) $^ -o $@ + $(CC) $^ -larchive -o $@ # Each test includes the test directory, which contains the acutest header file $(BUILD_DIR)/$(TEST_DIR)/%.c.o: $(TEST_DIR)/%.c diff --git a/include/dynarray.h b/include/dynarray.h new file mode 100644 index 0000000..2ab4022 --- /dev/null +++ b/include/dynarray.h @@ -0,0 +1,24 @@ +#ifndef VIETER_DYNARRAY +#define VIETER_DYNARRAY + +#include +#include + +typedef struct dyn_array DynArray; +struct dyn_array { + char **array; + size_t capacity; + size_t size; +}; + +DynArray *dynarray_init(size_t initial_capacity); +void dynarray_add(DynArray *da, const char * s); +void dynarray_free(DynArray *da); + +/** + * Convert a DynArray into an array by freeing all its surrounding components + * and returning the underlying array pointer. + */ +char **dynarray_convert(DynArray *da); + +#endif diff --git a/include/package.h b/include/package.h new file mode 100644 index 0000000..09e91bd --- /dev/null +++ b/include/package.h @@ -0,0 +1,26 @@ +#ifndef VIETER_PACKAGE +#define VIETER_PACKAGE + +#include +#include +#include +#include + +#include "archive.h" +#include "archive_entry.h" + +#include "package_info.h" +#include "dynarray.h" + +typedef struct pkg { + char *path; + PkgInfo *info; + DynArray *files; + int compression; +} Pkg; + +Pkg *package_read_archive(const char *pkg_path); +void package_free(Pkg ** ptp); +char *package_to_description(Pkg *pkg); + +#endif diff --git a/include/package_info.h b/include/package_info.h new file mode 100644 index 0000000..b1388a2 --- /dev/null +++ b/include/package_info.h @@ -0,0 +1,39 @@ +#ifndef VIETER_PACKAGE_INFO +#define VIETER_PACKAGE_INFO + +#define FREE_STRING(sp) if (sp != NULL) free(sp) + +#include + +#include "dynarray.h" + +typedef struct pkg_info { + char *name; + char *base; + char *version; + char *description; + int64_t size; + int64_t csize; + char *url; + char *arch; + int64_t build_date; + char *packager; + char *pgpsig; + int64_t pgpsigsize; + + DynArray *groups; + DynArray *licenses; + DynArray *replaces; + DynArray *depends; + DynArray *conflicts; + DynArray *provides; + DynArray *optdepends; + DynArray *makedepends; + DynArray *checkdepends; +} PkgInfo; + +PkgInfo *package_info_init(); +void package_info_parse(PkgInfo *pkg_info, char *pkg_info_str); +void package_info_free(PkgInfo *pkg_info); + +#endif diff --git a/src/package/dynarray.c b/src/package/dynarray.c new file mode 100644 index 0000000..a78e7ff --- /dev/null +++ b/src/package/dynarray.c @@ -0,0 +1,50 @@ +#include "dynarray.h" + +DynArray *dynarray_init(size_t initial_capacity) { + DynArray *da = malloc(sizeof(DynArray)); + da->size = 0; + da->capacity = initial_capacity; + + return da; +} + +void dynarray_add(DynArray *da, const char *s) { + // An empty dynarray does not have an allocated internal array yet + if (da->size == 0) { + da->array = malloc(sizeof(char*) * da->capacity); + } + // Double array size if it's full + else if (da->size == da->capacity) { + // if the realloc fails, access to memory in da->array is lost + da->array = realloc(da->array, sizeof(char*) * da->capacity * 2); + da->capacity *= 2; + } + + da->array[da->size] = strdup(s); + da->size++; +} + +void dynarray_free(DynArray *da) { + if (da == NULL) { + return; + } + + if (da->array != NULL) { + for (size_t i = 0; i < da->size; i++) { + free(da->array[i]); + } + + free(da->array); + } + + free(da); +} + +char **dynarray_convert(DynArray *da) { + char **array = da->array; + + da->array = NULL; + dynarray_free(da); + + return array; +} diff --git a/src/package/package.c b/src/package/package.c new file mode 100644 index 0000000..8d1565d --- /dev/null +++ b/src/package/package.c @@ -0,0 +1,180 @@ +#include "package.h" + +#define SMALL_BUFF_SIZE 128 + +#define ADD_STRING(section, field) if (pkg_info->field != 0) { \ + snprintf(aux, SMALL_BUFF_SIZE, section, pkg_info->field); \ + if (buff_size < strlen(description) + SMALL_BUFF_SIZE + 1) { \ + description = realloc(description, buff_size * 2); \ + buff_size *= 2; \ + } \ + strcat(description, aux); \ +} +#define ADD_ARRAY(section, field) i = 0; if (pkg_info->field != NULL) { \ + snprintf(aux, SMALL_BUFF_SIZE, section, pkg_info->field->array[i]); i++; \ + if (buff_size < strlen(description) + SMALL_BUFF_SIZE + 1) { \ + description = realloc(description, buff_size * 2); \ + buff_size *= 2; \ + } \ + strcat(description, aux); \ + while (pkg_info->field->array[i] != NULL) { \ + snprintf(aux, SMALL_BUFF_SIZE, "\n%s", pkg_info->field->array[i]); i++; \ + if (buff_size < strlen(description) + SMALL_BUFF_SIZE + 1) { \ + description = realloc(description, buff_size * 2); \ + buff_size *= 2; \ + } \ + strcat(description, aux); \ + } \ +} + +static char *ignored_names[5] = { + ".BUILDINFO", + ".INSTALL", + ".MTREE", + ".PKGINFO", + ".CHANGELOG" +}; +static size_t ignored_words_len = sizeof(ignored_names) / sizeof(char *); + +Pkg *package_init() { + return calloc(sizeof(PkgInfo), 1); +} + +Pkg *package_read_archive(const char *pkg_path) { + struct archive *a = archive_read_new(); + struct archive_entry *entry = archive_entry_new(); + + // These three are the most commonly used compression methods + archive_read_support_filter_zstd(a); + archive_read_support_filter_gzip(a); + archive_read_support_filter_xz(a); + + // Contents should always be a tarball + archive_read_support_format_tar(a); + + // TODO where does this 10240 come from? + int r = archive_read_open_filename(a, pkg_path, 10240); + + // Exit early if we weren't able to successfully open the archive for reading + if (r != ARCHIVE_OK) { + return NULL; + } + + int compression_code = archive_filter_code(a, 0); + const char *path_name; + + PkgInfo *pkg_info; + DynArray *files = dynarray_init(16); + dynarray_add(files, "%FILES%"); + + while (archive_read_next_header(a, &entry) == ARCHIVE_OK) { + path_name = archive_entry_pathname(entry); + + bool ignore = false; + + for (size_t i = 0; i < ignored_words_len; i++) { + if (strcmp(path_name, ignored_names[i]) == 0) { + ignore = true; + break; + } + } + + if (!ignore) { + dynarray_add(files, path_name); + } + + if (strcmp(path_name, ".PKGINFO") == 0) { + // Read data of file into memory buffer + int size = archive_entry_size(entry); + char *buf = malloc(size); + archive_read_data(a, buf, size); + + // Parse package info string into a struct + pkg_info = package_info_init(); + package_info_parse(pkg_info, buf); + + free(buf); + } else { + archive_read_data_skip(a); + } + } + + // Get size of file + struct stat stats; + + if (stat(pkg_path, &stats) != 0) { + return NULL; + } + + pkg_info->csize = stats.st_size; + + archive_read_free(a); + + // Create final return value + Pkg *pkg = package_init(); + pkg->path = strdup(pkg_path); + pkg->info = pkg_info; + pkg->files = files; + pkg->compression = compression_code; + + return pkg; +} + +void sha256sum(Pkg *pkg, char *res) { + char command[SMALL_BUFF_SIZE]; + snprintf(command, SMALL_BUFF_SIZE, "sha256sum %s", pkg->path); + FILE *p = popen(command, "r"); + + fgets(res, 65, p); + pclose(p); +} + +char *package_to_description(Pkg *pkg) { + PkgInfo *pkg_info = pkg->info; + + size_t buff_size = 1024; + char aux[SMALL_BUFF_SIZE]; + char *description = malloc(sizeof(char) * buff_size); + int i; + + // special case for FILENAME + // assuming .pkg.tar.zst; other formats are valid, this should account for that + snprintf(aux, SMALL_BUFF_SIZE, "%%FILENAME%%\n%s-%s-%s.pkg.tar.zst", pkg_info->name, pkg_info->version, + pkg_info->arch); + strcat(description, aux); + + ADD_STRING("\n\n%%NAME%%\n%s", name); + ADD_STRING("\n\n%%BASE%%\n%s", base); + ADD_STRING("\n\n%%VERSION%%\n%s", version); + ADD_STRING("\n\n%%DESC%%\n%s", description); + ADD_ARRAY("\n\n%%GROUPS%%\n%s", groups); + ADD_STRING("\n\n%%CSIZE%%\n%ld", csize); + ADD_STRING("\n\n%%ISIZE%%\n%ld", size); + + char checksum[65]; + sha256sum(pkg, checksum); + snprintf(aux, SMALL_BUFF_SIZE, "\n\n%%SHA256SUM%%\n%s", checksum); + if (buff_size < strlen(description) + SMALL_BUFF_SIZE + 1) { + description = realloc(description, buff_size * 2); + buff_size *= 2; + } + strcat(description, aux); + + ADD_STRING("\n\n%%URL%%\n%s", url); + ADD_ARRAY("\n\n%%LICENSE%%\n%s", licenses); + ADD_STRING("\n\n%%ARCH%%\n%s", arch); + ADD_STRING("\n\n%%BUILDDATE%%\n%ld", build_date); + ADD_STRING("\n\n%%PACKAGER%%\n%s", packager); + ADD_ARRAY("\n\n%%REPLACES%%\n%s", replaces); + ADD_ARRAY("\n\n%%CONFLICTS%%\n%s", conflicts); + ADD_ARRAY("\n\n%%PROVIDES%%\n%s", provides); + ADD_ARRAY("\n\n%%DEPENDS%%\n%s", depends); + ADD_ARRAY("\n\n%%OPTDEPENDS%%\n%s", optdepends); + ADD_ARRAY("\n\n%%MAKEDEPENDS%%\n%s", makedepends); + ADD_ARRAY("\n\n%%CHECKDEPENDS%%\n%s", checkdepends); + + snprintf(aux, SMALL_BUFF_SIZE, "\n\n"); + strcat(description, aux); + + return description; +} diff --git a/src/package/package_info.c b/src/package/package_info.c new file mode 100644 index 0000000..5e1986d --- /dev/null +++ b/src/package/package_info.c @@ -0,0 +1,79 @@ +#include + +#include "package_info.h" + +#define PKG_INFO_STRING(key_ptr, field) if ((value_ptr = strstr(value_ptr, key_ptr)) != NULL) { \ + value_ptr += strlen(key_ptr);\ + tail_ptr = strchr(value_ptr, '\n');\ + tail_ptr[0] = '\0'; \ + pkg_info->field = strdup(value_ptr); \ + tail_ptr[0] = '\n'; \ +} value_ptr = tail_ptr; + +#define PKG_INFO_INT(key_ptr, field) value_ptr = strstr(value_ptr, key_ptr) + strlen(key_ptr);\ + tail_ptr = strchr(value_ptr, '\n');\ + tail_ptr[0] = '\0'; \ + pkg_info->field = atoi(value_ptr); \ + tail_ptr[0] = '\n'; \ + value_ptr = tail_ptr; + +#define PKG_INFO_ARRAY(key_ptr, field) while((value_ptr = strstr(value_ptr, key_ptr)) != NULL){ \ + value_ptr = value_ptr + strlen(key_ptr);\ + tail_ptr = strchr(value_ptr, '\n'); \ + tail_ptr[0] = '\0'; \ + if(pkg_info->field == NULL) { pkg_info->field = dynarray_init(4); } \ + dynarray_add(pkg_info->field, value_ptr); \ + tail_ptr[0] = '\n'; \ + value_ptr = tail_ptr;\ +} value_ptr = tail_ptr; + +PkgInfo *package_info_init() { + return calloc(1, sizeof(PkgInfo)); +} + +void package_info_free(PkgInfo *pkg_info) { + FREE_STRING(pkg_info->name); + FREE_STRING(pkg_info->base); + FREE_STRING(pkg_info->version); + FREE_STRING(pkg_info->description); + FREE_STRING(pkg_info->url); + FREE_STRING(pkg_info->arch); + FREE_STRING(pkg_info->packager); + FREE_STRING(pkg_info->pgpsig); + + dynarray_free(pkg_info->groups); + dynarray_free(pkg_info->licenses); + dynarray_free(pkg_info->replaces); + dynarray_free(pkg_info->depends); + dynarray_free(pkg_info->conflicts); + dynarray_free(pkg_info->provides); + dynarray_free(pkg_info->optdepends); + dynarray_free(pkg_info->makedepends); + dynarray_free(pkg_info->checkdepends); + + free(pkg_info); +} + +void package_info_parse(PkgInfo *pkg_info, char *pkg_info_str) { + char *value_ptr = pkg_info_str, *tail_ptr; + + PKG_INFO_STRING("\npkgname = ", name); + PKG_INFO_STRING("\npkgbase = ", base); + PKG_INFO_STRING("\npkgver = ", version); + PKG_INFO_STRING("\npkgdesc = ", description); + PKG_INFO_STRING("\nurl = ", url); + PKG_INFO_INT("\nbuilddate = ", build_date); + PKG_INFO_STRING("\npackager = ", packager); + PKG_INFO_INT("\nsize = ", size); + PKG_INFO_STRING("\narch = ", arch); + PKG_INFO_ARRAY("\nlicense = ", licenses); + PKG_INFO_ARRAY("\nreplaces = ", replaces); + PKG_INFO_ARRAY("\ngroup = ", groups); + PKG_INFO_ARRAY("\nconflict = ", conflicts); + PKG_INFO_ARRAY("\nprovides = ", provides); + PKG_INFO_ARRAY("\ndepend = ", depends); + PKG_INFO_ARRAY("\noptdepend = ", optdepends); + PKG_INFO_ARRAY("\nmakedepend = ", makedepends); + PKG_INFO_ARRAY("\ncheckdepend = ", checkdepends); + +} diff --git a/test/package/.PKGINFO b/test/package/.PKGINFO new file mode 100644 index 0000000..7113061 --- /dev/null +++ b/test/package/.PKGINFO @@ -0,0 +1,22 @@ +# Generated by makepkg 6.0.2 +# using fakeroot version 1.30.1 +pkgname = xcursor-dmz +pkgbase = xcursor-dmz +pkgver = 0.4.5-2 +pkgdesc = Style neutral, scalable cursor theme +url = https://packages.debian.org/sid/dmz-cursor-theme +builddate = 1673751613 +packager = Unknown Packager +size = 3469584 +arch = any +license = MIT +replaces = test1 +group = x11 +conflict = test2 +conflict = test3 +provides = test4 +depend = test5 +depend = test6 +optdepend = test7 +makedepend = xorg-xcursorgen +checkdepend = test8 diff --git a/test/package/desc b/test/package/desc new file mode 100644 index 0000000..d583af1 --- /dev/null +++ b/test/package/desc @@ -0,0 +1,45 @@ +%FILENAME% +xcursor-dmz-0.4.5-2-any.pkg.tar.zst + +%NAME% +xcursor-dmz + +%BASE% +xcursor-dmz + +%VERSION% +0.4.5-2 + +%DESC% +Style neutral, scalable cursor theme + +%GROUPS% +x11 + +%CSIZE% +328282 + +%ISIZE% +3469584 + +%SHA256SUM% +4f4bce9e975334ed7775ff4ddf4d2e82e411d599802f6179a122f89149f53bfb + +%URL% +https://packages.debian.org/sid/dmz-cursor-theme + +%LICENSE% +MIT + +%ARCH% +any + +%BUILDDATE% +1673751613 + +%PACKAGER% +Unknown Packager + +%MAKEDEPENDS% +xorg-xcursorgen + diff --git a/test/package/files b/test/package/files new file mode 100644 index 0000000..aab44b1 --- /dev/null +++ b/test/package/files @@ -0,0 +1,243 @@ +%FILES% +usr/ +usr/share/ +usr/share/icons/ +usr/share/icons/DMZ-Black/ +usr/share/icons/DMZ-Black/cursor.theme +usr/share/icons/DMZ-Black/cursors/ +usr/share/icons/DMZ-Black/cursors/00008160000006810000408080010102 +usr/share/icons/DMZ-Black/cursors/028006030e0e7ebffc7f7070c0600140 +usr/share/icons/DMZ-Black/cursors/03b6e0fcb3499374a867c041f52298f0 +usr/share/icons/DMZ-Black/cursors/08e8e1c95fe2fc01f976f1e063a24ccd +usr/share/icons/DMZ-Black/cursors/1081e37283d90000800003c07f3ef6bf +usr/share/icons/DMZ-Black/cursors/14fef782d02440884392942c11205230 +usr/share/icons/DMZ-Black/cursors/2870a09082c103050810ffdffffe0204 +usr/share/icons/DMZ-Black/cursors/3085a0e285430894940527032f8b26df +usr/share/icons/DMZ-Black/cursors/3ecb610c1bf2410f44200f48c40d3599 +usr/share/icons/DMZ-Black/cursors/4498f0e0c1937ffe01fd06f973665830 +usr/share/icons/DMZ-Black/cursors/5c6cd98b3f3ebcb1f9c7f1c204630408 +usr/share/icons/DMZ-Black/cursors/6407b0e94181790501fd1e167b474872 +usr/share/icons/DMZ-Black/cursors/640fb0e74195791501fd1ed57b41487f +usr/share/icons/DMZ-Black/cursors/9081237383d90e509aa00f00170e968f +usr/share/icons/DMZ-Black/cursors/9d800788f1b08800ae810202380a0822 +usr/share/icons/DMZ-Black/cursors/X_cursor +usr/share/icons/DMZ-Black/cursors/alias +usr/share/icons/DMZ-Black/cursors/arrow +usr/share/icons/DMZ-Black/cursors/bd_double_arrow +usr/share/icons/DMZ-Black/cursors/bottom_left_corner +usr/share/icons/DMZ-Black/cursors/bottom_right_corner +usr/share/icons/DMZ-Black/cursors/bottom_side +usr/share/icons/DMZ-Black/cursors/bottom_tee +usr/share/icons/DMZ-Black/cursors/c7088f0f3e6c8088236ef8e1e3e70000 +usr/share/icons/DMZ-Black/cursors/circle +usr/share/icons/DMZ-Black/cursors/col-resize +usr/share/icons/DMZ-Black/cursors/color-picker +usr/share/icons/DMZ-Black/cursors/copy +usr/share/icons/DMZ-Black/cursors/cross +usr/share/icons/DMZ-Black/cursors/cross_reverse +usr/share/icons/DMZ-Black/cursors/crossed_circle +usr/share/icons/DMZ-Black/cursors/crosshair +usr/share/icons/DMZ-Black/cursors/d9ce0ab605698f320427677b458ad60b +usr/share/icons/DMZ-Black/cursors/default +usr/share/icons/DMZ-Black/cursors/diamond_cross +usr/share/icons/DMZ-Black/cursors/dnd-ask +usr/share/icons/DMZ-Black/cursors/dnd-copy +usr/share/icons/DMZ-Black/cursors/dnd-link +usr/share/icons/DMZ-Black/cursors/dnd-move +usr/share/icons/DMZ-Black/cursors/dnd-none +usr/share/icons/DMZ-Black/cursors/dot_box_mask +usr/share/icons/DMZ-Black/cursors/dotbox +usr/share/icons/DMZ-Black/cursors/double_arrow +usr/share/icons/DMZ-Black/cursors/draft_large +usr/share/icons/DMZ-Black/cursors/draft_small +usr/share/icons/DMZ-Black/cursors/draped_box +usr/share/icons/DMZ-Black/cursors/e-resize +usr/share/icons/DMZ-Black/cursors/e29285e634086352946a0e7090d73106 +usr/share/icons/DMZ-Black/cursors/ew-resize +usr/share/icons/DMZ-Black/cursors/fcf1c3c7cd4491d801f1e1c78f100000 +usr/share/icons/DMZ-Black/cursors/fd_double_arrow +usr/share/icons/DMZ-Black/cursors/fleur +usr/share/icons/DMZ-Black/cursors/grab +usr/share/icons/DMZ-Black/cursors/grabbing +usr/share/icons/DMZ-Black/cursors/h_double_arrow +usr/share/icons/DMZ-Black/cursors/hand +usr/share/icons/DMZ-Black/cursors/hand1 +usr/share/icons/DMZ-Black/cursors/hand2 +usr/share/icons/DMZ-Black/cursors/help +usr/share/icons/DMZ-Black/cursors/icon +usr/share/icons/DMZ-Black/cursors/left_ptr +usr/share/icons/DMZ-Black/cursors/left_ptr_help +usr/share/icons/DMZ-Black/cursors/left_ptr_watch +usr/share/icons/DMZ-Black/cursors/left_side +usr/share/icons/DMZ-Black/cursors/left_tee +usr/share/icons/DMZ-Black/cursors/link +usr/share/icons/DMZ-Black/cursors/ll_angle +usr/share/icons/DMZ-Black/cursors/lr_angle +usr/share/icons/DMZ-Black/cursors/move +usr/share/icons/DMZ-Black/cursors/n-resize +usr/share/icons/DMZ-Black/cursors/ne-resize +usr/share/icons/DMZ-Black/cursors/nesw-resize +usr/share/icons/DMZ-Black/cursors/not-allowed +usr/share/icons/DMZ-Black/cursors/ns-resize +usr/share/icons/DMZ-Black/cursors/nw-resize +usr/share/icons/DMZ-Black/cursors/nwse-resize +usr/share/icons/DMZ-Black/cursors/openhand +usr/share/icons/DMZ-Black/cursors/pencil +usr/share/icons/DMZ-Black/cursors/pirate +usr/share/icons/DMZ-Black/cursors/plus +usr/share/icons/DMZ-Black/cursors/pointer +usr/share/icons/DMZ-Black/cursors/progress +usr/share/icons/DMZ-Black/cursors/question_arrow +usr/share/icons/DMZ-Black/cursors/right_ptr +usr/share/icons/DMZ-Black/cursors/right_side +usr/share/icons/DMZ-Black/cursors/right_tee +usr/share/icons/DMZ-Black/cursors/row-resize +usr/share/icons/DMZ-Black/cursors/s-resize +usr/share/icons/DMZ-Black/cursors/sb_down_arrow +usr/share/icons/DMZ-Black/cursors/sb_h_double_arrow +usr/share/icons/DMZ-Black/cursors/sb_left_arrow +usr/share/icons/DMZ-Black/cursors/sb_right_arrow +usr/share/icons/DMZ-Black/cursors/sb_up_arrow +usr/share/icons/DMZ-Black/cursors/sb_v_double_arrow +usr/share/icons/DMZ-Black/cursors/se-resize +usr/share/icons/DMZ-Black/cursors/size_bdiag +usr/share/icons/DMZ-Black/cursors/size_fdiag +usr/share/icons/DMZ-Black/cursors/size_hor +usr/share/icons/DMZ-Black/cursors/size_ver +usr/share/icons/DMZ-Black/cursors/sw-resize +usr/share/icons/DMZ-Black/cursors/target +usr/share/icons/DMZ-Black/cursors/tcross +usr/share/icons/DMZ-Black/cursors/text +usr/share/icons/DMZ-Black/cursors/top_left_arrow +usr/share/icons/DMZ-Black/cursors/top_left_corner +usr/share/icons/DMZ-Black/cursors/top_right_corner +usr/share/icons/DMZ-Black/cursors/top_side +usr/share/icons/DMZ-Black/cursors/top_tee +usr/share/icons/DMZ-Black/cursors/ul_angle +usr/share/icons/DMZ-Black/cursors/ur_angle +usr/share/icons/DMZ-Black/cursors/v_double_arrow +usr/share/icons/DMZ-Black/cursors/w-resize +usr/share/icons/DMZ-Black/cursors/wait +usr/share/icons/DMZ-Black/cursors/watch +usr/share/icons/DMZ-Black/cursors/xterm +usr/share/icons/DMZ-White/ +usr/share/icons/DMZ-White/cursor.theme +usr/share/icons/DMZ-White/cursors/ +usr/share/icons/DMZ-White/cursors/00008160000006810000408080010102 +usr/share/icons/DMZ-White/cursors/028006030e0e7ebffc7f7070c0600140 +usr/share/icons/DMZ-White/cursors/03b6e0fcb3499374a867c041f52298f0 +usr/share/icons/DMZ-White/cursors/08e8e1c95fe2fc01f976f1e063a24ccd +usr/share/icons/DMZ-White/cursors/1081e37283d90000800003c07f3ef6bf +usr/share/icons/DMZ-White/cursors/14fef782d02440884392942c11205230 +usr/share/icons/DMZ-White/cursors/2870a09082c103050810ffdffffe0204 +usr/share/icons/DMZ-White/cursors/3085a0e285430894940527032f8b26df +usr/share/icons/DMZ-White/cursors/3ecb610c1bf2410f44200f48c40d3599 +usr/share/icons/DMZ-White/cursors/4498f0e0c1937ffe01fd06f973665830 +usr/share/icons/DMZ-White/cursors/5c6cd98b3f3ebcb1f9c7f1c204630408 +usr/share/icons/DMZ-White/cursors/6407b0e94181790501fd1e167b474872 +usr/share/icons/DMZ-White/cursors/640fb0e74195791501fd1ed57b41487f +usr/share/icons/DMZ-White/cursors/9081237383d90e509aa00f00170e968f +usr/share/icons/DMZ-White/cursors/9d800788f1b08800ae810202380a0822 +usr/share/icons/DMZ-White/cursors/X_cursor +usr/share/icons/DMZ-White/cursors/alias +usr/share/icons/DMZ-White/cursors/arrow +usr/share/icons/DMZ-White/cursors/bd_double_arrow +usr/share/icons/DMZ-White/cursors/bottom_left_corner +usr/share/icons/DMZ-White/cursors/bottom_right_corner +usr/share/icons/DMZ-White/cursors/bottom_side +usr/share/icons/DMZ-White/cursors/bottom_tee +usr/share/icons/DMZ-White/cursors/c7088f0f3e6c8088236ef8e1e3e70000 +usr/share/icons/DMZ-White/cursors/circle +usr/share/icons/DMZ-White/cursors/col-resize +usr/share/icons/DMZ-White/cursors/color-picker +usr/share/icons/DMZ-White/cursors/copy +usr/share/icons/DMZ-White/cursors/cross +usr/share/icons/DMZ-White/cursors/cross_reverse +usr/share/icons/DMZ-White/cursors/crossed_circle +usr/share/icons/DMZ-White/cursors/crosshair +usr/share/icons/DMZ-White/cursors/d9ce0ab605698f320427677b458ad60b +usr/share/icons/DMZ-White/cursors/default +usr/share/icons/DMZ-White/cursors/diamond_cross +usr/share/icons/DMZ-White/cursors/dnd-ask +usr/share/icons/DMZ-White/cursors/dnd-copy +usr/share/icons/DMZ-White/cursors/dnd-link +usr/share/icons/DMZ-White/cursors/dnd-move +usr/share/icons/DMZ-White/cursors/dnd-none +usr/share/icons/DMZ-White/cursors/dot_box_mask +usr/share/icons/DMZ-White/cursors/dotbox +usr/share/icons/DMZ-White/cursors/double_arrow +usr/share/icons/DMZ-White/cursors/draft_large +usr/share/icons/DMZ-White/cursors/draft_small +usr/share/icons/DMZ-White/cursors/draped_box +usr/share/icons/DMZ-White/cursors/e-resize +usr/share/icons/DMZ-White/cursors/e29285e634086352946a0e7090d73106 +usr/share/icons/DMZ-White/cursors/ew-resize +usr/share/icons/DMZ-White/cursors/fcf1c3c7cd4491d801f1e1c78f100000 +usr/share/icons/DMZ-White/cursors/fd_double_arrow +usr/share/icons/DMZ-White/cursors/fleur +usr/share/icons/DMZ-White/cursors/grab +usr/share/icons/DMZ-White/cursors/grabbing +usr/share/icons/DMZ-White/cursors/h_double_arrow +usr/share/icons/DMZ-White/cursors/hand +usr/share/icons/DMZ-White/cursors/hand1 +usr/share/icons/DMZ-White/cursors/hand2 +usr/share/icons/DMZ-White/cursors/help +usr/share/icons/DMZ-White/cursors/icon +usr/share/icons/DMZ-White/cursors/left_ptr +usr/share/icons/DMZ-White/cursors/left_ptr_help +usr/share/icons/DMZ-White/cursors/left_ptr_watch +usr/share/icons/DMZ-White/cursors/left_side +usr/share/icons/DMZ-White/cursors/left_tee +usr/share/icons/DMZ-White/cursors/link +usr/share/icons/DMZ-White/cursors/ll_angle +usr/share/icons/DMZ-White/cursors/lr_angle +usr/share/icons/DMZ-White/cursors/move +usr/share/icons/DMZ-White/cursors/n-resize +usr/share/icons/DMZ-White/cursors/ne-resize +usr/share/icons/DMZ-White/cursors/nesw-resize +usr/share/icons/DMZ-White/cursors/not-allowed +usr/share/icons/DMZ-White/cursors/ns-resize +usr/share/icons/DMZ-White/cursors/nw-resize +usr/share/icons/DMZ-White/cursors/nwse-resize +usr/share/icons/DMZ-White/cursors/openhand +usr/share/icons/DMZ-White/cursors/pencil +usr/share/icons/DMZ-White/cursors/pirate +usr/share/icons/DMZ-White/cursors/plus +usr/share/icons/DMZ-White/cursors/pointer +usr/share/icons/DMZ-White/cursors/progress +usr/share/icons/DMZ-White/cursors/question_arrow +usr/share/icons/DMZ-White/cursors/right_ptr +usr/share/icons/DMZ-White/cursors/right_side +usr/share/icons/DMZ-White/cursors/right_tee +usr/share/icons/DMZ-White/cursors/row-resize +usr/share/icons/DMZ-White/cursors/s-resize +usr/share/icons/DMZ-White/cursors/sb_down_arrow +usr/share/icons/DMZ-White/cursors/sb_h_double_arrow +usr/share/icons/DMZ-White/cursors/sb_left_arrow +usr/share/icons/DMZ-White/cursors/sb_right_arrow +usr/share/icons/DMZ-White/cursors/sb_up_arrow +usr/share/icons/DMZ-White/cursors/sb_v_double_arrow +usr/share/icons/DMZ-White/cursors/se-resize +usr/share/icons/DMZ-White/cursors/size_bdiag +usr/share/icons/DMZ-White/cursors/size_fdiag +usr/share/icons/DMZ-White/cursors/size_hor +usr/share/icons/DMZ-White/cursors/size_ver +usr/share/icons/DMZ-White/cursors/sw-resize +usr/share/icons/DMZ-White/cursors/target +usr/share/icons/DMZ-White/cursors/tcross +usr/share/icons/DMZ-White/cursors/text +usr/share/icons/DMZ-White/cursors/top_left_arrow +usr/share/icons/DMZ-White/cursors/top_left_corner +usr/share/icons/DMZ-White/cursors/top_right_corner +usr/share/icons/DMZ-White/cursors/top_side +usr/share/icons/DMZ-White/cursors/top_tee +usr/share/icons/DMZ-White/cursors/ul_angle +usr/share/icons/DMZ-White/cursors/ur_angle +usr/share/icons/DMZ-White/cursors/v_double_arrow +usr/share/icons/DMZ-White/cursors/w-resize +usr/share/icons/DMZ-White/cursors/wait +usr/share/icons/DMZ-White/cursors/watch +usr/share/icons/DMZ-White/cursors/xterm +usr/share/licenses/ +usr/share/licenses/xcursor-dmz/ +usr/share/licenses/xcursor-dmz/LICENSE diff --git a/test/package/test_package.c b/test/package/test_package.c new file mode 100644 index 0000000..c0c7085 --- /dev/null +++ b/test/package/test_package.c @@ -0,0 +1,84 @@ +#include "acutest.h" +#include "package.h" + +void test_pkg_info_parse() { + FILE *f = fopen("./test/package/.PKGINFO", "r"); + TEST_ASSERT_(f != NULL, "could not find test .PKGINFO file in ./test/package "); + fseek(f, 0L, SEEK_END); + size_t size = ftell(f); + fflush(stdout); + rewind(f); + char *pkg_info_str = malloc(size); + fread(pkg_info_str, 1, size, f); + fclose(f); + PkgInfo *pkg_info = package_info_init(); + package_info_parse(pkg_info, pkg_info_str); + + TEST_CHECK(!strcmp(pkg_info->name, "xcursor-dmz")); + TEST_CHECK(!strcmp(pkg_info->base, "xcursor-dmz")); + TEST_CHECK(!strcmp(pkg_info->version, "0.4.5-2")); + TEST_CHECK(!strcmp(pkg_info->description, "Style neutral, scalable cursor theme")); + TEST_CHECK(!strcmp(pkg_info->url, "https://packages.debian.org/sid/dmz-cursor-theme")); + TEST_CHECK(pkg_info->build_date == 1673751613); + TEST_CHECK(!strcmp(pkg_info->packager, "Unknown Packager")); + TEST_CHECK(pkg_info->size == 3469584); + TEST_CHECK(!strcmp(pkg_info->arch, "any")); + + TEST_CHECK(!strcmp(pkg_info->licenses->array[0], "MIT")); + TEST_CHECK(!strcmp(pkg_info->replaces->array[0], "test1")); + TEST_CHECK(!strcmp(pkg_info->groups->array[0], "x11")); + TEST_CHECK(!strcmp(pkg_info->conflicts->array[0], "test2")); + TEST_CHECK(!strcmp(pkg_info->conflicts->array[1], "test3")); + TEST_CHECK(!strcmp(pkg_info->provides->array[0], "test4")); + TEST_CHECK(!strcmp(pkg_info->depends->array[0], "test5")); + TEST_CHECK(!strcmp(pkg_info->depends->array[1], "test6")); + TEST_CHECK(!strcmp(pkg_info->optdepends->array[0], "test7")); + TEST_CHECK(!strcmp(pkg_info->makedepends->array[0], "xorg-xcursorgen")); + TEST_CHECK(!strcmp(pkg_info->checkdepends->array[0], "test8")); +} + +void test_pkg_read_archive_files() { + Pkg *pkg = package_read_archive("./test/package/xcursor-dmz-0.4.5-2-any.pkg.tar.zst"); + TEST_ASSERT_(pkg != NULL, "failure parsing pkg archive"); + + FILE *f = fopen("./test/package/files", "r"); + TEST_ASSERT_(f != NULL, "could not find test files file in ./test/package"); + char buff[128]; + size_t i = 0; + + while ((fgets(buff, 128, f)) != NULL || i < pkg->files->size) { + if (buff[strlen(buff) - 1] == '\n') { + buff[strlen(buff) - 1] = '\0'; + } + + TEST_CHECK_(!strcmp(pkg->files->array[i], buff), "%s != %s", pkg->files->array[i], buff); + i++; + } + TEST_CHECK(pkg->compression = 14); + +} + +void test_pkg_read_archive_desc() { + Pkg *pkg = package_read_archive("./test/package/xcursor-dmz-0.4.5-2-any.pkg.tar.zst"); + TEST_ASSERT_(pkg != NULL, "failure parsing pkg archive"); + + char *description = package_to_description(pkg); + + FILE *f = fopen("./test/package/desc", "r"); + TEST_ASSERT_(f != NULL, "could not find test desc file in ./test/package"); + fseek(f, 0, SEEK_END); + size_t size = ftell(f); + rewind(f); + char *desc = malloc(size); + fread(desc, 1, size, f); + fclose(f); + + TEST_CHECK(!strcmp(description, desc)); +} + +TEST_LIST = { + {"pkg_info_valid_parse", test_pkg_info_parse}, + {"pkg_read_archive_files", test_pkg_read_archive_files}, + {"pkg_read_archive_desc", test_pkg_read_archive_desc}, + {NULL, NULL} +}; diff --git a/test/package/xcursor-dmz-0.4.5-2-any.pkg.tar.zst b/test/package/xcursor-dmz-0.4.5-2-any.pkg.tar.zst new file mode 100644 index 0000000..a878047 Binary files /dev/null and b/test/package/xcursor-dmz-0.4.5-2-any.pkg.tar.zst differ