From dan@dan.emsphone.com  Sun Jun  8 10:44:50 2003
Return-Path: <dan@dan.emsphone.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 3D60E37B401
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  8 Jun 2003 10:44:50 -0700 (PDT)
Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101])
	by mx1.FreeBSD.org (Postfix) with ESMTP id A5F6443F85
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  8 Jun 2003 10:44:49 -0700 (PDT)
	(envelope-from dan@dan.emsphone.com)
Received: (from dan@localhost)
	by dan.emsphone.com (8.12.9/8.12.9) id h58HinCU027477;
	Sun, 8 Jun 2003 12:44:49 -0500 (CDT)
	(envelope-from dan)
Message-Id: <200306081744.h58HinCU027477@dan.emsphone.com>
Date: Sun, 8 Jun 2003 12:44:49 -0500 (CDT)
From: Dan Nelson <dnelson@allantgroup.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] Let mtree -U update mtime
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         53063
>Category:       bin
>Synopsis:       [PATCH] Let mtree -U update mtime
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jun 08 10:50:05 PDT 2003
>Closed-Date:    Fri Oct 31 05:39:49 PST 2003
>Last-Modified:  Fri Oct 31 05:39:49 PST 2003
>Originator:     Dan Nelson
>Release:        FreeBSD 5.1-BETA i386
>Organization:
The Allant Group
>Environment:
System: FreeBSD dan.emsphone.com 5.1-BETA FreeBSD 5.1-BETA #271: Thu May 29 16:33:28 CDT 2003 dan@dan.emsphone.com:/usr/src/sys/i386/compile/DANSMP i386


	
>Description:

mtree will not update timestamps when run with -U.  If you have
duplicated a directory tree with cp -R instead of cp -pR, this patch
lets you use mtree to correct the missing ownership/modes/timestamps.

	
>How-To-Repeat:
	
>Fix:

Index: compare.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/mtree/compare.c,v
retrieving revision 1.26
diff -u -p -r1.26 compare.c
--- compare.c	3 May 2003 21:06:37 -0000	1.26
+++ compare.c	8 Jun 2003 17:35:05 -0000
@@ -190,8 +190,21 @@ typeerr:		LABEL;
 		LABEL;
 		(void)printf("%smodification time expected %.24s ",
 		    tab, ctime(&s->st_mtimespec.tv_sec));
-		(void)printf("found %.24s\n",
+		(void)printf("found %.24s",
 		    ctime(&p->fts_statp->st_mtimespec.tv_sec));
+		if (uflag) {
+		    struct timeval tv[2];
+		    tv[0].tv_sec = s->st_mtimespec.tv_sec;
+		    tv[0].tv_usec = s->st_mtimespec.tv_nsec / 1000;
+		    tv[1] = tv[0];
+		    if (utimes(p->fts_accpath, tv))
+				(void)printf(" not modified: %s\n",
+				    strerror(errno));
+			else
+				(void)printf(" modified\n");
+        }
+		else
+			(void)printf("\n");
 		tab = "\t";
 	}
 	if (s->flags & F_CKSUM) {
@@ -364,7 +377,11 @@ rlink(name)
 	register int len;
 
 	if ((len = readlink(name, lbuf, sizeof(lbuf) - 1)) == -1)
-		err(1, "line %d: %s", lineno, name);
+	{
+		strcpy(lbuf, "Unknown!");
+		return lbuf;
+	}
+	/*	err(1, "line %d: %s", lineno, name); */
 	lbuf[len] = '\0';
 	return (lbuf);
 }
Index: mtree.8
===================================================================
RCS file: /home/ncvs/src/usr.sbin/mtree/mtree.8,v
retrieving revision 1.39
diff -u -p -r1.39 mtree.8
--- mtree.8	12 Dec 2002 17:26:02 -0000	1.39
+++ mtree.8	8 Jun 2003 17:42:00 -0000
@@ -76,8 +76,9 @@ Follow all symbolic links in the file hi
 Don't follow symbolic links in the file hierarchy, instead consider
 the symbolic link itself in any comparisons. This is the default.
 .It Fl U
-Modify the owner, group and permissions of existing files to match
-the specification and create any missing directories or symbolic links.
+Modify the owner, group, permissions, and modification time of existing 
+files to match the specification and create any missing directories or 
+symbolic links.
 User, group and permissions must all be specified for missing directories
 to be created.
 Corrected mismatches are not considered errors.

	


>Release-Note:
>Audit-Trail:

From: Dan Nelson <dnelson@allantgroup.com>
To: FreeBSD-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/53063: [PATCH] Let mtree -U update mtime
Date: Thu, 30 Oct 2003 13:18:33 -0600

 Updated patch.  The original had an extra fix for a failing readlink
 call, but I cannot remember what would cause the call to fail.
 Something to do with reading links over NFS mounts, maybe.
 
 Index: compare.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/mtree/compare.c,v
 retrieving revision 1.29
 diff -u -r1.29 compare.c
 --- compare.c	30 Oct 2003 12:03:25 -0000	1.29
 +++ compare.c	30 Oct 2003 19:03:49 -0000
 @@ -184,8 +184,21 @@
  		LABEL;
  		(void)printf("%smodification time expected %.24s ",
  		    tab, ctime(&s->st_mtimespec.tv_sec));
 -		(void)printf("found %.24s\n",
 +		(void)printf("found %.24s",
  		    ctime(&p->fts_statp->st_mtimespec.tv_sec));
 +		if (uflag) {
 +		    struct timeval tv[2];
 +		    tv[0].tv_sec = s->st_mtimespec.tv_sec;
 +		    tv[0].tv_usec = s->st_mtimespec.tv_nsec / 1000;
 +		    tv[1] = tv[0];
 +		    if (utimes(p->fts_accpath, tv))
 +				(void)printf(" not modified: %s\n",
 +				    strerror(errno));
 +			else
 +				(void)printf(" modified\n");
 +        }
 +		else
 +			(void)printf("\n");
  		tab = "\t";
  	}
  	if (s->flags & F_CKSUM) {
 Index: mtree.8
 ===================================================================
 RCS file: /home/ncvs/src/usr.sbin/mtree/mtree.8,v
 retrieving revision 1.40
 diff -u -r1.40 mtree.8
 --- mtree.8	14 Sep 2003 13:41:58 -0000	1.40
 +++ mtree.8	30 Oct 2003 18:46:48 -0000
 @@ -76,8 +76,9 @@
  Don't follow symbolic links in the file hierarchy, instead consider
  the symbolic link itself in any comparisons. This is the default.
  .It Fl U
 -Modify the owner, group and permissions of existing files to match
 -the specification and create any missing directories or symbolic links.
 +Modify the owner, group, permissions, and modification time of existing 
 +files to match the specification and create any missing directories or 
 +symbolic links.
  User, group and permissions must all be specified for missing directories
  to be created.
  Corrected mismatches are not considered errors.
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Fri Oct 31 05:39:39 PST 2003 
State-Changed-Why:  
Fixed, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=53063 
>Unformatted:
