commit:     dcec34fcf04c0399efc466adf770d60dc145129f
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Mon Feb 22 17:49:25 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Mon Feb 22 17:49:25 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=dcec34fc

qsize: change interface to operate on atoms

We also drop the --all flag as it's now the default behavior.
If no atoms are specified, we just check everything.

 man/qsize.1 |  5 +----
 qsize.c     | 49 ++++++++++++++++++++++++++++++++-----------------
 2 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/man/qsize.1 b/man/qsize.1
index ca6a352..af32869 100644
--- a/man/qsize.1
+++ b/man/qsize.1
@@ -1,4 +1,4 @@
-.TH qsize "1" "Mar 2014" "Gentoo Foundation" "qsize"
+.TH qsize "1" "Feb 2016" "Gentoo Foundation" "qsize"
 .SH NAME
 qsize \- calculate size usage
 .SH SYNOPSIS
@@ -11,9 +11,6 @@ qsize \- calculate size usage
 \fB\-f\fR, \fB\-\-filesystem\fR
 Show size used on disk
 .TP
-\fB\-a\fR, \fB\-\-all\fR
-Size all installed packages
-.TP
 \fB\-s\fR, \fB\-\-sum\fR
 Include a summary
 .TP

diff --git a/qsize.c b/qsize.c
index 3a11842..7a40141 100644
--- a/qsize.c
+++ b/qsize.c
@@ -8,10 +8,9 @@
 
 #ifdef APPLET_qsize
 
-#define QSIZE_FLAGS "fasSmkbi:" COMMON_FLAGS
+#define QSIZE_FLAGS "fsSmkbi:" COMMON_FLAGS
 static struct option const qsize_long_opts[] = {
        {"filesystem", no_argument, NULL, 'f'},
-       {"all",        no_argument, NULL, 'a'},
        {"sum",        no_argument, NULL, 's'},
        {"sum-only",   no_argument, NULL, 'S'},
        {"megabytes",  no_argument, NULL, 'm'},
@@ -22,7 +21,6 @@ static struct option const qsize_long_opts[] = {
 };
 static const char * const qsize_opts_help[] = {
        "Show size used on disk",
-       "Size all installed packages",
        "Include a summary",
        "Show just the summary",
        "Display size in megabytes",
@@ -39,7 +37,6 @@ int qsize_main(int argc, char **argv)
        q_vdb_cat_ctx *cat_ctx;
        q_vdb_pkg_ctx *pkg_ctx;
        size_t i;
-       char search_all = 0;
        struct stat st;
        char fs_size = 0, summary = 0, summary_only = 0;
        size_t num_all_files, num_all_nonfiles, num_all_ignored;
@@ -50,13 +47,14 @@ int qsize_main(int argc, char **argv)
        size_t buflen;
        char *buf;
        char filename[_Q_PATH_MAX], *filename_root;
+       depend_atom *atom;
+       DECLARE_ARRAY(atoms);
        DECLARE_ARRAY(ignore_regexp);
 
        while ((i = GETOPT_LONG(QSIZE, qsize, "")) != -1) {
                switch (i) {
                COMMON_GETOPTS_CASES(qsize)
                case 'f': fs_size = 1; break;
-               case 'a': search_all = 1; break;
                case 's': summary = 1; break;
                case 'S': summary = summary_only = 1; break;
                case 'm': disp_units = MEGABYTE; str_disp_units = "MiB"; break;
@@ -70,8 +68,16 @@ int qsize_main(int argc, char **argv)
                }
                }
        }
-       if ((argc == optind) && !search_all)
-               qsize_usage(EXIT_FAILURE);
+
+       argc -= optind;
+       argv += optind;
+       for (i = 0; i < argc; ++i) {
+               atom = atom_explode(argv[i]);
+               if (!atom)
+                       warn("invalid atom: %s", argv[i]);
+               else
+                       xarraypush_ptr(atoms, atom);
+       }
 
        num_all_bytes = num_all_files = num_all_nonfiles = num_all_ignored = 0;
 
@@ -91,18 +97,24 @@ int qsize_main(int argc, char **argv)
                while ((pkg_ctx = q_vdb_next_pkg(cat_ctx))) {
                        const char *pkgname = pkg_ctx->name;
                        FILE *fp;
+                       bool showit = false;
+
                        /* see if this cat/pkg is requested */
-                       if (!search_all) {
-                               for (i = optind; i < argc; ++i) {
-                                       snprintf(buf, buflen, "%s/%s", catname, 
pkgname);
-                                       if (rematch(argv[i], buf, REG_EXTENDED) 
== 0)
+                       if (array_cnt(atoms)) {
+                               depend_atom *qatom;
+
+                               snprintf(buf, buflen, "%s/%s", catname, 
pkgname);
+                               qatom = atom_explode(buf);
+                               array_for_each(atoms, i, atom)
+                                       if (atom_compare(atom, qatom) == EQUAL) 
{
+                                               showit = true;
                                                break;
-                                       if (rematch(argv[i], pkgname, 
REG_EXTENDED) == 0)
-                                               break;
-                               }
-                               if (i == argc)
-                                       goto next_pkg;
-                       }
+                                       }
+                               atom_implode(qatom);
+                       } else
+                               showit = true;
+                       if (!showit)
+                               goto next_pkg;
 
                        if ((fp = q_vdb_pkg_fopenat_ro(pkg_ctx, "CONTENTS")) == 
NULL)
                                goto next_pkg;
@@ -178,6 +190,9 @@ int qsize_main(int argc, char **argv)
                               decimal_point,
                               (unsigned 
long)(((num_all_bytes%MEGABYTE)*1000)/MEGABYTE));
        }
+       array_for_each(atoms, i, atom)
+               atom_implode(atom);
+       xarrayfree_int(atoms);
        xarrayfree(ignore_regexp);
        return EXIT_SUCCESS;
 }

Reply via email to