git: ddacf99b4fc0 - main - shared-mime-info: use triggers

From: Baptiste Daroussin <bapt_at_FreeBSD.org>
Date: Wed, 20 Oct 2021 09:11:10 UTC
The branch main has been updated by bapt:

URL: https://cgit.FreeBSD.org/ports/commit/?id=ddacf99b4fc010511a09e1af376d0fca7399e208

commit ddacf99b4fc010511a09e1af376d0fca7399e208
Author:     Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2021-10-11 09:31:35 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2021-10-20 09:11:08 +0000

    shared-mime-info: use triggers
    
    the rebuild of the database is now handled by a trigger and happen only
    once at the end of the transaction instead of after each package
    installation.
    
    While make shared-mime-info a runtime only dependency
    
    Reviewed by:    manu, mat
    Differential Revision:  https://reviews.freebsd.org/D32452
---
 Keywords/shared-mime-info.ucl                      |  9 ------
 Mk/Uses/shared-mime-info.mk                        |  2 --
 misc/shared-mime-info/Makefile                     | 16 +++++-----
 misc/shared-mime-info/files/pkg-install.in         | 12 --------
 .../shared-mime-info/files/shared-mime-info.ucl.in | 27 ++++++++++++++++
 misc/shared-mime-info/pkg-plist                    | 36 ++++++++--------------
 6 files changed, 48 insertions(+), 54 deletions(-)

diff --git a/Keywords/shared-mime-info.ucl b/Keywords/shared-mime-info.ucl
deleted file mode 100644
index 2fdc0a2ba4c4..000000000000
--- a/Keywords/shared-mime-info.ucl
+++ /dev/null
@@ -1,9 +0,0 @@
-# MAINTAINER: gnome@FreeBSD.org
-
-actions: []
-post-install: <<EOD
-  update-mime-database %D/%@ || true
-EOD
-post-deinstall: <<EOD
-  update-mime-database %D/%@ || true
-EOD
diff --git a/Mk/Uses/shared-mime-info.mk b/Mk/Uses/shared-mime-info.mk
index 8e0f972ba4f6..49b552e419e8 100644
--- a/Mk/Uses/shared-mime-info.mk
+++ b/Mk/Uses/shared-mime-info.mk
@@ -13,8 +13,6 @@ _INCLUDE_USES_SHARED_MIME_INFO_MK=	yes
 IGNORE=	USES=shared-mime-info does not require args
 .endif
 
-BUILD_DEPENDS+=	update-mime-database:misc/shared-mime-info
 RUN_DEPENDS+=	update-mime-database:misc/shared-mime-info
-PLIST_FILES+=	"@shared-mime-info share/mime"
 
 .endif
diff --git a/misc/shared-mime-info/Makefile b/misc/shared-mime-info/Makefile
index 4302cf031973..bc81d9447691 100644
--- a/misc/shared-mime-info/Makefile
+++ b/misc/shared-mime-info/Makefile
@@ -2,6 +2,7 @@
 
 PORTNAME=	shared-mime-info
 DISTVERSION=	2.0
+PORTREVISION=	1
 CATEGORIES=	misc gnome
 
 MAINTAINER=	desktop@FreeBSD.org
@@ -14,7 +15,8 @@ BUILD_DEPENDS=	gmake:devel/gmake \
 		itstool:textproc/itstool \
 		minixmlto:textproc/minixmlto
 
-USES=		gettext gnome localbase meson pathfix pkgconfig shebangfix tar:xz
+USES=		gettext gnome localbase meson pathfix pkgconfig shebangfix \
+		tar:xz trigger
 CONFIGURE_ARGS=	-Dupdate-mimedb=false \
 		-Dxdgmime-path=${WRKSRC}/src/xdgmime
 USE_GNOME=	glib20 libxml2
@@ -27,13 +29,8 @@ GL_TUPLE=	xdg:xdgmime:6663a2288d11b37bc07f5a01b4b85dcd377787e1:xdgmime/src/xdgmi
 bash_CMD=	/bin/sh
 SHEBANG_FILES=	${WRKSRC}/data/freedesktop_generate.sh
 
-SUB_FILES=	pkg-install
-SUB_LIST=	MIMEDIRS="${MIMEDIRS:O:u}"
-
-MIMEDIRS=	${LOCALBASE}/share/mime \
-		${PREFIX}/share/mime
 MIMESUBDIRS=	application audio image inode message model multipart \
-		packages text video x-epoc x-content
+		packages text video x-epoc x-content font
 
 BINARY_ALIAS=	xmlto=minixmlto
 
