Article View: comp.sources.d
Article #1972compress 4.1 file deletion fixes
From: David J. MacKenzie
Date: Thu, 27 Jun 1991 07:22
Date: Thu, 27 Jun 1991 07:22
129 lines
4501 bytes
4501 bytes
> This new version of compress seems to have the old problem with zcat
> somtimes deleting the compressed file when interrupted. I thought
> this bug was fixed long ago.
To be precise, comp.sources.misc "v06i066: compress 4.0 bug fixes"
submitted by res@cbnews.ATT.COM (Robert E. Stampfli) contains that
fix. It drops in to 4.1 with only a few small changes. Below, I have
adapted Robert's fixes for compress 4.1. I also fixed a problem with
declaring signal handlers in the wrong place, which prevented compress
from compiling with gcc. And I fixed the problem that the error
messages that compress prints #ifdef SHORTNAMES when it can't tack on
a .Z only mentioned the last component of the pathname. This happened
both in Robert's patch and in the stock code, when creating the output
file.
--- compress.c.dist Tue Jun 25 17:36:59 1991
+++ compress.c Thu Jun 27 02:19:55 1991
@@ -373,6 +373,7 @@
#define CLEAR 256 /* table clear output code */
int force = 0;
+int valid = 0; /* set when signal can remove ofname */
char ofname [100];
#ifdef DEBUG
int verbose = 0;
@@ -429,18 +430,18 @@
int overwrite = 0; /* Do not overwrite unless given -f flag */
int recursive = 0; /* compress directories */
+extern onintr(), oops();
main( argc, argv )
register int argc; char **argv;
{
char **filelist, **fileptr;
char *cp, *rindex(), *malloc();
- extern onintr(), oops();
if ( (bgnd_flag = signal ( SIGINT, SIG_IGN )) != SIG_IGN ) {
signal ( SIGINT, onintr );
- signal ( SIGSEGV, oops );
}
+ signal ( SIGSEGV, oops );
#ifdef COMPATIBLE
nomagic = 1; /* Original didn't have a magic number */
@@ -615,6 +616,14 @@
** directory, but it shouldn't do any harm.
*/
if (strcmp(tempname + strlen(tempname) - 2, ".Z") != 0) {
+#ifdef SHORTNAMES
+ if ((cp=rindex(tempname,'/')) != NULL) cp++;
+ else cp = tempname;
+ if (strlen(cp) > 12) {
+ fprintf(stderr,"%s.Z: No such file or directory\n",tempname);
+ return;
+ }
+#endif /* SHORTNAMES */
strcat(tempname,".Z");
errno = 0;
#ifdef BSD4
@@ -732,7 +741,7 @@
if ((cp=rindex(ofname,'/')) != NULL) cp++;
else cp = ofname;
if (strlen(cp) > 12) {
- fprintf(stderr,"%s: filename too long to tack on .Z\n",cp);
+ fprintf(stderr,"%s: filename too long to tack on .Z\n",ofname);
signal(SIGINT,onintr);
return;
}
@@ -746,8 +755,7 @@
response[0] = 'n';
fprintf(stderr, "%s already exists;", ofname);
if (foreground()) {
- fprintf(stderr, " do you wish to overwrite %s (y or n)? ",
- ofname);
+ fprintf(stderr, " OK to overwrite (y or n)? ");
fflush(stderr);
read(2, response, 2);
while (response[1] != '\n') {
@@ -765,6 +773,7 @@
}
signal(SIGINT,onintr);
if(zcat_flg == 0) { /* Open output file */
+ valid = 1;
if (freopen(ofname, "w", stdout) == NULL) {
perror(ofname);
return;
@@ -1400,7 +1409,8 @@
writeerr()
{
perror ( ofname );
- unlink ( ofname );
+ if (valid)
+ unlink ( ofname );
exit ( 1 );
}
@@ -1439,6 +1449,7 @@
timep[0] = statbuf.st_atime;
timep[1] = statbuf.st_mtime;
utime(ofname, timep); /* Update last accessed and modified times */
+ valid = 0; /* prevent latent ofname removal */
if (unlink(ifname)) /* Remove input file */
perror(ifname);
if(!quiet)
@@ -1469,7 +1480,8 @@
onintr ( )
{
- unlink ( ofname );
+ if (valid)
+ unlink ( ofname );
exit ( 1 );
}
@@ -1477,7 +1489,8 @@
{
if ( do_decomp == 1 )
fprintf ( stderr, "uncompress: corrupt input\n" );
- unlink ( ofname );
+ if (valid)
+ unlink ( ofname );
exit ( 1 );
}
--
David J. MacKenzie <djm@eng.umd.edu> <djm@ai.mit.edu>
Technical Details
Message-ID:
<DJM.91Jun27022257@egypt.eng.umd.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!ncar!gatech!udel!haven.umd.edu!mimsy!mojo.eng.umd.edu!mojo!djmReferences:
<csm-v20i064=compress.133807@sparky.imd.sterling.com> <1991Jun26.221030.23987@motcad.portal.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!ncar!gatech!udel!haven.umd.edu!mimsy!mojo.eng.umd.edu!mojo!djm From: djm@eng.umd.edu (David J. MacKenzie) Newsgroups: comp.sources.d,comp.sources.bugs,alt.sources.patches Subject: compress 4.1 file deletion fixes Message-ID: <DJM.91Jun27022257@egypt.eng.umd.edu> Date: 27 Jun 91 07:22:57 GMT References: <csm-v20i064=compress.133807@sparky.imd.sterling.com> <1991Jun26.221030.23987@motcad.portal.com> Organization: Project GLUE, University of Maryland Lines: 129 In-Reply-To: jtc@motcad.portal.com's message of 26 Jun 91 22:10:30 GMT