diff -upk.orig gzip-1.3.5.orig/gzip.c gzip-1.3.5/gzip.c --- gzip-1.3.5.orig/gzip.c 2005-05-19 17:00:28 +0000 +++ gzip-1.3.5/gzip.c 2005-05-19 17:29:22 +0000 @@ -878,8 +878,9 @@ local void treat_file(iname) } close(ifd); - if (!to_stdout && close(ofd)) { - write_error(); + /* Copy modes, times, ownership, and remove the input file */ + if (!to_stdout && method != -1) { + copy_stat(&istat); } if (method == -1) { if (!to_stdout) xunlink (ofname); @@ -899,10 +900,6 @@ local void treat_file(iname) } fprintf(stderr, "\n"); } - /* Copy modes, times, ownership, and remove the input file */ - if (!to_stdout) { - copy_stat(&istat); - } } /* ======================================================================== @@ -1720,17 +1717,8 @@ local void reset_times (name, statb) local void copy_stat(ifstat) struct stat *ifstat; { -#ifndef NO_UTIME - if (decompress && time_stamp != 0 && ifstat->st_mtime != time_stamp) { - ifstat->st_mtime = time_stamp; - if (verbose > 1) { - fprintf(stderr, "%s: time stamp restored\n", ofname); - } - } - reset_times(ofname, ifstat); -#endif /* Copy the protection modes */ - if (chmod(ofname, ifstat->st_mode & 07777)) { + if (fchmod(ofd, ifstat->st_mode & 07777)) { int e = errno; WARN((stderr, "%s: ", progname)); if (!quiet) { @@ -1739,9 +1727,20 @@ local void copy_stat(ifstat) } } #ifndef NO_CHOWN - chown(ofname, ifstat->st_uid, ifstat->st_gid); /* Copy ownership */ + fchown(ofd, ifstat->st_uid, ifstat->st_gid); /* Copy ownership */ #endif + if (close(ofd)) + write_error(); remove_ofname = 0; +#ifndef NO_UTIME + if (decompress && time_stamp != 0 && ifstat->st_mtime != time_stamp) { + ifstat->st_mtime = time_stamp; + if (verbose > 1) { + fprintf(stderr, "%s: time stamp restored\n", ofname); + } + } + reset_times(ofname, ifstat); +#endif /* It's now safe to remove the input file: */ if (xunlink (ifname)) { int e = errno;