refactor: Added SHA256 to package description file.

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

View File

@ -120,6 +120,14 @@ Pkg *package_read_archive(const char *pkg_path) {
return pkg; 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) { char *package_to_description(Pkg *pkg) {
PkgInfo *pkg_info = pkg->info; PkgInfo *pkg_info = pkg->info;
@ -142,7 +150,16 @@ char *package_to_description(Pkg *pkg) {
ADD_ARRAY("\n\n%%GROUPS%%\n%s", groups); ADD_ARRAY("\n\n%%GROUPS%%\n%s", groups);
ADD_STRING("\n\n%%CSIZE%%\n%ld", csize); ADD_STRING("\n\n%%CSIZE%%\n%ld", csize);
ADD_STRING("\n\n%%ISIZE%%\n%ld", size); 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_STRING("\n\n%%URL%%\n%s", url);
ADD_ARRAY("\n\n%%LICENSE%%\n%s", licenses); ADD_ARRAY("\n\n%%LICENSE%%\n%s", licenses);
ADD_STRING("\n\n%%ARCH%%\n%s", arch); ADD_STRING("\n\n%%ARCH%%\n%s", arch);