source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Never create empty databases.
Date: Wed, 17 May 2017 17:27:43 -0500 (EST)	[thread overview]
Message-ID: <12174038619587285967.enqueue@fantadrom.bsd.lv> (raw)

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

                 reply	other threads:[~2017-05-17 22:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12174038619587285967.enqueue@fantadrom.bsd.lv \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).