Date: Mon, 30 Nov 1998 22:50:08 -0500 (EST) From: "John W. DeBoskey" <jwd@unx.sas.com> To: freebsd-current@FreeBSD.ORG Subject: mtree -d (diff to include symlinks) Message-ID: <199812010350.WAA12951@bb01f39.unx.sas.com>
next in thread | raw e-mail | index | archive | help
Hi, Please read the whole msg. It appears that mtree doesn't correctly parse all it output formats correctly on input :-( I'm trying to use mtree to create a mapping of a directory structure that contains symlinks. 'mtree -d' will give me all the directories, but not the info for the symlinks. Without the -d, I am inundated with information concerning the files in the structure that I don't care about.. Thus, I've added the following 2 options to mtree: -P cause mtree to use ftsoptions = FTS_PHYSICAL so information is returned about the link, and not the link target. (See 1.3.8.3 Mon Mar 9 12:32:09 1998 UTC by ache) The comment does not say why the 'FTS_PHYSICAL -> FTS_LOGICAL' change was done. -l link flag. specifies that we want output about symlinks to be written out when running with the -d option. With the above additions, I can now use mtree to create the following map file: $ /usr/src/usr.sbin/mtree/mtree -cdilnPp . # user: jwd # machine: magenta.pc.sas.com # tree: /usr/home/jwd/bsd # date: Mon Sep 29 11:18:19 1997 /set type=dir uid=227 gid=0 mode=0755 nlink=1 . nlink=4 size=512 time=875531854.0 a nlink=3 size=512 time=875531884.0 symlink2b size=4 time=875531823.0 link=../b dir_in_a nlink=2 size=512 time=875500662.0 .. .. b nlink=3 size=512 time=875531891.0 symlink2a size=4 time=875531838.0 link=../a dir_in_b nlink=2 size=512 time=875500662.0 .. .. .. The following are the diffs to mtree.c and create.c ... Would someone please review these and commit them? My commentary above can be used as part of the commit msg. If this is committed, I will also update the man page. If someone knows of a better way to do this, I'm all ears! :-) Thanks! John ps: Ok, I quit for the evenning. If I feed the above back into mtree, it creates 'a', then 'b' under 'a' instead of beside it, and the symlinks are real directories instead of symlinks. Looks like I need to look at the input parsing... ie: mtree -cdilnPp bsd | /usr/sbin/mtree -dUp /tmp/bsd yields: find bsd -exec file {} \; bsd: directory bsd/a: directory bsd/a/symlink2b: directory <--- Wrong bsd/a/symlink2b/dir_in_a: directory <--- Wrong, didn't .. bsd/a/b: directory <--- " bsd/a/b/symlink2a: directory <--- " bsd/a/b/symlink2a/dir_in_b: directory <--- " instead of:find bsd -exec file {} \; bsd: directory bsd/a: directory bsd/a/dir_in_a: directory bsd/a/symlink2b: symbolic link to ../b <--- Correct bsd/b: directory bsd/b/dir_in_b: directory bsd/b/symlink2a: symbolic link to ../a --- mtree.c.orig +++ mtree.c @@ -58,7 +58,7 @@ extern long int crc_total; int ftsoptions = FTS_LOGICAL; -int cflag, dflag, eflag, iflag, nflag, rflag, sflag, uflag, Uflag; +int cflag, dflag, eflag, iflag, lflag, nflag, rflag, sflag, uflag, Uflag; u_int keys; char fullpath[MAXPATHLEN]; @@ -75,7 +75,7 @@ dir = NULL; keys = KEYDEFAULT; - while ((ch = getopt(argc, argv, "cdef:iK:k:np:rs:Uux")) != -1) + while ((ch = getopt(argc, argv, "cdef:iK:k:lnPp:rs:Uux")) != -1) switch((char)ch) { case 'c': cflag = 1; @@ -104,8 +104,14 @@ if (*p != '\0') keys |= parsekey(p, NULL); break; + case 'l': + lflag = 1; + break; case 'n': nflag = 1; + break; + case 'P': + ftsoptions = FTS_PHYSICAL; break; case 'p': dir = optarg; --- create.c.orig +++ create.c @@ -60,7 +60,7 @@ extern long int crc_total; extern int ftsoptions; -extern int dflag, iflag, nflag, sflag; +extern int dflag, iflag, lflag, nflag, sflag; extern u_int keys; extern char fullpath[MAXPATHLEN]; extern int lineno; @@ -97,6 +97,10 @@ if (iflag) indent = p->fts_level * 4; switch(p->fts_info) { + case FTS_SL: + case FTS_SLNONE: + if (!lflag) + break; case FTS_D: if (!dflag) (void)printf("\n"); To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199812010350.WAA12951>