Bug 147275 - [patch] gzip(1): gzip -c <file> does not save original time stamp
Summary: [patch] gzip(1): gzip -c <file> does not save original time stamp
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 8.0-STABLE
Hardware: Any Any
: Normal Affects Only Me
Assignee: Xin LI
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-01 11:10 UTC by Thomas Quinot
Modified: 2010-06-12 06:39 UTC (History)
0 users

See Also:


Attachments
file.diff (685 bytes, patch)
2010-06-01 11:10 UTC, Thomas Quinot
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Quinot 2010-06-01 11:10:02 UTC
	When a file name is provided on the command line, gzip -c does not
	save its timestamp in the output compressed stream.

How-To-Repeat: 	cd /tmp
	touch foo
	gzip -c foo > foo1.gz
	gzip foo
	file foo1.gz foo.gz

foo1.gz: gzip compressed data, was "foo", from Unix
foo.gz:  gzip compressed data, was "foo", from Unix, last modified: Tue Jun  1 11:55:30 2010
Comment 1 Jilles Tjoelker freebsd_committer freebsd_triage 2010-06-05 20:49:53 UTC
I'm not sure if we care, but this patch breaks compilation with SMALL
defined (if it is not already broken, as SMALL does not appear to be
used).

-- 
Jilles Tjoelker
Comment 2 Xin LI freebsd_committer freebsd_triage 2010-06-07 10:11:42 UTC
Responsible Changed
From-To: freebsd-bugs->delphij

Take.
Comment 3 Thomas Quinot freebsd_committer freebsd_triage 2010-06-07 10:16:08 UTC
* delphij@FreeBSD.org, 2010-06-07 :

> Responsible-Changed-From-To: freebsd-bugs->delphij
> Responsible-Changed-By: delphij
> Responsible-Changed-When: Mon Jun 7 09:11:42 UTC 2010
> Responsible-Changed-Why: 
> Take.

Thanks! Let me know if there's any further info I can provide.

Thomas.
Comment 4 dfilter service freebsd_committer freebsd_triage 2010-06-07 11:09:51 UTC
Author: delphij
Date: Mon Jun  7 10:09:40 2010
New Revision: 208888
URL: http://svn.freebsd.org/changeset/base/208888

Log:
  Correct a bug in gzip(1): make sure that initialize isb with fstat() on
  input file before using it.
  
  PR:		bin/147275
  Submitted by:	thomas
  MFC after:	1 week

Modified:
  head/usr.bin/gzip/gzip.c

Modified: head/usr.bin/gzip/gzip.c
==============================================================================
--- head/usr.bin/gzip/gzip.c	Mon Jun  7 08:23:16 2010	(r208887)
+++ head/usr.bin/gzip/gzip.c	Mon Jun  7 10:09:40 2010	(r208888)
@@ -1224,17 +1224,23 @@ file_compress(char *file, char *outfile,
 		return -1;
 	}
 
