From 8b57b63b4cb2b643ba7381cfd27d7cb7548b7e9930f386ed22942487ca9c53ff Mon Sep 17 00:00:00 2001 From: Matej Cepl Date: Mon, 13 May 2024 11:18:25 +0000 Subject: [PATCH] Accepting request 1173636 from home:lnussel:branches:Documentation ok OBS-URL: https://build.opensuse.org/request/show/1173636 OBS-URL: https://build.opensuse.org/package/show/Documentation/mandoc?expand=0&rev=21 --- mandoc.lua | 52 +++++++++++++++++++++++++++++++++++++ mandoc.spec | 74 +++++++++++++++++++++-------------------------------- 2 files changed, 81 insertions(+), 45 deletions(-) create mode 100644 mandoc.lua diff --git a/mandoc.lua b/mandoc.lua new file mode 100644 index 0000000..404b32b --- /dev/null +++ b/mandoc.lua @@ -0,0 +1,52 @@ +mandoc = { debug = nil, todo = {}, count = 0, limit = 16 } -- package + +function _log(...) + if mandoc.debug and posix.getenv("VERBOSE_FILETRIGGERS") then + print(mandoc.debug .. ": ", ...) + end +end + +function mandoc._run(add, file) + if add then op = "-d" else op = "-u" end + _log("calling makewhatis " .. op .. " " .. file) + rpm.execute("/usr/sbin/makewhatis", op, "/usr/share/man", file) +end + +function mandoc._handle(add, file) + if not string.match(file, "/usr/share/man/man[^/]+/[^/]+.gz$") then + return + end + if not posix.access(file) then + return + end +-- if mandoc.count < mandoc.limit then + if add then + _log("adding " .. file) + else + _log("removing " .. file) + end + mandoc.todo[file] = add +-- elseif mandoc.count == mandoc.limit then +-- _log("too many files, using makewhatis for batch processing") +-- end + mandoc.count = mandoc.count + 1 +end + +function mandoc.add(fn) + mandoc._handle(true, fn) +end + +function mandoc.remove(fn) + mandoc._handle(false, fn) +end + +function mandoc.done() + if mandoc.count < mandoc.limit and posix.access("/usr/share/man/mandoc.db") then + for file, what in pairs(mandoc.todo) do + mandoc._run(what, file) + end + else + _log("calling makewhatis") + rpm.execute("/usr/sbin/makewhatis") + end +end diff --git a/mandoc.spec b/mandoc.spec index 5a9531b..e1b7a4b 100644 --- a/mandoc.spec +++ b/mandoc.spec @@ -1,7 +1,7 @@ # # spec file for package mandoc # -# Copyright (c) 2023 SUSE LLC +# Copyright (c) 2024 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -25,6 +25,7 @@ License: ISC Group: Productivity/Publishing/Troff URL: http://mandoc.bsd.lv/ Source: http://mandoc.bsd.lv/snapshots/mandoc-%{version}.tar.gz +Source1: mandoc.lua # PATCH-FIX-UPSTREAM boo1209830-endless-loop.patch bsc#1209830 mcepl@suse.com # Fix endless loop Patch0: boo1209830-endless-loop.patch @@ -71,62 +72,43 @@ export CFLAGS="%optflags" %make_install MANDIR=%{_mandir} BINDIR=%{_bindir} SBINDIR=%{_sbindir} cp -fv %{buildroot}%{_bindir}/apropos %{_tmppath}/ mv -fv %{_tmppath}/apropos %{buildroot}%{_sbindir}/makewhatis +install -D -m 644 %{SOURCE1} %{buildroot}%{_rpmconfigdir}/lua/mandoc.lua # ghost : > %{buildroot}%{_mandir}/mandoc.db -%post -%{_sbindir}/makewhatis +%posttrans +/usr/sbin/makewhatis || : %filetriggerin -p -- %{_mandir} --- no point registering individual files if we can call --- makewhatis in %%post to catch all if -if posix.getenv("VERBOSE_FILETRIGGERS") then - print("%{nvr}: running file install trigger") -end -if posix.access("%{_mandir}/mandoc.db") then +if not posix.access("/usr/share/man/mandoc.db") then return end +require("mandoc") +mandoc.debug = "%{nvr}(fin)" +file = rpm.next_file() +while file do + mandoc.add(file) file = rpm.next_file() - while file do - if string.match(file, "%{_mandir}/man[^/]+/[^/]+%{?ext_man}$") then - if posix.access(file) then - if posix.getenv("VERBOSE_FILETRIGGERS") then - print("%{nvr}: adding " .. file) - end - rpm.execute("%{_sbindir}/makewhatis", "-d", "%{_mandir}", file) - else - io.stderr:write("%{nvr}: missing " .. file .. "\n") - end - end - file = rpm.next_file() - end -elseif posix.getenv("VERBOSE_FILETRIGGERS") then - print("%{nvr}: missing mandoc.db, skipped") end -io.flush() + +%transfiletriggerin -p -- %{_mandir} +require("mandoc") +mandoc.debug = "%{nvr}(tfin)" +mandoc.done() %filetriggerun -p -- %{_mandir} -if posix.getenv("VERBOSE_FILETRIGGERS") then - print("%{nvr}: running file remove trigger") -end -if posix.access("%{_mandir}/mandoc.db") then +if not posix.access("/usr/share/man/mandoc.db") then return end +require("mandoc") +mandoc.debug = "%{nvr}(fun)" +file = rpm.next_file() +while file do + mandoc.remove(file) file = rpm.next_file() - while file do - if string.match(file, "%{_mandir}/man[^/]+/[^/]+%{?ext_man}$") then - if posix.access(file) then - if posix.getenv("VERBOSE_FILETRIGGERS") then - print("%{nvr}: removing " .. file) - end - rpm.execute("%{_sbindir}/makewhatis", "-u", "%{_mandir}", file) - else - io.stderr:write("%{nvr}: missing " .. file .. "\n") - end - end - file = rpm.next_file() - end -elseif posix.getenv("VERBOSE_FILETRIGGERS") then - print("%{nvr}: missing mandoc.db, skipped") end -io.flush() + +%transfiletriggerpostun -p -- %{_mandir} +require("mandoc") +mandoc.debug = "%{nvr}(tfpun)" +mandoc.done() %files %license LICENSE @@ -137,6 +119,8 @@ io.flush() %{_bindir}/soelim %{_bindir}/whatis %{_sbindir}/makewhatis +%dir %{_rpmconfigdir}/lua +%{_rpmconfigdir}/lua/mandoc.lua %{_mandir}/man1/*.1%{?ext_man} %{_mandir}/man5/*.5%{?ext_man} %{_mandir}/man7/*.7%{?ext_man}