Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Jul 2018 06:19:33 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r336121 - head/usr.bin/gzip
Message-ID:  <201807090619.w696JXOv089732@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Mon Jul  9 06:19:33 2018
New Revision: 336121
URL: https://svnweb.freebsd.org/changeset/base/336121

Log:
  Don't delete outfile unconditionally.
  
  MFC after:	1 month

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

Modified: head/usr.bin/gzip/gzip.c
==============================================================================
--- head/usr.bin/gzip/gzip.c	Mon Jul  9 06:02:45 2018	(r336120)
+++ head/usr.bin/gzip/gzip.c	Mon Jul  9 06:19:33 2018	(r336121)
@@ -1429,6 +1429,7 @@ file_uncompress(char *file, char *outfile, size_t outs
 	unsigned char header1[4];
 	enum filetype method;
 	int fd, ofd, zfd = -1;
+	int err;
 	size_t in_size;
 #ifndef SMALL
 	ssize_t rv;
@@ -1601,14 +1602,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);
+		err = ferror(in);
+		if (err | fclose(in)) {
+			if (err)
+				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?201807090619.w696JXOv089732>