+#ifndef SMALL
+	if (fstat(in, &isb) != 0) {
+		maybe_warn("couldn't stat: %s", file);
+		close(in);
+		return -1;
+	}
+#endif
+
 	if (cflag == 0) {
 #ifndef SMALL
-		if (fstat(in, &isb) == 0) {
-			if (isb.st_nlink > 1 && fflag == 0) {
+		if (isb.st_nlink != 1 && fflag == 0) {
 				maybe_warnx("%s has %d other link%s -- "
 					    "skipping", file, isb.st_nlink - 1,
 					    isb.st_nlink == 1 ? "" : "s");
 				close(in);
 				return -1;
 			}
-		}
 
 		if (fflag == 0 && (suff = check_suffix(file, 0))
 		    && suff->zipped[0] != 0) {
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 5 Xin LI freebsd_committer freebsd_triage 2010-06-07 11:10:53 UTC
State Changed
From-To: open->patched

Fixed in -CURRENT, MFC reminder.
Comment 6 dfilter service freebsd_committer freebsd_triage 2010-06-12 06:23:14 UTC
Author: delphij
Date: Sat Jun 12 05:22:55 2010
New Revision: 209090
URL: http://svn.freebsd.org/changeset/base/209090

Log:
  MFC r208888,208889,209017:
  
   - make sure that initialize isb with fstat() on
     input file before using it. (bin/147275)
   - Fix grammar for st_nlink.
   - Style changes.
  
  PR:		bin/147275
  Approved by:	re (kensmith)

Modified:
  stable/8/usr.bin/gzip/gzip.c
Directory Properties:
  stable/8/usr.bin/gzip/   (props changed)

Modified: stable/8/usr.bin/gzip/gzip.c
==============================================================================
--- stable/8/usr.bin/gzip/gzip.c	Sat Jun 12 05:21:29 2010	(r209089)
+++ stable/8/usr.bin/gzip/gzip.c	Sat Jun 12 05:22:55 2010	(r209090)
@@ -65,10 +65,6 @@ __RCSID("$FreeBSD$");
 #include <getopt.h>
 #include <time.h>
 
-#ifndef PRIdOFF
-#define PRIdOFF PRId64
-#endif
-
 /* what type of file are we dealing with */
 enum filetype {
 	FT_GZIP,
@@ -1221,40 +1217,46 @@ file_compress(char *file, char *outfile,
 	in = open(file, O_RDONLY);
 	if (in == -1) {
 		maybe_warn("can't open %s", file);
-		return -1;
+		return (-1);
 	}
 
+#ifndef SMALL
+	if (fstat(in, &isb) != 0) {
+		maybe_warn("couldn't stat: %s", file);
+		close(in);
+		return (-1);
+	}
+#endif
+
 	if (cflag == 0) {
 #ifndef SMALL
-		if (fstat(in, &isb) == 0) {
-			if (isb.st_nlink > 1 && fflag == 0) {
-				maybe_warnx("%s has %d other link%s -- "
-					    "skipping", file, isb.st_nlink - 1,
-					    isb.st_nlink == 1 ? "" : "s");
-				close(in);
-				return -1;
-			}
+		if (isb.st_nlink > 1 && fflag == 0) {
+			maybe_warnx("%s has %d other link%s -- skipping",
+			    file, isb.st_nlink - 1,
+			    (isb.st_nlink - 1) == 1 ? "" : "s");
+			close(in);
+			return (-1);
 		}
 
-		if (fflag == 0 && (suff = check_suffix(file, 0))
-		    && suff->zipped[0] != 0) {
+		if (fflag == 0 && (suff = check_suffix(file, 0)) &&
+		    suff->zipped[0] != 0) {
 			maybe_warnx("%s already has %s suffix -- unchanged",
-				    file, suff->zipped);
+			    file, suff->zipped);
 			close(in);
-			return -1;
+			return (-1);
 		}
 #endif
 
 		/* Add (usually) .gz to filename */
 		if ((size_t)snprintf(outfile, outsize, "%s%s",
-					file, suffixes[0].zipped) >= outsize)
+		    file, suffixes[0].zipped) >= outsize)
 			memcpy(outfile + outsize - suffixes[0].ziplen - 1,
-				suffixes[0].zipped, suffixes[0].ziplen + 1);
+			    suffixes[0].zipped, suffixes[0].ziplen + 1);
 
 #ifndef SMALL
 		if (check_outfile(outfile) == 0) {
 			close(in);
-			return -1;
+			return (-1);
 		}
 #endif
 	}
@@ -1264,7 +1266,7 @@ file_compress(char *file, char *outfile,
 		if (out == -1) {
 			maybe_warn("could not create output: %s", outfile);
 			fclose(stdin);
-			return -1;
+			return (-1);
 		}
 #ifndef SMALL
 		remove_file = outfile;
@@ -1284,7 +1286,7 @@ file_compress(char *file, char *outfile,
 	 * has the expected size.
 	 */
 	if (cflag != 0)
-		return insize == -1 ? -1 : size;
+		return (insize == -1 ? -1 : size);
 
 #ifndef SMALL
 	if (fstat(out, &osb) != 0) {
@@ -1293,9 +1295,8 @@ file_compress(char *file, char *outfile,
 	}
 
 	if (osb.st_size != size) {
-		maybe_warnx("output file: %s wrong size (%" PRIdOFF
-				" != %" PRIdOFF "), deleting",
-				outfile, osb.st_size, size);
+		maybe_warnx("output file: %s wrong size (%ju != %ju), deleting",
+		    outfile, (uintmax_t)osb.st_size, (uintmax_t)size);
 		goto bad_outfile;
 	}
 
@@ -1307,7 +1308,7 @@ file_compress(char *file, char *outfile,
 
 	/* output is good, ok to delete input */
 	unlink_input(file, &isb);
-	return size;
+	return (size);
 
 #ifndef SMALL
     bad_outfile:
@@ -1316,7 +1317,7 @@ file_compress(char *file, char *outfile,
 
 	maybe_warnx("leaving original %s", file);
 	unlink(outfile);
-	return size;
+	return (size);
 #endif
 }
 
@@ -1564,9 +1565,8 @@ file_uncompress(char *file, char *outfil
 		return -1;
 	}
 	if (osb.st_size != size) {
-		maybe_warnx("stat gave different size: %" PRIdOFF
-				" != %" PRIdOFF " (leaving original)",
-				size, osb.st_size);
+		maybe_warnx("stat gave different size: %ju != %ju (leaving original)",
+		    (uintmax_t)size, (uintmax_t)osb.st_size);
 		close(ofd);
 		unlink(outfile);
 		return -1;
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 7 Xin LI freebsd_committer freebsd_triage 2010-06-12 06:39:18 UTC
State Changed
From-To: patched->closed

MFC'ed to 8.1-PRERELEASE.