source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Never create empty databases.
@ 2017-05-17 22:27 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-05-17 22:27 UTC (permalink / raw)
  To: source

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-05-17 22:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-17 22:27 mdocml: Never create empty databases schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).