svn commit: r337521 - stable/11/usr.bin/gzip

Xin LI delphij at FreeBSD.org
Thu Aug 9 02:27:19 UTC 2018


Author: delphij
Date: Thu Aug  9 02:27:18 2018
New Revision: 337521
URL: https://svnweb.freebsd.org/changeset/base/337521

Log:
  MFC r336121+r336127(cem): Don't delete outfile unconditionally.

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

Modified: stable/11/usr.bin/gzip/gzip.c
==============================================================================
--- stable/11/usr.bin/gzip/gzip.c	Thu Aug  9 02:06:25 2018	(r337520)
+++ stable/11/usr.bin/gzip/gzip.c	Thu Aug  9 02:27:18 2018	(r337521)
@@ -1424,6 +1424,7 @@ file_uncompress(char *file, char *outfile, size_t outs
 	unsigned char header1[4];
 	enum filetype method;
 	int fd, ofd, zfd = -1;
+	int error;
 	size_t in_size;
 #ifndef SMALL
 	ssize_t rv;
@@ -1597,14 +1598,21 @@ file_uncompress(char *file, char *outfile, size_t outs
 
 		size = zuncompress(in, out, NULL, 0, NULL);
 		/* need to fclose() if ferror() is true... */
-		if (ferror(in) | fclose(in)) {
-			maybe_warn("failed infile fclose");
-			unlink(outfile);
+		error = ferror(in);
+		if (error | fclose(in)) {
+			if (error)
+				maybe_warn("failed infile");
+			else
+				maybe_warn("failed infile fclose");
+			if (cflag == 0)
+				unlink(outfile);
 			(void)fclose(out);
+			goto lose;
 		}
 		if (fclose(out) != 0) {
 			maybe_warn("failed outfile fclose");
-			unlink(outfile);
+			if (cflag == 0)
+				unlink(outfile);
 			goto lose;
 		}
 		break;


More information about the svn-src-stable-11 mailing list