* [gentoo-commits] gentoo-projects commit in portage-utils: qfile.c
@ 2009-10-18 17:28 Ned Ludd (solar)
0 siblings, 0 replies; 11+ messages in thread
From: Ned Ludd (solar) @ 2009-10-18 17:28 UTC (permalink / raw
To: gentoo-commits
solar 09/10/18 17:28:30
Modified: qfile.c
Log:
- New option. -S/Display installed packages with slots
Revision Changes Path
1.46 portage-utils/qfile.c
file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/portage-utils/qfile.c?rev=1.46&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/portage-utils/qfile.c?rev=1.46&content-type=text/plain
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/portage-utils/qfile.c?r1=1.45&r2=1.46
Index: qfile.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- qfile.c 24 May 2007 14:47:18 -0000 1.45
+++ qfile.c 18 Oct 2009 17:28:30 -0000 1.46
@@ -1,7 +1,7 @@
/*
* Copyright 2005-2007 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.45 2007/05/24 14:47:18 solar Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.46 2009/10/18 17:28:30 solar Exp $
*
* Copyright 2005-2007 Ned Ludd - <solar@gentoo.org>
* Copyright 2005-2007 Mike Frysinger - <vapier@gentoo.org>
@@ -13,7 +13,7 @@
#define QFILE_DEFAULT_MAX_ARGS 5000
#define QFILE_DEFAULT_MAX_ARGS_STR "5000"
-#define QFILE_FLAGS "ef:m:oRx:" COMMON_FLAGS
+#define QFILE_FLAGS "ef:m:oRx:S" COMMON_FLAGS
static struct option const qfile_long_opts[] = {
{"exact", no_argument, NULL, 'e'},
{"from", a_argument, NULL, 'f'},
@@ -21,6 +21,7 @@
{"orphans", no_argument, NULL, 'o'},
{"root-prefix", no_argument, NULL, 'R'},
{"exclude", a_argument, NULL, 'x'},
+ {"slots", no_argument, NULL, 'S'},
COMMON_LONG_OPTS
};
static const char *qfile_opts_help[] = {
@@ -30,9 +31,10 @@
"List orphan files",
"Assume arguments are already prefixed by $ROOT",
"Don't look in package <arg>",
+ "Display installed packages with slots",
COMMON_OPTS_HELP
};
-static char qfile_rcsid[] = "$Id: qfile.c,v 1.45 2007/05/24 14:47:18 solar Exp $";
+static char qfile_rcsid[] = "$Id: qfile.c,v 1.46 2009/10/18 17:28:30 solar Exp $";
#define qfile_usage(ret) usage(ret, QFILE_FLAGS, qfile_long_opts, qfile_opts_help, lookup_applet_idx("qfile"))
#define qfile_is_prefix(path, prefix, prefix_length) \
@@ -53,6 +55,8 @@
char *exclude_slot;
} qfile_args_t;
+char slotted = 0;
+
void qfile(char *, const char *, qfile_args_t *);
void qfile(char *path, const char *root, qfile_args_t *args)
{
@@ -213,13 +217,26 @@
continue;
if (non_orphans == NULL) {
+ char pkgslot[126];
+
if (atom == NULL && (atom = atom_explode(pkg)) == NULL) {
warn("invalid atom %s", pkg);
continue;
}
-
- printf("%s%s/%s%s%s", BOLD, atom->CATEGORY, BLUE,
- (exact ? dentry->d_name : atom->PN), NORM);
+ if (slotted) {
+ FILE *pkgfp = NULL;
+ strcpy(pkgslot, "");
+ xasprintf(&p, "%s/%s/SLOT", path, dentry->d_name);
+ if ((pkgfp = fopen(p, "r")) != NULL) {
+ fgets(pkgslot, sizeof(pkgslot), pkgfp);
+ rmspace(pkgslot);
+ fclose(pkgfp);
+ }
+ free(p);
+ }
+ printf("%s%s/%s%s%s%s%s", BOLD, atom->CATEGORY, BLUE,
+ (exact ? dentry->d_name : atom->PN),
+ (slotted ? ":" : ""), (slotted ? pkgslot : ""), NORM);
if (quiet)
puts("");
else if (root != NULL)
@@ -494,6 +511,7 @@
while ((i = GETOPT_LONG(QFILE, qfile, "")) != -1) {
switch (i) {
COMMON_GETOPTS_CASES(qfile)
+ case 'S': slotted = 1; break;
case 'e': exact = 1; break;
case 'f':
if (args_file != NULL) {
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo-projects commit in portage-utils: qfile.c
@ 2010-01-16 21:31 Mike Frysinger (vapier)
0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2010-01-16 21:31 UTC (permalink / raw
To: gentoo-commits
vapier 10/01/16 21:31:57
Modified: qfile.c
Log:
only warn and avoid exiting if we find a file in the pkg db #301221 by Petteri Räty
Revision Changes Path
1.50 portage-utils/qfile.c
file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/portage-utils/qfile.c?rev=1.50&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/portage-utils/qfile.c?rev=1.50&content-type=text/plain
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/portage-utils/qfile.c?r1=1.49&r2=1.50
Index: qfile.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- qfile.c 13 Jan 2010 19:01:34 -0000 1.49
+++ qfile.c 16 Jan 2010 21:31:57 -0000 1.50
@@ -1,7 +1,7 @@
/*
* Copyright 2005-2007 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.49 2010/01/13 19:01:34 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.50 2010/01/16 21:31:57 vapier Exp $
*
* Copyright 2005-2007 Ned Ludd - <solar@gentoo.org>
* Copyright 2005-2007 Mike Frysinger - <vapier@gentoo.org>
@@ -34,7 +34,7 @@
"Display installed packages with slots",
COMMON_OPTS_HELP
};
-static char qfile_rcsid[] = "$Id: qfile.c,v 1.49 2010/01/13 19:01:34 vapier Exp $";
+static char qfile_rcsid[] = "$Id: qfile.c,v 1.50 2010/01/16 21:31:57 vapier Exp $";
#define qfile_usage(ret) usage(ret, QFILE_FLAGS, qfile_long_opts, qfile_opts_help, lookup_applet_idx("qfile"))
#define qfile_is_prefix(path, prefix, prefix_length) \
@@ -78,9 +78,11 @@
char *bn_firstchars = args->bn_firstchars;
short *non_orphans = args->non_orphans;
- xchdir(path);
- if ((dir = opendir(".")) == NULL)
+ if ((dir = opendir(path)) == NULL) {
+ warnp("opendir(%s) failed", path);
return;
+ }
+ xchdir(path);
while ((dentry = readdir(dir))) {
if (dentry->d_name[0] == '.')
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo-projects commit in portage-utils: qfile.c
@ 2011-03-01 6:11 Mike Frysinger (vapier)
0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2011-03-01 6:11 UTC (permalink / raw
To: gentoo-commits
vapier 11/03/01 06:11:54
Modified: qfile.c
Log:
make sure ROOT works properly
Revision Changes Path
1.56 portage-utils/qfile.c
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.56&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.56&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?r1=1.55&r2=1.56
Index: qfile.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- qfile.c 21 Feb 2011 07:33:21 -0000 1.55
+++ qfile.c 1 Mar 2011 06:11:54 -0000 1.56
@@ -1,7 +1,7 @@
/*
* Copyright 2005-2010 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.55 2011/02/21 07:33:21 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.56 2011/03/01 06:11:54 vapier Exp $
*
* Copyright 2005-2010 Ned Ludd - <solar@gentoo.org>
* Copyright 2005-2010 Mike Frysinger - <vapier@gentoo.org>
@@ -34,7 +34,7 @@
"Display installed packages with slots",
COMMON_OPTS_HELP
};
-static const char qfile_rcsid[] = "$Id: qfile.c,v 1.55 2011/02/21 07:33:21 vapier Exp $";
+static const char qfile_rcsid[] = "$Id: qfile.c,v 1.56 2011/03/01 06:11:54 vapier Exp $";
#define qfile_usage(ret) usage(ret, QFILE_FLAGS, qfile_long_opts, qfile_opts_help, lookup_applet_idx("qfile"))
#define qfile_is_prefix(path, prefix, prefix_length) \
@@ -488,7 +488,7 @@
char *p;
short search_orphans = 0;
short assume_root_prefix = 0;
- char *root_prefix = NULL;
+ char *root_prefix;
char *exclude_pkg_arg = NULL;
qfile_args_t *qfile_args = NULL;
int qargc = 0;
@@ -497,7 +497,7 @@
FILE *args_file = NULL;
int max_args = QFILE_DEFAULT_MAX_ARGS;
size_t buflen;
- char *buf = NULL;
+ char *buf;
DBG("argc=%d argv[0]=%s argv[1]=%s",
argc, argv[0], argc > 1 ? argv[1] : "NULL?");
@@ -552,8 +552,10 @@
if ((args_file == NULL) && (max_args != QFILE_DEFAULT_MAX_ARGS))
warn("--max-args is only used when reading arguments from a file (with -f)");
- xchdir(portroot);
- xchdir(portvdb);
+ xasprintf(&buf, "%s/%s", portroot, portvdb);
+ xchdir(buf);
+ free(buf);
+ buf = NULL;
/* Get a copy of $ROOT, with no trailing slash
* (this one is just for qfile(...) output)
@@ -655,8 +657,7 @@
free(qfile_args);
}
- if (root_prefix != NULL)
- free(root_prefix);
+ free(root_prefix);
return (found ? EXIT_SUCCESS : EXIT_FAILURE);
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo-projects commit in portage-utils: qfile.c
@ 2011-03-02 2:41 Mike Frysinger (vapier)
0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2011-03-02 2:41 UTC (permalink / raw
To: gentoo-commits
vapier 11/03/02 02:41:08
Modified: qfile.c
Log:
fix uninitialized warning after previous commit
Revision Changes Path
1.57 portage-utils/qfile.c
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.57&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.57&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?r1=1.56&r2=1.57
Index: qfile.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- qfile.c 1 Mar 2011 06:11:54 -0000 1.56
+++ qfile.c 2 Mar 2011 02:41:08 -0000 1.57
@@ -1,7 +1,7 @@
/*
* Copyright 2005-2010 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.56 2011/03/01 06:11:54 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.57 2011/03/02 02:41:08 vapier Exp $
*
* Copyright 2005-2010 Ned Ludd - <solar@gentoo.org>
* Copyright 2005-2010 Mike Frysinger - <vapier@gentoo.org>
@@ -34,7 +34,7 @@
"Display installed packages with slots",
COMMON_OPTS_HELP
};
-static const char qfile_rcsid[] = "$Id: qfile.c,v 1.56 2011/03/01 06:11:54 vapier Exp $";
+static const char qfile_rcsid[] = "$Id: qfile.c,v 1.57 2011/03/02 02:41:08 vapier Exp $";
#define qfile_usage(ret) usage(ret, QFILE_FLAGS, qfile_long_opts, qfile_opts_help, lookup_applet_idx("qfile"))
#define qfile_is_prefix(path, prefix, prefix_length) \
@@ -488,7 +488,7 @@
char *p;
short search_orphans = 0;
short assume_root_prefix = 0;
- char *root_prefix;
+ char *root_prefix = NULL;
char *exclude_pkg_arg = NULL;
qfile_args_t *qfile_args = NULL;
int qargc = 0;
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo-projects commit in portage-utils: qfile.c
@ 2011-10-02 22:08 Mike Frysinger (vapier)
0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2011-10-02 22:08 UTC (permalink / raw
To: gentoo-commits
vapier 11/10/02 22:08:49
Modified: qfile.c
Log:
delete unused variable
Revision Changes Path
1.58 portage-utils/qfile.c
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.58&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.58&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?r1=1.57&r2=1.58
Index: qfile.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- qfile.c 2 Mar 2011 02:41:08 -0000 1.57
+++ qfile.c 2 Oct 2011 22:08:49 -0000 1.58
@@ -1,7 +1,7 @@
/*
* Copyright 2005-2010 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.57 2011/03/02 02:41:08 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.58 2011/10/02 22:08:49 vapier Exp $
*
* Copyright 2005-2010 Ned Ludd - <solar@gentoo.org>
* Copyright 2005-2010 Mike Frysinger - <vapier@gentoo.org>
@@ -34,7 +34,7 @@
"Display installed packages with slots",
COMMON_OPTS_HELP
};
-static const char qfile_rcsid[] = "$Id: qfile.c,v 1.57 2011/03/02 02:41:08 vapier Exp $";
+static const char qfile_rcsid[] = "$Id: qfile.c,v 1.58 2011/10/02 22:08:49 vapier Exp $";
#define qfile_usage(ret) usage(ret, QFILE_FLAGS, qfile_long_opts, qfile_opts_help, lookup_applet_idx("qfile"))
#define qfile_is_prefix(path, prefix, prefix_length) \
@@ -493,7 +493,6 @@
qfile_args_t *qfile_args = NULL;
int qargc = 0;
char **qargv = NULL;
- short done = 0;
FILE *args_file = NULL;
int max_args = QFILE_DEFAULT_MAX_ARGS;
size_t buflen;
@@ -568,7 +567,6 @@
if (args_file == NULL) {
qargc = argc - optind;
qargv = argv + optind;
- done = 1;
} else {
qargv = xcalloc(max_args, sizeof(char*));
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo-projects commit in portage-utils: qfile.c
@ 2011-12-18 8:01 Mike Frysinger (vapier)
0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2011-12-18 8:01 UTC (permalink / raw
To: gentoo-commits
vapier 11/12/18 08:01:03
Modified: qfile.c
Log:
push down "exact" from global scope to per-applet state
Revision Changes Path
1.59 portage-utils/qfile.c
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.59&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.59&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?r1=1.58&r2=1.59
Index: qfile.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- qfile.c 2 Oct 2011 22:08:49 -0000 1.58
+++ qfile.c 18 Dec 2011 08:01:03 -0000 1.59
@@ -1,7 +1,7 @@
/*
* Copyright 2005-2010 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.58 2011/10/02 22:08:49 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.59 2011/12/18 08:01:03 vapier Exp $
*
* Copyright 2005-2010 Ned Ludd - <solar@gentoo.org>
* Copyright 2005-2010 Mike Frysinger - <vapier@gentoo.org>
@@ -34,7 +34,7 @@
"Display installed packages with slots",
COMMON_OPTS_HELP
};
-static const char qfile_rcsid[] = "$Id: qfile.c,v 1.58 2011/10/02 22:08:49 vapier Exp $";
+static const char qfile_rcsid[] = "$Id: qfile.c,v 1.59 2011/12/18 08:01:03 vapier Exp $";
#define qfile_usage(ret) usage(ret, QFILE_FLAGS, qfile_long_opts, qfile_opts_help, lookup_applet_idx("qfile"))
#define qfile_is_prefix(path, prefix, prefix_length) \
@@ -55,7 +55,8 @@
char *exclude_slot;
} qfile_args_t;
-char slotted = 0;
+bool qfile_slotted = false;
+bool qfile_exact = false;
/*
* We assume the people calling us have chdir(/var/db/pkg) and so
@@ -228,7 +229,7 @@
warn("invalid atom %s", pkg);
continue;
}
- if (slotted) {
+ if (qfile_slotted) {
strcpy(p, "/SLOT");
eat_file(pkg, pkgslot+1, sizeof(pkgslot)-1);
rmspace(pkgslot+1);
@@ -237,7 +238,7 @@
} else
*pkgslot = '\0';
printf("%s%s/%s%s%s%s", BOLD, atom->CATEGORY, BLUE,
- (exact ? dentry->d_name : atom->PN),
+ (qfile_exact ? dentry->d_name : atom->PN),
pkgslot, NORM);
if (quiet)
puts("");
@@ -504,8 +505,8 @@
while ((i = GETOPT_LONG(QFILE, qfile, "")) != -1) {
switch (i) {
COMMON_GETOPTS_CASES(qfile)
- case 'S': slotted = 1; break;
- case 'e': exact = 1; break;
+ case 'S': qfile_slotted = true; break;
+ case 'e': qfile_exact = true; break;
case 'f':
if (args_file != NULL) {
warn("Don't use -f twice!");
@@ -544,7 +545,7 @@
break;
}
}
- if (!exact && verbose) exact++;
+ if (!qfile_exact && verbose) qfile_exact = true;
if ((argc == optind) && (args_file == NULL))
qfile_usage(EXIT_FAILURE);
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo-projects commit in portage-utils: qfile.c
@ 2012-01-16 1:12 Mike Frysinger (vapier)
0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2012-01-16 1:12 UTC (permalink / raw
To: gentoo-commits
vapier 12/01/16 01:12:31
Modified: qfile.c
Log:
kill useless set of paren
Revision Changes Path
1.60 portage-utils/qfile.c
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.60&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.60&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?r1=1.59&r2=1.60
Index: qfile.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- qfile.c 18 Dec 2011 08:01:03 -0000 1.59
+++ qfile.c 16 Jan 2012 01:12:31 -0000 1.60
@@ -1,7 +1,7 @@
/*
* Copyright 2005-2010 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.59 2011/12/18 08:01:03 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.60 2012/01/16 01:12:31 vapier Exp $
*
* Copyright 2005-2010 Ned Ludd - <solar@gentoo.org>
* Copyright 2005-2010 Mike Frysinger - <vapier@gentoo.org>
@@ -34,7 +34,7 @@
"Display installed packages with slots",
COMMON_OPTS_HELP
};
-static const char qfile_rcsid[] = "$Id: qfile.c,v 1.59 2011/12/18 08:01:03 vapier Exp $";
+static const char qfile_rcsid[] = "$Id: qfile.c,v 1.60 2012/01/16 01:12:31 vapier Exp $";
#define qfile_usage(ret) usage(ret, QFILE_FLAGS, qfile_long_opts, qfile_opts_help, lookup_applet_idx("qfile"))
#define qfile_is_prefix(path, prefix, prefix_length) \
@@ -328,7 +328,7 @@
/* Try to get $PWD. Must be absolute, with no trailing slash. */
if ((pwd = getenv("PWD")) != NULL && pwd[0] == '/') {
pwd = xstrdup(pwd);
- if ((pwd[strlen(pwd) - 1] == '/'))
+ if (pwd[strlen(pwd) - 1] == '/')
pwd[strlen(pwd) - 1] = '\0';
} else
pwd = NULL;
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo-projects commit in portage-utils: qfile.c
@ 2012-10-28 8:57 Mike Frysinger (vapier)
0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2012-10-28 8:57 UTC (permalink / raw
To: gentoo-commits
vapier 12/10/28 08:57:18
Modified: qfile.c
Log:
qfile: push more of qfile_args_t into qfile_opt_state as the former is less volatile
Revision Changes Path
1.63 portage-utils/qfile.c
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.63&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.63&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?r1=1.62&r2=1.63
Index: qfile.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -r1.62 -r1.63
--- qfile.c 28 Oct 2012 07:56:51 -0000 1.62
+++ qfile.c 28 Oct 2012 08:57:18 -0000 1.63
@@ -1,7 +1,7 @@
/*
* Copyright 2005-2010 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.62 2012/10/28 07:56:51 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.63 2012/10/28 08:57:18 vapier Exp $
*
* Copyright 2005-2010 Ned Ludd - <solar@gentoo.org>
* Copyright 2005-2010 Mike Frysinger - <vapier@gentoo.org>
@@ -34,7 +34,7 @@
"Display installed packages with slots",
COMMON_OPTS_HELP
};
-static const char qfile_rcsid[] = "$Id: qfile.c,v 1.62 2012/10/28 07:56:51 vapier Exp $";
+static const char qfile_rcsid[] = "$Id: qfile.c,v 1.63 2012/10/28 08:57:18 vapier Exp $";
#define qfile_usage(ret) usage(ret, QFILE_FLAGS, qfile_long_opts, qfile_opts_help, lookup_applet_idx("qfile"))
#define qfile_is_prefix(path, prefix, prefix_length) \
@@ -48,20 +48,24 @@
char **basenames;
char **dirnames;
char **realdirnames;
- char *bn_firstchars;
short *non_orphans;
- char *real_root;
- char *exclude_pkg;
- char *exclude_slot;
} qfile_args_t;
struct qfile_opt_state {
char *buf;
size_t buflen;
- qfile_args_t *args;
+ qfile_args_t args;
char *root;
+ char *pwd;
+ char *real_root;
+ size_t real_root_len;
+ char *exclude_pkg;
+ char *exclude_slot;
+ depend_atom *exclude_atom;
bool slotted;
bool exact;
+ bool orphans;
+ bool assume_root_prefix;
};
/*
@@ -73,18 +77,17 @@
struct qfile_opt_state *state = priv;
const char *catname = pkg_ctx->cat_ctx->name;
const char *pkgname = pkg_ctx->name;
- qfile_args_t *args = state->args;
+ qfile_args_t *args = &state->args;
FILE *fp;
const char *base;
char pkg[_Q_PATH_MAX];
depend_atom *atom = NULL;
int i, path_ok;
char bn_firstchar;
- char *real_root = args->real_root;
+ char *real_root = state->real_root;
char **base_names = args->basenames;
char **dir_names = args->dirnames;
char **real_dir_names = args->realdirnames;
- char *bn_firstchars = args->bn_firstchars;
short *non_orphans = args->non_orphans;
int found = 0;
@@ -93,25 +96,26 @@
/* If exclude_pkg is not NULL, check it. We are looking for files
* collisions, and must exclude one package.
*/
- if (args->exclude_pkg) {
- if (strcmp(args->exclude_pkg, pkg) == 0)
- goto check_pkg_slot; /* CAT/PF matches */
- if (strcmp(args->exclude_pkg, pkg_ctx->name) == 0)
- goto check_pkg_slot; /* PF matches */
- if ((atom = atom_explode(pkg)) == NULL) {
- warn("invalid atom %s", pkg);
+ if (state->exclude_pkg) {
+ /* see if CATEGORY matches */
+ if (state->exclude_atom->CATEGORY &&
+ strcmp(state->exclude_atom->CATEGORY, catname))
goto dont_skip_pkg;
+ atom = atom_explode(pkg);
+ if (state->exclude_atom->PVR) {
+ /* see if PVR is exact match */
+ if (strcmp(state->exclude_atom->PVR, atom->PVR))
+ goto dont_skip_pkg;
+ } else {
+ /* see if PN is exact match */
+ if (strcmp(state->exclude_atom->PN, atom->PN))
+ goto dont_skip_pkg;
}
- snprintf(state->buf, state->buflen, "%s/%s", atom->CATEGORY, atom->PN);
- if (strncmp(args->exclude_pkg, state->buf, state->buflen) != 0
- && strcmp(args->exclude_pkg, atom->PN) != 0)
- goto dont_skip_pkg; /* "(CAT/)?PN" doesn't match */
- check_pkg_slot: /* Also compare slots, if any was specified */
- if (args->exclude_slot == NULL)
+ if (state->exclude_slot == NULL)
goto qlist_done; /* "(CAT/)?(PN|PF)" matches, and no SLOT specified */
eat_file_at(pkg_ctx->fd, "SLOT", state->buf, state->buflen);
rmspace(state->buf);
- if (strcmp(args->exclude_slot, state->buf) == 0)
+ if (strcmp(state->exclude_slot, state->buf) == 0)
goto qlist_done; /* "(CAT/)?(PN|PF):SLOT" matches */
}
dont_skip_pkg: /* End of the package exclusion tests. */
@@ -140,7 +144,10 @@
continue;
path_ok = (dir_names[i] == NULL && real_dir_names[i] == NULL);
- if (bn_firstchar != bn_firstchars[i]
+ /* For optimization of qfile(), we also give it an array of the first char
+ * of each basename. This way we avoid numerous strcmp() calls.
+ */
+ if (bn_firstchar != base_names[i][0]
|| strcmp(base, base_names[i]))
continue;
@@ -168,7 +175,7 @@
else if (real_root[0]) {
char rpath[_Q_PATH_MAX + 1], *_rpath;
char *fullpath;
- size_t real_root_len = strlen(real_root);
+ size_t real_root_len = state->real_root_len;
xasprintf(&fullpath, "%s%s", real_root, e->name);
fullpath[real_root_len + dirname_len] = '\0';
@@ -251,60 +258,26 @@
free(qfile_args->basenames);
free(qfile_args->dirnames);
free(qfile_args->realdirnames);
- free(qfile_args->bn_firstchars);
free(qfile_args->non_orphans);
- free(qfile_args->real_root);
- free(qfile_args->exclude_pkg);
- /* don't free qfile_args->exclude_slot, it's the same chunk */
memset(qfile_args, 0, sizeof(qfile_args_t));
}
_q_static int
-prepare_qfile_args(const int argc, const char **argv,
- bool assume_root_prefix, bool search_orphans,
- const char *exclude_pkg_arg, qfile_args_t *qfile_args)
+prepare_qfile_args(const int argc, const char **argv, struct qfile_opt_state *state)
{
+ qfile_args_t *args = &state->args;
int i;
int nb_of_queries = argc;
- char *pwd = NULL;
- int real_root_length;
- char *real_root = NULL;
+ char *pwd = state->pwd;
+ size_t real_root_len = state->real_root_len;
+ char *real_root = state->real_root;
char **basenames = NULL;
char **dirnames = NULL;
char **realdirnames = NULL;
- char *basenames_firstchars = NULL;
char tmppath[_Q_PATH_MAX+1];
char abspath[_Q_PATH_MAX+1];
- /* Try to get $PWD. Must be absolute, with no trailing slash. */
- if ((pwd = getenv("PWD")) != NULL && pwd[0] == '/') {
- pwd = xstrdup(pwd);
- if (pwd[strlen(pwd) - 1] == '/')
- pwd[strlen(pwd) - 1] = '\0';
- } else
- pwd = NULL;
-
- /* Get realpath of $ROOT, with no trailing slash */
- if (portroot[0] == '/')
- strncpy(tmppath, portroot, _Q_PATH_MAX);
- else if (pwd)
- snprintf(tmppath, _Q_PATH_MAX, "%s/%s", pwd, portroot);
- else {
- free(pwd);
- warn("Could not get absolute path for ROOT (\"%s\"), because of missing or not absolute $PWD", tmppath);
- return -1;
- }
- if (realpath(tmppath, abspath) == NULL) {
- free(pwd);
- warnp("Could not read real path of ROOT (\"%s\")", tmppath);
- return -1;
- }
- if (strlen(abspath) == 1)
- abspath[0] = '\0';
- real_root = xstrdup(abspath);
- real_root_length = strlen(real_root);
-
/* For each argument, we store its basename, its absolute dirname,
* and the realpath of its dirname. Dirnames and their realpaths
* are stored without their $ROOT prefix, but $ROOT is used when
@@ -313,10 +286,6 @@
basenames = xcalloc(argc, sizeof(char*));
dirnames = xcalloc(argc, sizeof(char*));
realdirnames = xcalloc(argc, sizeof(char*));
- /* For optimization of qfile(), we also give it an array of the first char
- * of each basename. This way we avoid numerous strcmp() calls.
- */
- basenames_firstchars = xcalloc(argc, sizeof(char));
for (i = 0; i < argc; ++i) {
/* Record basename, but if it is ".", ".." or "/" */
@@ -327,7 +296,6 @@
&& strncmp(tmppath, "/", strlen(tmppath))))
{
basenames[i] = xstrdup(tmppath);
- basenames_firstchars[i] = basenames[i][0];
/* If there is no "/" in the argument, then it's over.
* (we are searching a simple file name)
*/
@@ -337,12 +305,12 @@
/* Make sure we have an absolute path available (with "realpath(ROOT)" prefix) */
if (argv[i][0] == '/') {
- if (assume_root_prefix)
+ if (state->assume_root_prefix)
strncpy(abspath, argv[i], _Q_PATH_MAX);
else
snprintf(abspath, _Q_PATH_MAX, "%s%s", real_root, argv[i]);
} else if (pwd) {
- if (assume_root_prefix)
+ if (state->assume_root_prefix)
snprintf(abspath, _Q_PATH_MAX, "%s/%s", pwd, argv[i]);
else
snprintf(abspath, _Q_PATH_MAX, "%s%s/%s", real_root, pwd, argv[i]);
@@ -358,9 +326,9 @@
*/
strncpy(tmppath, abspath, _Q_PATH_MAX);
strncpy(abspath, dirname(tmppath), _Q_PATH_MAX);
- if (abspath[real_root_length] == '\0')
+ if (abspath[real_root_len] == '\0')
strncat(abspath, "/", 1);
- dirnames[i] = xstrdup(abspath + real_root_length);
+ dirnames[i] = xstrdup(abspath + real_root_len);
if (realpath(abspath, tmppath) == NULL) {
if (verbose) {
warnp("Could not read real path of \"%s\"", abspath);
@@ -368,14 +336,14 @@
}
continue;
}
- if (!qfile_is_prefix(tmppath, real_root, real_root_length)) {
+ if (!qfile_is_prefix(tmppath, real_root, real_root_len)) {
warn("Real path of \"%s\" is not under ROOT: %s", abspath, tmppath);
goto skip_query_item;
}
- if (tmppath[real_root_length] == '\0')
+ if (tmppath[real_root_len] == '\0')
strncat(tmppath, "/", 1);
- if (strcmp(dirnames[i], tmppath + real_root_length))
- realdirnames[i] = xstrdup(tmppath + real_root_length);
+ if (strcmp(dirnames[i], tmppath + real_root_len))
+ realdirnames[i] = xstrdup(tmppath + real_root_len);
} else {
/* No basename means we are looking for something like "/foo/bar/.."
* Dirname is meaningless here, we can only get realpath of the full
@@ -385,17 +353,16 @@
warnp("Could not read real path of \"%s\"", abspath);
goto skip_query_item;
}
- if (!qfile_is_prefix(tmppath, real_root, real_root_length)) {
+ if (!qfile_is_prefix(tmppath, real_root, real_root_len)) {
warn("Real path of \"%s\" is not under ROOT: %s", abspath, tmppath);
goto skip_query_item;
}
strncpy(abspath, tmppath, _Q_PATH_MAX);
basenames[i] = xstrdup(basename(abspath));
- basenames_firstchars[i] = basenames[i][0];
strncpy(abspath, dirname(tmppath), _Q_PATH_MAX);
- if (tmppath[real_root_length] == '\0')
+ if (tmppath[real_root_len] == '\0')
strncat(tmppath, "/", 1);
- realdirnames[i] = xstrdup(abspath + real_root_length);
+ realdirnames[i] = xstrdup(abspath + real_root_len);
}
continue;
@@ -408,26 +375,13 @@
basenames[i] = dirnames[i] = realdirnames[i] = NULL;
}
- free(pwd);
+ args->basenames = basenames;
+ args->dirnames = dirnames;
+ args->realdirnames = realdirnames;
+ args->length = argc;
- qfile_args->real_root = real_root;
- qfile_args->basenames = basenames;
- qfile_args->dirnames = dirnames;
- qfile_args->realdirnames = realdirnames;
- qfile_args->bn_firstchars = basenames_firstchars;
- qfile_args->length = argc;
-
- if (search_orphans) {
- qfile_args->non_orphans = xcalloc(argc, sizeof(short));
- memset(qfile_args->non_orphans, 0, argc);
- }
-
- if (exclude_pkg_arg) {
- qfile_args->exclude_pkg = xstrdup(exclude_pkg_arg);
- if ((qfile_args->exclude_slot = strchr(qfile_args->exclude_pkg, ':')) != NULL)
- *qfile_args->exclude_slot++ = '\0';
- /* Maybe this should be atom-exploded instead (to check syntax, etc.) */
- }
+ if (state->orphans)
+ args->non_orphans = xcalloc(argc, sizeof(short));
return nb_of_queries;
}
@@ -438,12 +392,11 @@
.buflen = _Q_PATH_MAX,
.slotted = false,
.exact = false,
+ .orphans = false,
+ .assume_root_prefix = false,
};
int i, nb_of_queries, found = 0;
char *p;
- bool search_orphans = false;
- bool assume_root_prefix = false;
- char *exclude_pkg_arg = NULL;
int qargc = 0;
char **qargv = NULL;
FILE *args_file = NULL;
@@ -482,12 +435,17 @@
goto exit;
}
break;
- case 'o': search_orphans = true; break;
- case 'R': assume_root_prefix = true; break;
+ case 'o': state.orphans = true; break;
+ case 'R': state.assume_root_prefix = true; break;
case 'x':
- if (exclude_pkg_arg)
+ if (state.exclude_pkg)
err("--exclude can only be used once.");
- exclude_pkg_arg = optarg;
+ state.exclude_pkg = xstrdup(optarg);
+ if ((state.exclude_slot = strchr(state.exclude_pkg, ':')) != NULL)
+ *state.exclude_slot++ = '\0';
+ state.exclude_atom = atom_explode(optarg);
+ if (!state.exclude_atom)
+ err("invalid atom %s", optarg);
break;
}
}
@@ -509,8 +467,7 @@
}
state.buf = xmalloc(state.buflen);
- state.args = xzalloc(sizeof(qfile_args_t));
- if (assume_root_prefix) {
+ if (state.assume_root_prefix) {
/* Get a copy of $ROOT, with no trailing slash
* (this one is just for qfile(...) output)
*/
@@ -520,6 +477,30 @@
state.root[lastc] = '\0';
}
+ /* Try to get $PWD. Must be absolute, with no trailing slash. */
+ state.pwd = getcwd(state.buf, state.buflen);
+ if (state.pwd) {
+ size_t lastc = strlen(state.pwd) - 1;
+ state.pwd = xstrdup(state.pwd);
+ if (state.pwd[lastc] == '/')
+ state.pwd[lastc] = '\0';
+ }
+
+ /* Get realpath of $ROOT, with no trailing slash */
+ if (portroot[0] == '/')
+ p = realpath(portroot, NULL);
+ else if (state.pwd) {
+ snprintf(state.buf, state.buflen, "%s/%s", state.pwd, portroot);
+ p = realpath(state.buf, NULL);
+ } else
+ p = NULL;
+ if (p == NULL)
+ errp("Could not read real path of ROOT (\"%s\") + $PWD", portroot);
+ if (!strcmp(p, "/"))
+ *p = '\0';
+ state.real_root = p;
+ state.real_root_len = strlen(p);
+
do { /* This block may be repeated if using --from with a big files list */
if (args_file) {
/* Read up to max_args files from the input file */
@@ -540,20 +521,20 @@
break;
/* Prepare the qfile(...) arguments structure */
- nb_of_queries = prepare_qfile_args(qargc, (const char **) qargv,
- assume_root_prefix, search_orphans, exclude_pkg_arg, state.args);
+ nb_of_queries = prepare_qfile_args(qargc, (const char **) qargv, &state);
if (nb_of_queries < 0)
break;
+ /* Now do the actual `qfile` checking */
if (nb_of_queries)
found += q_vdb_foreach_pkg(qfile_cb, &state, NULL);
- if (state.args->non_orphans) {
+ if (state.args.non_orphans) {
/* display orphan files */
- for (i = 0; i < state.args->length; i++) {
- if (state.args->non_orphans[i])
+ for (i = 0; i < state.args.length; i++) {
+ if (state.args.non_orphans[i])
continue;
- if (state.args->basenames[i]) {
+ if (state.args.basenames[i]) {
found = 0; /* ~inverse return code (as soon as an orphan is found, return non-zero) */
if (!quiet)
puts(qargv[i]);
@@ -563,7 +544,7 @@
}
}
- destroy_qfile_args(state.args);
+ destroy_qfile_args(&state.args);
} while (args_file && qargc == max_args);
exit:
@@ -578,10 +559,16 @@
fclose(args_file);
}
- destroy_qfile_args(state.args);
+ destroy_qfile_args(&state.args);
free(state.buf);
- free(state.args);
free(state.root);
+ free(state.real_root);
+ free(state.pwd);
+ if (state.exclude_pkg) {
+ free(state.exclude_pkg);
+ /* don't free state.exclude_slot as it's a pointer into exclude_pkg */
+ atom_implode(state.exclude_atom);
+ }
return (found ? EXIT_SUCCESS : EXIT_FAILURE);
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo-projects commit in portage-utils: qfile.c
@ 2012-10-28 9:44 Mike Frysinger (vapier)
0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2012-10-28 9:44 UTC (permalink / raw
To: gentoo-commits
vapier 12/10/28 09:44:24
Modified: qfile.c
Log:
qfile: fix handling of paths relative to pwd #362643 by Jeremy Olexa
Revision Changes Path
1.64 portage-utils/qfile.c
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.64&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.64&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?r1=1.63&r2=1.64
Index: qfile.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- qfile.c 28 Oct 2012 08:57:18 -0000 1.63
+++ qfile.c 28 Oct 2012 09:44:24 -0000 1.64
@@ -1,7 +1,7 @@
/*
* Copyright 2005-2010 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.63 2012/10/28 08:57:18 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.64 2012/10/28 09:44:24 vapier Exp $
*
* Copyright 2005-2010 Ned Ludd - <solar@gentoo.org>
* Copyright 2005-2010 Mike Frysinger - <vapier@gentoo.org>
@@ -34,7 +34,7 @@
"Display installed packages with slots",
COMMON_OPTS_HELP
};
-static const char qfile_rcsid[] = "$Id: qfile.c,v 1.63 2012/10/28 08:57:18 vapier Exp $";
+static const char qfile_rcsid[] = "$Id: qfile.c,v 1.64 2012/10/28 09:44:24 vapier Exp $";
#define qfile_usage(ret) usage(ret, QFILE_FLAGS, qfile_long_opts, qfile_opts_help, lookup_applet_idx("qfile"))
#define qfile_is_prefix(path, prefix, prefix_length) \
@@ -82,8 +82,8 @@
const char *base;
char pkg[_Q_PATH_MAX];
depend_atom *atom = NULL;
- int i, path_ok;
- char bn_firstchar;
+ int i;
+ bool path_ok;
char *real_root = state->real_root;
char **base_names = args->basenames;
char **dir_names = args->dirnames;
@@ -134,72 +134,70 @@
if ((base = basename(e->name)) == NULL)
continue;
- /* used to cut the number of strcmp() calls */
- bn_firstchar = base[0];
-
for (i = 0; i < args->length; i++) {
if (base_names[i] == NULL)
continue;
if (non_orphans && non_orphans[i])
continue;
- path_ok = (dir_names[i] == NULL && real_dir_names[i] == NULL);
/* For optimization of qfile(), we also give it an array of the first char
* of each basename. This way we avoid numerous strcmp() calls.
*/
- if (bn_firstchar != base_names[i][0]
- || strcmp(base, base_names[i]))
+ if (base[0] != base_names[i][0] || strcmp(base, base_names[i]))
continue;
- if (!path_ok) {
- /* check the full filepath ... */
- size_t dirname_len = (base - e->name - 1);
- /* basename(/usr) = usr, dirname(/usr) = /
- * basename(/usr/bin) = bin, dirname(/usr/bin) = /usr
- */
- if (dirname_len == 0)
- dirname_len = 1;
-
- if (dir_names[i] &&
- strncmp(e->name, dir_names[i], dirname_len) == 0 &&
- dir_names[i][dirname_len] == '\0')
- /* dir_name == dirname(CONTENTS) */
- path_ok = 1;
-
- else if (real_dir_names[i] &&
- strncmp(e->name, real_dir_names[i], dirname_len) == 0 &&
- real_dir_names[i][dirname_len] == '\0')
- /* real_dir_name == dirname(CONTENTS) */
- path_ok = 1;
-
- else if (real_root[0]) {
- char rpath[_Q_PATH_MAX + 1], *_rpath;
- char *fullpath;
- size_t real_root_len = state->real_root_len;
-
- xasprintf(&fullpath, "%s%s", real_root, e->name);
- fullpath[real_root_len + dirname_len] = '\0';
- _rpath = rpath + real_root_len;
- if (realpath(fullpath, rpath) == NULL) {
- if (verbose) {
- warnp("Could not read real path of \"%s\" (from %s)", fullpath, pkg);
- warn("We'll never know whether \"%s\" was a result for your query...",
- e->name);
- }
- } else if (!qfile_is_prefix(rpath, real_root, real_root_len)) {
- if (verbose)
- warn("Real path of \"%s\" is not under ROOT: %s", fullpath, rpath);
- } else if (dir_names[i] &&
- strcmp(_rpath, dir_names[i]) == 0) {
- /* dir_name == realpath(dirname(CONTENTS)) */
- path_ok = 1;
- } else if (real_dir_names[i] &&
- strcmp(_rpath, real_dir_names[i]) == 0) {
- /* real_dir_name == realpath(dirname(CONTENTS)) */
- path_ok = 1;
+ path_ok = false;
+
+ /* check the full filepath ... */
+ size_t dirname_len = (base - e->name - 1);
+ /* basename(/usr) = usr, dirname(/usr) = /
+ * basename(/usr/bin) = bin, dirname(/usr/bin) = /usr
+ */
+ if (dirname_len == 0)
+ dirname_len = 1;
+
+ if (dir_names[i] &&
+ strncmp(e->name, dir_names[i], dirname_len) == 0 &&
+ dir_names[i][dirname_len] == '\0') {
+ /* dir_name == dirname(CONTENTS) */
+ path_ok = true;
+
+ } else if (real_dir_names[i] &&
+ strncmp(e->name, real_dir_names[i], dirname_len) == 0 &&
+ real_dir_names[i][dirname_len] == '\0') {
+ /* real_dir_name == dirname(CONTENTS) */
+ path_ok = true;
+
+ } else if (real_root[0]) {
+ char rpath[_Q_PATH_MAX + 1], *_rpath;
+ char *fullpath;
+ size_t real_root_len = state->real_root_len;
+
+ xasprintf(&fullpath, "%s%s", real_root, e->name);
+ fullpath[real_root_len + dirname_len] = '\0';
+ _rpath = rpath + real_root_len;
+ if (realpath(fullpath, rpath) == NULL) {
+ if (verbose) {
+ warnp("Could not read real path of \"%s\" (from %s)", fullpath, pkg);
+ warn("We'll never know whether \"%s\" was a result for your query...",
+ e->name);
}
- free(fullpath);
+ } else if (!qfile_is_prefix(rpath, real_root, real_root_len)) {
+ if (verbose)
+ warn("Real path of \"%s\" is not under ROOT: %s", fullpath, rpath);
+ } else if (dir_names[i] &&
+ strcmp(_rpath, dir_names[i]) == 0) {
+ /* dir_name == realpath(dirname(CONTENTS)) */
+ path_ok = true;
+ } else if (real_dir_names[i] &&
+ strcmp(_rpath, real_dir_names[i]) == 0) {
+ /* real_dir_name == realpath(dirname(CONTENTS)) */
+ path_ok = true;
}
+ free(fullpath);
+ } else if (state->pwd) {
+ if (!strncmp(e->name, state->pwd, dirname_len))
+ path_ok = true;
}
if (!path_ok)
continue;
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo-projects commit in portage-utils: qfile.c
@ 2012-11-10 6:44 Mike Frysinger (vapier)
0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2012-11-10 6:44 UTC (permalink / raw
To: gentoo-commits
vapier 12/11/10 06:44:05
Modified: qfile.c
Log:
qfile: re-order options and clarify --exclude/--exact are only for --orphans #441696
Revision Changes Path
1.65 portage-utils/qfile.c
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.65&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.65&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?r1=1.64&r2=1.65
Index: qfile.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -r1.64 -r1.65
--- qfile.c 28 Oct 2012 09:44:24 -0000 1.64
+++ qfile.c 10 Nov 2012 06:44:05 -0000 1.65
@@ -1,7 +1,7 @@
/*
* Copyright 2005-2010 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.64 2012/10/28 09:44:24 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.65 2012/11/10 06:44:05 vapier Exp $
*
* Copyright 2005-2010 Ned Ludd - <solar@gentoo.org>
* Copyright 2005-2010 Mike Frysinger - <vapier@gentoo.org>
@@ -15,26 +15,26 @@
#define QFILE_FLAGS "ef:m:oRx:S" COMMON_FLAGS
static struct option const qfile_long_opts[] = {
- {"exact", no_argument, NULL, 'e'},
- {"from", a_argument, NULL, 'f'},
- {"max-args", a_argument, NULL, 'm'},
- {"orphans", no_argument, NULL, 'o'},
- {"root-prefix", no_argument, NULL, 'R'},
- {"exclude", a_argument, NULL, 'x'},
{"slots", no_argument, NULL, 'S'},
+ {"root-prefix", no_argument, NULL, 'R'},
+ {"from", a_argument, NULL, 'f'},
+ {"max-args", a_argument, NULL, 'm'},
+ {"orphans", no_argument, NULL, 'o'},
+ {"exclude", a_argument, NULL, 'x'},
+ {"exact", no_argument, NULL, 'e'},
COMMON_LONG_OPTS
};
static const char * const qfile_opts_help[] = {
- "Exact match",
+ "Display installed packages with slots",
+ "Assume arguments are already prefixed by $ROOT",
"Read arguments from file <arg> (\"-\" for stdin)",
"Treat from file arguments by groups of <arg> (defaults to " QFILE_DEFAULT_MAX_ARGS_STR ")",
"List orphan files",
- "Assume arguments are already prefixed by $ROOT",
- "Don't look in package <arg>",
- "Display installed packages with slots",
+ "Don't look in package <arg> (used with --orphans)",
+ "Exact match (used with --exclude)",
COMMON_OPTS_HELP
};
-static const char qfile_rcsid[] = "$Id: qfile.c,v 1.64 2012/10/28 09:44:24 vapier Exp $";
+static const char qfile_rcsid[] = "$Id: qfile.c,v 1.65 2012/11/10 06:44:05 vapier Exp $";
#define qfile_usage(ret) usage(ret, QFILE_FLAGS, qfile_long_opts, qfile_opts_help, lookup_applet_idx("qfile"))
#define qfile_is_prefix(path, prefix, prefix_length) \
^ permalink raw reply [flat|nested] 11+ messages in thread
* [gentoo-commits] gentoo-projects commit in portage-utils: qfile.c
@ 2013-04-29 5:32 Mike Frysinger (vapier)
0 siblings, 0 replies; 11+ messages in thread
From: Mike Frysinger (vapier) @ 2013-04-29 5:32 UTC (permalink / raw
To: gentoo-commits
vapier 13/04/29 05:32:43
Modified: qfile.c
Log:
qfile: add a --basename option so people can match just the base name of a path #441696 by Samuli Suominen
Revision Changes Path
1.66 portage-utils/qfile.c
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.66&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?rev=1.66&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/qfile.c?r1=1.65&r2=1.66
Index: qfile.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- qfile.c 10 Nov 2012 06:44:05 -0000 1.65
+++ qfile.c 29 Apr 2013 05:32:43 -0000 1.66
@@ -1,7 +1,7 @@
/*
* Copyright 2005-2010 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.65 2012/11/10 06:44:05 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/qfile.c,v 1.66 2013/04/29 05:32:43 vapier Exp $
*
* Copyright 2005-2010 Ned Ludd - <solar@gentoo.org>
* Copyright 2005-2010 Mike Frysinger - <vapier@gentoo.org>
@@ -13,12 +13,13 @@
#define QFILE_DEFAULT_MAX_ARGS 5000
#define QFILE_DEFAULT_MAX_ARGS_STR "5000"
-#define QFILE_FLAGS "ef:m:oRx:S" COMMON_FLAGS
+#define QFILE_FLAGS "bef:m:oRx:S" COMMON_FLAGS
static struct option const qfile_long_opts[] = {
{"slots", no_argument, NULL, 'S'},
{"root-prefix", no_argument, NULL, 'R'},
{"from", a_argument, NULL, 'f'},
{"max-args", a_argument, NULL, 'm'},
+ {"basename", no_argument, NULL, 'b'},
{"orphans", no_argument, NULL, 'o'},
{"exclude", a_argument, NULL, 'x'},
{"exact", no_argument, NULL, 'e'},
@@ -29,12 +30,13 @@
"Assume arguments are already prefixed by $ROOT",
"Read arguments from file <arg> (\"-\" for stdin)",
"Treat from file arguments by groups of <arg> (defaults to " QFILE_DEFAULT_MAX_ARGS_STR ")",
+ "Match any component of the path",
"List orphan files",
"Don't look in package <arg> (used with --orphans)",
"Exact match (used with --exclude)",
COMMON_OPTS_HELP
};
-static const char qfile_rcsid[] = "$Id: qfile.c,v 1.65 2012/11/10 06:44:05 vapier Exp $";
+static const char qfile_rcsid[] = "$Id: qfile.c,v 1.66 2013/04/29 05:32:43 vapier Exp $";
#define qfile_usage(ret) usage(ret, QFILE_FLAGS, qfile_long_opts, qfile_opts_help, lookup_applet_idx("qfile"))
#define qfile_is_prefix(path, prefix, prefix_length) \
@@ -63,6 +65,7 @@
char *exclude_slot;
depend_atom *exclude_atom;
bool slotted;
+ bool basename;
bool exact;
bool orphans;
bool assume_root_prefix;
@@ -195,6 +198,8 @@
path_ok = true;
}
free(fullpath);
+ } else if (state->basename) {
+ path_ok = true;
} else if (state->pwd) {
if (!strncmp(e->name, state->pwd, dirname_len))
path_ok = true;
@@ -389,6 +394,7 @@
struct qfile_opt_state state = {
.buflen = _Q_PATH_MAX,
.slotted = false,
+ .basename = false,
.exact = false,
.orphans = false,
.assume_root_prefix = false,
@@ -407,6 +413,7 @@
switch (i) {
COMMON_GETOPTS_CASES(qfile)
case 'S': state.slotted = true; break;
+ case 'b': state.basename = true; break;
case 'e': state.exact = true; break;
case 'f':
if (args_file)
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2013-04-29 5:32 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-01 6:11 [gentoo-commits] gentoo-projects commit in portage-utils: qfile.c Mike Frysinger (vapier)
-- strict thread matches above, loose matches on Subject: below --
2013-04-29 5:32 Mike Frysinger (vapier)
2012-11-10 6:44 Mike Frysinger (vapier)
2012-10-28 9:44 Mike Frysinger (vapier)
2012-10-28 8:57 Mike Frysinger (vapier)
2012-01-16 1:12 Mike Frysinger (vapier)
2011-12-18 8:01 Mike Frysinger (vapier)
2011-10-02 22:08 Mike Frysinger (vapier)
2011-03-02 2:41 Mike Frysinger (vapier)
2010-01-16 21:31 Mike Frysinger (vapier)
2009-10-18 17:28 Ned Ludd (solar)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox