[PATCH 2/3] util.c: extend --print-format with %b for builddate

Jelle van der Waa jelle at vdwaa.nl
Sat Mar 26 15:54:21 UTC 2022


From: Jelle van der Waa <jelle at vdwaa.nl>

Signed-off-by: Jelle van der Waa <jelle at archlinux.org>
---
 doc/pacman.8.asciidoc | 10 +++++-----
 src/pacman/util.c     | 11 +++++++++++
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/doc/pacman.8.asciidoc b/doc/pacman.8.asciidoc
index 49e392cb..8a9294fc 100644
--- a/doc/pacman.8.asciidoc
+++ b/doc/pacman.8.asciidoc
@@ -235,11 +235,11 @@ Transaction Options (apply to '-S', '-R' and '-U')
 
 *\--print-format* <format>::
 	Specify a printf-like format to control the output of the '\--print'
-	operation. The possible attributes are: "%a" for arch, "%d" for
-	description, "%e" for pkgbase, "%f" for filename, "%g" for base64
-	encoded PGP signature, "%h" for sha256sum, "%n" for pkgname, "%p" for
-	packager, "%v" for pkgver, "%l" for location, "%r" for repository, and
-	"%s" for size.
+	operation. The possible attributes are: "%a" for arch, "%b" for
+	builddate, "%d" for description, "%e" for pkgbase, "%f" for filename,
+	"%g" for base64 encoded PGP signature, "%h" for sha256sum, "%n" for
+	pkgname, "%p" for packager, "%v" for pkgver, "%l" for location, "%r"
+	for repository, and "%s" for size.
 	Implies '\--print'.
 
 
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 3b92e678..519765f1 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -1163,6 +1163,17 @@ void print_packages(const alpm_list_t *packages)
 			free(temp);
 			temp = string;
 		}
+		/* %b : build date */
+		if(strstr(temp, "%b")) {
+			char bdatestr[50] = "";
+			time_t bdate = (time_t)alpm_pkg_get_builddate(pkg);
+			if(bdate) {
+				strftime(bdatestr, 50, "%c", localtime(&bdate));
+				string = strreplace(temp, "%b", bdatestr);
+				free(temp);
+				temp = string;
+			}
+		}
 		/* %d : description */
 		VAL_FROM_FORMAT_STR(temp, "%d", alpm_pkg_get_desc)
 		/* %e : pkgbase */
-- 
2.35.1



More information about the pacman-dev mailing list