refactor: Added SHA256 to package description file.

pull/6/head
GreekStapler 2023-01-25 23:10:53 +01:00
parent 7561a74793
commit 660e711b17
1 changed files with 21 additions and 4 deletions

View File

@ -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);