FreeBSD Bugzilla – Attachment 7976 Details for
Bug 16944
[MFC] Give mtree(8) an ``exclude'' facility
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 7.01 KB, created by
wollman
on 2000-02-23 21:10:00 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
wollman
Created:
2000-02-23 21:10:00 UTC
Size:
7.01 KB
patch
obsolete
>Index: Makefile >=================================================================== >RCS file: /home/ncvs/src/usr.sbin/mtree/Makefile,v >retrieving revision 1.6.2.1 >diff -u -r1.6.2.1 Makefile >--- Makefile 1999/08/29 15:44:16 1.6.2.1 >+++ Makefile 2000/02/23 20:43:16 >@@ -2,7 +2,7 @@ > # $FreeBSD: src/usr.sbin/mtree/Makefile,v 1.6.2.1 1999/08/29 15:44:16 peter Exp $ > > PROG= mtree >-SRCS= compare.c crc.c create.c misc.c mtree.c spec.c verify.c >+SRCS= compare.c crc.c create.c excludes.c misc.c mtree.c spec.c verify.c > MAN8= mtree.8 > .PATH: ${.CURDIR}/../../usr.bin/cksum > >Index: create.c >=================================================================== >RCS file: /home/ncvs/src/usr.sbin/mtree/create.c,v >retrieving revision 1.13.2.1 >diff -u -r1.13.2.1 create.c >--- create.c 1999/08/29 15:44:17 1.13.2.1 >+++ create.c 2000/02/23 20:44:38 >@@ -97,6 +97,10 @@ > while ((p = fts_read(t))) { > if (iflag) > indent = p->fts_level * 4; >+ if (check_excludes(p->fts_name, p->fts_path)) { >+ fts_set(t, p, FTS_SKIP); >+ continue; >+ } > switch(p->fts_info) { > case FTS_D: > if (!dflag) >Index: excludes.c >=================================================================== >RCS file: excludes.c >diff -N excludes.c >--- /dev/null Wed Feb 23 15:44:28 2000 >+++ excludes.c Wed Feb 23 15:49:28 2000 >@@ -0,0 +1,102 @@ >+/* >+ * Copyright 2000 Massachusetts Institute of Technology >+ * >+ * Permission to use, copy, modify, and distribute this software and >+ * its documentation for any purpose and without fee is hereby >+ * granted, provided that both the above copyright notice and this >+ * permission notice appear in all copies, that both the above >+ * copyright notice and this permission notice appear in all >+ * supporting documentation, and that the name of M.I.T. not be used >+ * in advertising or publicity pertaining to distribution of the >+ * software without specific, written prior permission. M.I.T. makes >+ * no representations about the suitability of this software for any >+ * purpose. It is provided "as is" without express or implied >+ * warranty. >+ * >+ * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS >+ * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, >+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF >+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT >+ * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT >+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF >+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND >+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, >+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT >+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF >+ * SUCH DAMAGE. >+ */ >+ >+#include <sys/types.h> >+#include <sys/queue.h> >+ >+#include <err.h> >+#include <fnmatch.h> >+#include <fts.h> >+#include <stdio.h> >+#include <stdlib.h> >+ >+/* >+ * We're assuming that there won't be a whole lot of excludes, >+ * so it's OK to use a stupid algorithm. >+ */ >+struct exclude { >+ LIST_ENTRY(exclude) link; >+ const char *glob; >+ int pathname; >+}; >+static LIST_HEAD(, exclude) excludes; >+ >+void >+init_excludes(void) >+{ >+ LIST_INIT(&excludes); >+} >+ >+void >+read_excludes_file(const char *name) >+{ >+ FILE *fp; >+ char *line, *str; >+ struct exclude *e; >+ size_t len; >+ >+ fp = fopen(name, "r"); >+ if (fp == 0) >+ err(1, "%s", name); >+ >+ while ((line = fgetln(fp, &len)) != 0) { >+ if (line[len - 1] == '\n') >+ len--; >+ if (len == 0) >+ continue; >+ >+ str = malloc(len + 1); >+ e = malloc(sizeof *e); >+ if (str == 0 || e == 0) >+ errx(1, "memory allocation error"); >+ e->glob = str; >+ memcpy(str, line, len); >+ str[len] = '\0'; >+ if (strchr(str, '/')) >+ e->pathname = 1; >+ LIST_INSERT_HEAD(&excludes, e, link); >+ } >+ fclose(fp); >+} >+ >+int >+check_excludes(const char *fname, const char *path) >+{ >+ struct exclude *e; >+ >+ /* fnmatch(3) has a funny return value convention... */ >+#define MATCH(g, n) (fnmatch((g), (n), FNM_PATHNAME) == 0) >+ >+ for (e = excludes.lh_first; e != 0; e = e->link.le_next) { >+ if (e->pathname && MATCH(e->glob, path) >+ || MATCH(e->glob, fname)) >+ return 1; >+ } >+ return 0; >+} >Index: extern.h >=================================================================== >RCS file: /home/ncvs/src/usr.sbin/mtree/extern.h,v >retrieving revision 1.2 >diff -u -r1.2 extern.h >--- extern.h 1997/10/01 06:30:00 1.2 >+++ extern.h 2000/02/23 20:39:04 >@@ -41,3 +41,7 @@ > char *rlink __P((char *)); > NODE *spec __P((void)); > int verify __P((void)); >+ >+int check_excludes __P((const char *, const char *)); >+void init_excludes __P((void)); >+void read_excludes_file __P((const char *)); >Index: mtree.8 >=================================================================== >RCS file: /home/ncvs/src/usr.sbin/mtree/mtree.8,v >retrieving revision 1.13.2.1 >diff -u -r1.13.2.1 mtree.8 >--- mtree.8 1999/08/29 15:44:18 1.13.2.1 >+++ mtree.8 2000/02/23 20:59:30 >@@ -46,6 +46,7 @@ > .Op Fl k Ar keywords > .Op Fl p Ar path > .Op Fl s Ar seed >+.Op Fl X Ar exclude-list > .Sh DESCRIPTION > The utility > .Nm mtree >@@ -117,6 +118,19 @@ > the specification. > .It Fl x > Don't descend below mount points in the file hierarchy. >+.It Fl X Ar exclude-list >+The specified file contains >+.Xr fnmatch 3 >+patterns matching files to be excluded from >+the specification, one to a line. >+If the pattern contains a >+.Ql \&/ >+character, it will be matched against entire pathnames (relative to >+the starting directory); otherwise, >+it will be matched against basenames only. No comments are allowed in >+the >+.Ar exclude-list >+file. > .El > .Pp > Specifications are mostly composed of ``keywords'', i.e. strings that >Index: mtree.c >=================================================================== >RCS file: /home/ncvs/src/usr.sbin/mtree/mtree.c,v >retrieving revision 1.7.2.1 >diff -u -r1.7.2.1 mtree.c >--- mtree.c 1999/08/29 15:44:19 1.7.2.1 >+++ mtree.c 2000/02/23 20:46:43 >@@ -75,7 +75,9 @@ > > dir = NULL; > keys = KEYDEFAULT; >- while ((ch = getopt(argc, argv, "cdef:iK:k:np:rs:Uux")) != -1) >+ init_excludes(); >+ >+ while ((ch = getopt(argc, argv, "cdef:iK:k:np:rs:UuxX:")) != -1) > switch((char)ch) { > case 'c': > cflag = 1; >@@ -128,6 +130,9 @@ > case 'x': > ftsoptions |= FTS_XDEV; > break; >+ case 'X': >+ read_excludes_file(optarg); >+ break; > case '?': > default: > usage(); >@@ -158,6 +163,7 @@ > usage() > { > (void)fprintf(stderr, >-"usage: mtree [-cdeinrUux] [-f spec] [-K key] [-k key] [-p path] [-s seed]\n"); >+"usage: mtree [-cdeinrUux] [-f spec] [-K key] [-k key] [-p path] [-s seed]\n" >+"\t[-X excludes]\n"); > exit(1); > } >Index: verify.c >=================================================================== >RCS file: /home/ncvs/src/usr.sbin/mtree/verify.c,v >retrieving revision 1.7.2.1 >diff -u -r1.7.2.1 verify.c >--- verify.c 1999/08/29 15:44:19 1.7.2.1 >+++ verify.c 2000/02/23 20:52:30 >@@ -90,6 +90,10 @@ > level = root; > specdepth = rval = 0; > while ((p = fts_read(t))) { >+ if (check_excludes(p->fts_name, p->fts_path)) { >+ fts_set(t, p, FTS_SKIP); >+ continue; >+ } > switch(p->fts_info) { > case FTS_D: > break;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 16944
: 7976