Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Aug 2018 02:27:18 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r337521 - stable/11/usr.bin/gzip
Message-ID:  <201808090227.w792RI5o083013@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808090227.w792RI5o083013>