commit:     94809f6d2e1db71b7444748d8561a25dab6df07b
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 25 14:21:20 2025 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Aug 25 14:21:20 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=94809f6d

q: report cache size in verbose mode

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 q.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/q.c b/q.c
index 8629e03..76f607d 100644
--- a/q.c
+++ b/q.c
@@ -27,6 +27,7 @@
 #include "atom.h"
 #include "basename.h"
 #include "eat_file.h"
+#include "human_readable.h"
 #include "rmspace.h"
 #include "scandirat.h"
 #include "tree.h"
@@ -745,6 +746,7 @@ int q_main(int argc, char **argv)
                ssize_t               rlen;
                int                   dfd;
                int                   tfd;
+               int                   fd;
 
                memset(&qcctx, 0, sizeof(qcctx));
 
@@ -778,10 +780,11 @@ int q_main(int argc, char **argv)
 
                        /* ensure we can actually write the new cache */
                        mkdir_p_at(t->tree_fd, "metadata", 0755);
+                       fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC);
 
                        a = archive_write_new();
                        archive_write_set_format_ustar(a);  /* GLEP-78, just to 
be safe */
-                       archive_write_open_filename(a, buf);
+                       archive_write_open_fd(a, fd);
 
                        qcctx.buildtime = time(NULL);
 
@@ -872,9 +875,22 @@ int q_main(int argc, char **argv)
                        /* cleanup repo archive */
                        close(tfd);
 
-                       tree_close(t);
                        archive_write_close(a);
                        archive_write_free(a);
+
+                       if (verbose) {
+                               if (fstat(fd, &st) < 0)
+                                       warnp("could not stat produced 
archive");
+                               else
+                                       printf("%s%s%s: %s%siB%s\n",
+                                                  GREEN, t->repo == NULL ? 
"???" : t->repo, NORM,
+                                                  RED, 
make_human_readable_str(st.st_size,
+                                                                               
                                1, 0), NORM);
+                       }
+
+                       fchmod(fd, 0644);
+                       close(fd);
+                       tree_close(t);
                }
 
                free(qcctx.cbuf);

Reply via email to