]> git.ipfire.org Git - pakfire.git/commitdiff
repos: Add filesize to metadata
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 2 Feb 2025 15:00:12 +0000 (15:00 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 2 Feb 2025 15:00:12 +0000 (15:00 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/repo.c

index 53199aa8b6e8343a720bc6240b614e8961483635..a5e020a492e9ac6c14521678dc97a6f260397a11 100644 (file)
@@ -1975,9 +1975,18 @@ static int pakfire_repo_metadata_add_file(struct pakfire_repo* self,
        struct json_object* chksums = NULL;
        char filename[PATH_MAX];
        char* hexdigest = NULL;
+       struct stat st = {};
        int digest;
        int r;
 
+       // Stat the file
+       r = stat(path, &st);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not stat %s: %m\n", path);
+               r = -errno;
+               goto ERROR;
+       }
+
        // Make the filename
        r = pakfire_path_basename(filename, path);
        if (r < 0)
@@ -2010,6 +2019,11 @@ static int pakfire_repo_metadata_add_file(struct pakfire_repo* self,
        if (r < 0)
                goto ERROR;
 
+       // Add the filesize
+       r = pakfire_json_add_uint64(file, "size", st.st_size);
+       if (r < 0)
+               goto ERROR;
+
        // Add checksums
        r = pakfire_json_add_object(file, "chksums", &chksums);
        if (r < 0)