From nobody@FreeBSD.org  Fri Feb  1 15:54:30 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 274A616A46D
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  1 Feb 2008 15:54:30 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 1887013C4FF
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  1 Feb 2008 15:54:30 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m11FqbLd065814
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 1 Feb 2008 15:52:37 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m11FqbO4065813;
	Fri, 1 Feb 2008 15:52:37 GMT
	(envelope-from nobody)
Message-Id: <200802011552.m11FqbO4065813@www.freebsd.org>
Date: Fri, 1 Feb 2008 15:52:37 GMT
From: Ighighi <ighighi@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch]: gzip cannot preserve utimes() because it first sets chflags()
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         120208
>Category:       bin
>Synopsis:       [patch]: gzip(1) cannot preserve utimes() because it first sets chflags()
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    rwatson
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Feb 01 16:00:04 UTC 2008
>Closed-Date:    Tue Feb 10 09:39:44 UTC 2009
>Last-Modified:  Tue Feb 10 09:39:44 UTC 2009
>Originator:     Ighighi
>Release:        6.3-STABLE
>Organization:
>Environment:
FreeBSD orion 6.3-STABLE FreeBSD 6.3-STABLE #0: Fri Jan 25 17:39:39 VET 2008     root@orion.nebula.mil:/usr/obj/usr/src/sys/CUSTOM  i386

>Description:
gzip(1) cannot preserve file's times from input files because it first sets the file's flags.  It happens with the immutable flag.
>How-To-Repeat:
$ /usr/bin/touch /tmp/foo
$ /bin/chflags uchg /tmp/foo
$ /usr/bin/gzip -v /tmp/foo
gzip: couldn't utimes: /tmp/foo.gz: Operation not permitted
/tmp/foo:         -99.9% -- replaced with /tmp/foo.gz
>Fix:
Attached patch available

Patch attached with submission follows:

--- gzip.c.orig	2007-08-05 22:31:25.000000000 -0400
+++ gzip.c	2008-02-01 11:08:35.953127226 -0430
@@ -1075,14 +1077,14 @@ copymodes(int fd, const struct stat *sbp
 	if (fchmod(fd, sb.st_mode) < 0)
 		maybe_warn("couldn't fchmod: %s", file);
 
-	/* only try flags if they exist already */
-        if (sb.st_flags != 0 && fchflags(fd, sb.st_flags) < 0)
-		maybe_warn("couldn't fchflags: %s", file);
-
 	TIMESPEC_TO_TIMEVAL(&times[0], &sb.st_atimespec);
 	TIMESPEC_TO_TIMEVAL(&times[1], &sb.st_mtimespec);
 	if (futimes(fd, times) < 0)
 		maybe_warn("couldn't utimes: %s", file);
+
+	/* only try flags if they exist already */
+        if (sb.st_flags != 0 && fchflags(fd, sb.st_flags) < 0)
+		maybe_warn("couldn't fchflags: %s", file);
 }
 #endif
 


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->rwatson 
Responsible-Changed-By: rwatson 
Responsible-Changed-When: Sun Mar 9 11:19:16 UTC 2008 
Responsible-Changed-Why:  
Take ownership of this PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120208 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/120208: commit references a PR
Date: Sun,  9 Mar 2008 11:16:47 +0000 (UTC)

 rwatson     2008-03-09 11:16:42 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.bin/gzip         gzip.c 
   Log:
   When gzipping to a target file, only set the source file flags on the
   target file after the timestamp has been set; otherwise setting the
   timestamp will fail if the flags don't permit it (i.e., uchg).
   
   MFC after:      1 week
   PR:             120208
   Submitted by:   Ighighi <ighighi at gmail.com>
   
   Revision  Changes    Path
   1.5       +4 -4      src/usr.bin/gzip/gzip.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: rwatson 
State-Changed-When: Sun Mar 9 11:22:06 UTC 2008 
State-Changed-Why:  
Transition to patched state while awaiting MFC. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120208 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/120208: commit references a PR
Date: Sun, 16 Mar 2008 18:53:22 +0000 (UTC)

 rwatson     2008-03-16 18:53:17 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     usr.bin/gzip         gzip.c 
   Log:
   Merge gzip.c:1.5 from HEAD to RELENG_7:
   
     When gzipping to a target file, only set the source file flags on the
     target file after the timestamp has been set; otherwise setting the
     timestamp will fail if the flags don't permit it (i.e., uchg).
   
     PR:             120208
     Submitted by:   Ighighi <ighighi at gmail.com>
   
   Revision  Changes    Path
   1.4.2.2   +4 -4      src/usr.bin/gzip/gzip.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: rwatson 
State-Changed-When: Tue Feb 10 09:39:08 UTC 2009 
State-Changed-Why:  
Close following MFC.  This fix appeared in FreeBSD 7.1. 

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