From 660e711b176f6053b6edf089c7d8c79af392b59e Mon Sep 17 00:00:00 2001 From: GreekStapler Date: Wed, 25 Jan 2023 23:10:53 +0100 Subject: [PATCH] refactor: Added SHA256 to package description file. --- src/package/package.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/package/package.c b/src/package/package.c index bd77f3e..932ac32 100644 --- a/src/package/package.c +++ b/src/package/package.c @@ -5,7 +5,7 @@ #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);\ + description = realloc(description, buff_size * 2); \ buff_size *= 2; \ } \ strcat(description, aux); \ @@ -13,14 +13,14 @@ #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);\ + 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);\ + description = realloc(description, buff_size * 2); \ buff_size *= 2; \ } \ strcat(description, aux); \ @@ -120,6 +120,14 @@ Pkg *package_read_archive(const char *pkg_path) { 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; @@ -142,7 +150,16 @@ char *package_to_description(Pkg *pkg) { ADD_ARRAY("\n\n%%GROUPS%%\n%s", groups); ADD_STRING("\n\n%%CSIZE%%\n%ld", csize); ADD_STRING("\n\n%%ISIZE%%\n%ld", size); - //SHA256SUM + + char res[65]; + sha256sum(pkg, res); + snprintf(aux, SMALL_BUFF_SIZE, "\n\n%%SHA256SUM%%\n%s", res); + 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);