@@ -45,4 +42,9 @@ post-patch:
 pre-configure:
 	cd ${WRKSRC}/src/xdgmime/src && ${SETENV} ${MAKE_ENV} ${GMAKE}
 
+post-install:
+	for dir in ${MIMESUBDIRS} ; do \
+		${MKDIR} ${STAGEDIR}${PREFIX}/share/mime/$${dir} ; \
+	done
+
 .include <bsd.port.mk>
diff --git a/misc/shared-mime-info/files/pkg-install.in b/misc/shared-mime-info/files/pkg-install.in
deleted file mode 100644
index b2c3db6d3ca3..000000000000
--- a/misc/shared-mime-info/files/pkg-install.in
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-
-case $2 in
-POST-INSTALL)
-	for mdir in %%MIMEDIRS%%; do
-	    if [ -d ${mdir} ]; then
-		%%PREFIX%%/bin/update-mime-database ${mdir}
-	    fi
-	done
-	exit 0
-	;;
-esac
diff --git a/misc/shared-mime-info/files/shared-mime-info.ucl.in b/misc/shared-mime-info/files/shared-mime-info.ucl.in
new file mode 100644
index 000000000000..38d1d2cfec04
--- /dev/null
+++ b/misc/shared-mime-info/files/shared-mime-info.ucl.in
@@ -0,0 +1,27 @@
+path: "%%PREFIX%%/share/mime/packages"
+cleanup: {
+	type: lua
+	script: <<EOS
+local mimedir = "%%PREFIX%%/share/mime/"
+local files = { "XMLnamespaces", "aliases", "generic-icons", "globs", "globs2", "icons", "mime.cache", "subclasses", "treemagic", "types", "version"}
+for _,filename in pairs(files) do
+	local fpath = mimedir .. filename
+	local st = pkg.stat(fpath)
+	if st then
+		os.remove(fpath)
+	end
+end
+local res = pkg.readdir(mimedir)
+if #res == 0 then
+	os.remove(mimedir)
+end
+EOS
+}
+trigger: {
+	type: lua
+	sandbox: false
+	script: <<EOS
+print("Building the Shared MIME-Info database cache")
+pkg.exec({"%%PREFIX%%/bin/update-mime-database", "%%PREFIX%%/share/mime"})
+EOS
+}
diff --git a/misc/shared-mime-info/pkg-plist b/misc/shared-mime-info/pkg-plist
index 0026c0d3c9d8..700f9fa4ba3c 100644
--- a/misc/shared-mime-info/pkg-plist
+++ b/misc/shared-mime-info/pkg-plist
@@ -79,27 +79,15 @@ share/locale/zh_CN/LC_MESSAGES/shared-mime-info.mo
 share/locale/zh_HK/LC_MESSAGES/shared-mime-info.mo
 share/locale/zh_TW/LC_MESSAGES/shared-mime-info.mo
 share/mime/packages/freedesktop.org.xml
-@rmtry share/mime/XMLnamespaces
-@rmtry share/mime/aliases
-@rmtry share/mime/generic-icons
-@rmtry share/mime/globs
-@rmtry share/mime/globs2
-@rmtry share/mime/icons
-@rmtry share/mime/magic
-@rmtry share/mime/mime.cache
-@rmtry share/mime/subclasses
-@rmtry share/mime/treemagic
-@rmtry share/mime/types
-@rmtry share/mime/version
-@postunexec rm -fr %D/share/mime/x-epoc 2>/dev/null || true
-@postunexec rm -fr %D/share/mime/x-content 2>/dev/null || true
-@postunexec rm -fr %D/share/mime/video 2>/dev/null || true
-@postunexec rm -fr %D/share/mime/text 2>/dev/null || true
-@postunexec rm -fr %D/share/mime/multipart 2>/dev/null || true
-@postunexec rm -fr %D/share/mime/model 2>/dev/null || true
-@postunexec rm -fr %D/share/mime/message 2>/dev/null || true
-@postunexec rm -fr %D/share/mime/inode 2>/dev/null || true
-@postunexec rm -fr %D/share/mime/image 2>/dev/null || true
-@postunexec rm -fr %D/share/mime/font 2>/dev/null || true
-@postunexec rm -fr %D/share/mime/audio 2>/dev/null || true
-@postunexec rm -fr %D/share/mime/application 2>/dev/null || true
+@dir share/mime/x-epoc
+@dir share/mime/x-content
+@dir share/mime/video
+@dir share/mime/text
+@dir share/mime/multipart
+@dir share/mime/model
+@dir share/mime/message
+@dir share/mime/inode
+@dir share/mime/image
+@dir share/mime/font
+@dir share/mime/audio
+@dir share/mime/application