tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Kristaps Dzonsons <kristaps@bsd.lv>
To: tech@mdocml.bsd.lv
Subject: mandocdb(8) relative paths
Date: Thu, 15 Dec 2011 02:04:25 +0100	[thread overview]
Message-ID: <4EE94799.90308@bsd.lv> (raw)

[-- Attachment #1: Type: text/plain, Size: 672 bytes --]

Hi,

Enclosed is a patch to mandocdb(8) that lists index filenames relative 
to their database directory instead of absolute.

In other words,

   /usr/local/man/man1/foo.1 -> man1/foo.1

This frees up a lot of space in the databases and also allows whole 
subtrees to move around with `cp -R'.

While here, I made chdir() error out since it's now required to traverse 
the paths.  I also touched up this and that, and removed some missed 
"verb > 2" statements.

apropos(1) and whatis(1) work fine with this patch (except my 
"interactive mode" posted to discuss@, eagerly awaiting your comments), 
but catman(8) and man.cgi(7) will need adjustment.

Thoughts?

Kristaps

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 4712 bytes --]

Index: mandocdb.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.c,v
retrieving revision 1.34
diff -u -r1.34 mandocdb.c
--- mandocdb.c	12 Dec 2011 02:00:49 -0000	1.34
+++ mandocdb.c	15 Dec 2011 00:43:32 -0000
@@ -21,7 +21,6 @@
 
 #include <sys/param.h>
 #include <sys/types.h>
-#include <sys/stat.h>
 
 #include <assert.h>
 #include <dirent.h>
@@ -110,7 +109,7 @@
 				recno_t *, recno_t **, size_t *,
 				size_t *);
 static	void		  ofile_argbuild(int, char *[], struct of **);
-static	int		  ofile_dirbuild(const char *, const char *,
+static	void		  ofile_dirbuild(const char *, const char *,
 				const char *, int, struct of **);
 static	void		  ofile_free(struct of *);
 static	void		  pformatted(DB *, struct buf *, struct buf *,
@@ -384,12 +383,8 @@
 			exit((int)MANDOCLEVEL_SYSERR);
 		}
 
-		if (verb > 2) {
-			printf("%s: Opened\n", fbuf);
-			printf("%s: Opened\n", ibuf);
-		}
-
 		ofile_argbuild(argc, argv, &of);
+
 		if (NULL == of)
 			goto out;
 
@@ -399,13 +394,16 @@
 				&maxrec, &recs, &recsz, &reccur);
 
 		/*
-		 * Go to the root of the respective manual tree
-		 * such that .so links work.  In case of failure,
-		 * just prod on, even though .so links won't work.
+		 * Go to the root of the respective manual tree.
+		 * This must work or no manuals may be found (they're
+		 * indexed relative to the root).
 		 */
 
 		if (OP_UPDATE == op) {
-			chdir(dir);
+			if (-1 == chdir(dir)) {
+				perror(dir);
+				exit((int)MANDOCLEVEL_SYSERR);
+			}
 			index_merge(of, mp, &dbuf, &buf, hash,
 					db, fbuf, idx, ibuf,
 					maxrec, recs, reccur);
@@ -466,17 +464,15 @@
 			exit((int)MANDOCLEVEL_SYSERR);
 		}
 
-		if (verb > 2) {
-			printf("%s: Truncated\n", fbuf);
-			printf("%s: Truncated\n", ibuf);
-		}
-
 		ofile_free(of);
 		of = NULL;
 
-		if ( ! ofile_dirbuild(dirs.paths[i], NULL, NULL,
-					0, &of)) 
+		if (-1 == chdir(dirs.paths[i])) {
+			perror(dirs.paths[i]);
 			exit((int)MANDOCLEVEL_SYSERR);
+		} 
+
+	       	ofile_dirbuild(".", NULL, NULL, 0, &of);
 
 		if (NULL == of)
 			continue;
@@ -484,12 +480,16 @@
 		of = of->first;
 
 		/*
-		 * Go to the root of the respective manual tree
-		 * such that .so links work.  In case of failure,
-		 * just prod on, even though .so links won't work.
+		 * Go to the root of the respective manual tree.  
+		 * This must work or no manuals may be found (they're
+		 * indexed relative to the root).
 		 */
 
-		chdir(dirs.paths[i]);
+		if (-1 == chdir(dirs.paths[i])) {
+			perror(dirs.paths[i]);
+			exit((int)MANDOCLEVEL_SYSERR);
+		}
+
 		index_merge(of, mp, &dbuf, &buf, hash, db, fbuf,
 				idx, ibuf, maxrec, recs, reccur);
 	}
@@ -1434,8 +1434,6 @@
 		 * Add the structure to the list.
 		 */
 
-		if (verb > 2) 
-			printf("%s: Scheduling\n", argv[i]);
 		if (NULL == *of) {
 			*of = nof;
 			(*of)->first = nof;
@@ -1455,12 +1453,11 @@
  * everything else is a manual.
  * Pass in a pointer to a NULL structure for the first invocation.
  */
-static int
+static void
 ofile_dirbuild(const char *dir, const char* psec, const char *parch,
 		int p_src_form, struct of **of)
 {
 	char		 buf[MAXPATHLEN];
-	struct stat	 sb;
 	size_t		 sz;
 	DIR		*d;
 	const char	*fn, *sec, *arch;
@@ -1471,7 +1468,7 @@
 
 	if (NULL == (d = opendir(dir))) {
 		perror(dir);
-		return(0);
+		exit((int)MANDOCLEVEL_SYSERR);
 	}
 
 	while (NULL != (dp = readdir(d))) {
@@ -1516,20 +1513,16 @@
 
 			if (MAXPATHLEN <= sz) {
 				fprintf(stderr, "%s: Path too long\n", dir);
-				return(0);
+				exit((int)MANDOCLEVEL_SYSERR);
 			}
  
-			if (verb > 2)
-				printf("%s: Scanning\n", buf);
-
-			if ( ! ofile_dirbuild(buf, sec, arch,
-					src_form, of))
-				return(0);
+			ofile_dirbuild(buf, sec, arch, src_form, of);
 		}
+
 		if (DT_REG != dp->d_type ||
-		    (NULL == psec && !use_all) ||
-		    !strcmp(MANDOC_DB, fn) ||
-		    !strcmp(MANDOC_IDX, fn))
+				(NULL == psec && !use_all) ||
+				! strcmp(MANDOC_DB, fn) ||
+				! strcmp(MANDOC_IDX, fn))
 			continue;
 
 		/*
@@ -1593,13 +1586,15 @@
 					    "%s: Path too long\n", buf);
 					continue;
 				}
-				if (0 == stat(buf, &sb))
+				if (0 == access(buf, R_OK))
 					continue;
 			}
 		}
 
+		assert('.' == dir[0]);
+		assert('/' == dir[1]);
 		buf[0] = '\0';
-		strlcat(buf, dir, MAXPATHLEN);
+		strlcat(buf, dir + 2, MAXPATHLEN);
 		strlcat(buf, "/", MAXPATHLEN);
 		sz = strlcat(buf, fn, MAXPATHLEN);
 		if (sz >= MAXPATHLEN) {
@@ -1628,8 +1623,6 @@
 		 * Add the structure to the list.
 		 */
 
-		if (verb > 2)
-			printf("%s: Scheduling\n", buf);
 		if (NULL == *of) {
 			*of = nof;
 			(*of)->first = nof;
@@ -1641,7 +1634,6 @@
 	}
 
 	closedir(d);
-	return(1);
 }
 
 static void

             reply	other threads:[~2011-12-15  1:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-15  1:04 Kristaps Dzonsons [this message]
2011-12-15 10:10 ` Kristaps Dzonsons

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=4EE94799.90308@bsd.lv \
    --to=kristaps@bsd.lv \
    --cc=tech@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).