summaryrefslogtreecommitdiff
path: root/src/pacman/files.c
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2015-10-17 14:37:07 +0200
committerAllan McRae <allan@archlinux.org>2015-11-03 14:36:59 +1000
commit906dc0ce24d62284b6a3caf612948553e7ffceb3 (patch)
tree46d1c8c255353b8142eecd8341f050030ff5ee32 /src/pacman/files.c
parent697377aae3df2ed9743f20c92e807526105c60c0 (diff)
downloadpacman-906dc0ce24d62284b6a3caf612948553e7ffceb3.tar.xz
Add -F --machinereadable option
Signed-off-by: Florian Pritz <bluewind@xinu.at> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src/pacman/files.c')
-rw-r--r--src/pacman/files.c48
1 files changed, 42 insertions, 6 deletions
diff --git a/src/pacman/files.c b/src/pacman/files.c
index 31ce9e07..f6b18380 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -27,6 +27,27 @@
#include "conf.h"
#include "package.h"
+static void print_line_machinereadable(alpm_db_t *db, alpm_pkg_t *pkg, char *filename)
+{
+ /* Fields are repo, pkgname, pkgver, filename separated with \0 */
+ fputs(alpm_db_get_name(db), stdout);
+ fputc(0, stdout);
+ fputs(alpm_pkg_get_name(pkg), stdout);
+ fputc(0, stdout);
+ fputs(alpm_pkg_get_version(pkg), stdout);
+ fputc(0, stdout);
+ fputs(filename, stdout);
+ fputs("\n", stdout);
+}
+
+static void dump_pkg_machinereadable(alpm_db_t *db, alpm_pkg_t *pkg)
+{
+ alpm_filelist_t *pkgfiles = alpm_pkg_get_files(pkg);
+ for(size_t filenum = 0; filenum < pkgfiles->count; filenum++) {
+ const alpm_file_t *file = pkgfiles->files + filenum;
+ print_line_machinereadable(db, pkg, file->name);
+ }
+}
static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) {
int ret = 0;
@@ -59,8 +80,9 @@ static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) {
alpm_filelist_t *files = alpm_pkg_get_files(pkg);
if(alpm_filelist_contains(files, f)) {
-
- if(!config->quiet) {
+ if(config->op_f_machinereadable) {
+ print_line_machinereadable(repo, pkg, f);
+ } else if(!config->quiet) {
printf(_("%s is owned by %s/%s %s\n"), f,
alpm_db_get_name(repo), alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg));
@@ -137,7 +159,13 @@ static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) {
}
if(match != NULL) {
- if(config->quiet) {
+ if(config->op_f_machinereadable) {
+ alpm_list_t *ml;
+ for(ml = match; ml; ml = alpm_list_next(ml)) {
+ char *filename = ml->data;
+ print_line_machinereadable(repo, pkg, filename);
+ }
+ } else if(config->quiet) {
printf("%s/%s\n", alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
} else {
alpm_list_t *ml;
@@ -149,8 +177,8 @@ static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) {
c = ml->data;
printf(" %s\n", c);
}
- FREELIST(match);
}
+ FREELIST(match);
}
}
}
@@ -222,7 +250,11 @@ static int files_list(alpm_list_t *syncs, alpm_list_t *targets) {
if((pkg = alpm_db_get_pkg(db, targ)) != NULL) {
found = 1;
- dump_file_list(pkg);
+ if(config->op_f_machinereadable) {
+ dump_pkg_machinereadable(db, pkg);
+ } else {
+ dump_file_list(pkg);
+ }
break;
}
}
@@ -240,7 +272,11 @@ static int files_list(alpm_list_t *syncs, alpm_list_t *targets) {
for(j = alpm_db_get_pkgcache(db); j; j = alpm_list_next(j)) {
alpm_pkg_t *pkg = j->data;
- dump_file_list(pkg);
+ if(config->op_f_machinereadable) {
+ dump_pkg_machinereadable(db, pkg);
+ } else {
+ dump_file_list(pkg);
+ }
}
}
}