From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id b25afaa1 for ; Wed, 17 May 2017 17:27:43 -0500 (EST) Date: Wed, 17 May 2017 17:27:43 -0500 (EST) Message-Id: <12174038619587285967.enqueue@fantadrom.bsd.lv> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Never create empty databases. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Never create empty databases. When pkg_add(1)ing packages installing manual pages into some directory, the database in that directory automatically gets created or updated, no change so far. This patch causes the database file to be automatically unlinked when pkg_delete(1)ing the last package having manual pages in that directory, to leave less cruft behind. Suggested by ajacoutot@. Modified Files: -------------- mdocml: makewhatis.8 mandocdb.c Revision Data ------------- Index: makewhatis.8 =================================================================== RCS file: /home/cvs/mdocml/mdocml/makewhatis.8,v retrieving revision 1.5 retrieving revision 1.6 diff -Lmakewhatis.8 -Lmakewhatis.8 -u -p -r1.5 -r1.6 --- makewhatis.8 +++ makewhatis.8 @@ -74,6 +74,8 @@ and .Sm on in that directory. Existing databases are replaced. +If a directory contains no manual pages, no database is created in that +directory. If .Ar dir is not provided, @@ -130,6 +132,7 @@ Remove .Ar from the database in .Ar dir . +If that causes the database to become empty, also delete the database file. .El .Pp If fatal parse errors are encountered while parsing, the offending file Index: mandocdb.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/mandocdb.c,v retrieving revision 1.249 retrieving revision 1.250 diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.249 -r1.250 --- mandocdb.c +++ mandocdb.c @@ -2122,6 +2122,23 @@ dbwrite(struct dba *dba) int status; pid_t child; + /* + * Do not write empty databases, and delete existing ones + * when makewhatis -u causes them to become empty. + */ + + dba_array_start(dba->pages); + if (dba_array_next(dba->pages) == NULL) { + if (unlink(MANDOC_DB) == -1) + say(MANDOC_DB, "&unlink"); + return; + } + + /* + * Build the database in a temporary file, + * then atomically move it into place. + */ + if (dba_write(MANDOC_DB "~", dba) != -1) { if (rename(MANDOC_DB "~", MANDOC_DB) == -1) { exitcode = (int)MANDOCLEVEL_SYSERR; @@ -2130,6 +2147,11 @@ dbwrite(struct dba *dba) } return; } + + /* + * We lack write permission and cannot replace the database + * file, but let's at least check whether the data changed. + */ (void)strlcpy(tfn, "/tmp/mandocdb.XXXXXXXX", sizeof(tfn)); if (mkdtemp(tfn) == NULL) { -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv