Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/mtree fill up the directory hierarchy so that leaf ...



details:   https://anonhg.NetBSD.org/src/rev/b8e0df5fb298
branches:  trunk
changeset: 784653:b8e0df5fb298
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Feb 05 00:59:03 2013 +0000

description:
fill up the directory hierarchy so that leaf files are not ignored if
specified by themselves.

diffstat:

 usr.sbin/mtree/only.c |  39 ++++++++++++++++++++++++++++++---------
 1 files changed, 30 insertions(+), 9 deletions(-)

diffs (77 lines):

diff -r 70e042556bb5 -r b8e0df5fb298 usr.sbin/mtree/only.c
--- a/usr.sbin/mtree/only.c     Tue Feb 05 00:41:51 2013 +0000
+++ b/usr.sbin/mtree/only.c     Tue Feb 05 00:59:03 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: only.c,v 1.1 2013/02/03 19:15:17 christos Exp $        */
+/*     $NetBSD: only.c,v 1.2 2013/02/05 00:59:03 christos Exp $        */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #include <sys/cdefs.h>
 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: only.c,v 1.1 2013/02/03 19:15:17 christos Exp $");
+__RCSID("$NetBSD: only.c,v 1.2 2013/02/05 00:59:03 christos Exp $");
 #endif
 
 #include <sys/param.h>
@@ -86,14 +86,10 @@
 }
 
 static void
-hash_insert(char *str)
+hash_insert(char *str, uint32_t h)
 {
-       uint32_t h;
        struct hentry *e;
 
-       if (hash_find(str, &h))
-               err(1, "Duplicate entry %s", str);
-
        if ((e = malloc(sizeof(*e))) == NULL)
                mtree_err("memory allocation error");
 
@@ -103,6 +99,26 @@
        table[h] = e;
 }
 
+static void
+fill(char *str)
+{
+       uint32_t h;
+       char *ptr = strrchr(str, '/');
+
+       if (ptr == NULL)
+               return;
+
+       *ptr = '\0';
+       if (!hash_find(str, &h)) {
+               char *x = strdup(str);
+               if (x == NULL)
+                       mtree_err("memory allocation error");
+               hash_insert(x, h);
+               fill(str);
+       }
+       *ptr = '/';
+}
+
 void
 load_only(const char *fname)
 {
@@ -113,8 +129,13 @@
        if ((fp = fopen(fname, "r")) == NULL)
                err(1, "Cannot open `%s'", fname);
 
-       while ((line = fparseln(fp, &len, &lineno, NULL, FPARSELN_UNESCALL)))
-               hash_insert(line);
+       while ((line = fparseln(fp, &len, &lineno, NULL, FPARSELN_UNESCALL))) {
+               uint32_t h;
+               if (hash_find(line, &h))
+                       err(1, "Duplicate entry %s", line);
+               hash_insert(line, h);
+               fill(line);
+       }
 
        fclose(fp);
        loaded = true;



Home | Main Index | Thread Index | Old Index