components/procmail/patches/05-procmail-3.22-truncate.patch
changeset 1069 415af38929a1
parent 1068 0b7caaf07429
equal deleted inserted replaced
1068:0b7caaf07429 1069:415af38929a1
       
     1 --- procmail-3.22/src/mailfold.c.truncate	2007-03-27 13:24:05.000000000 +0200
       
     2 +++ procmail-3.22/src/mailfold.c	2007-03-27 13:25:06.000000000 +0200
       
     3 @@ -30,6 +30,7 @@
       
     4  
       
     5  int logopened,rawnonl;
       
     6  off_t lasttell;
       
     7 +static int trunced;
       
     8  static long lastdump;
       
     9  static volatile int mailread;	/* if the mail is completely read in already */
       
    10  static struct dyna_array confield;		  /* escapes, concatenations */
       
    11 @@ -81,6 +82,7 @@
       
    12   long len;
       
    13  { int i;long part;
       
    14    lasttell=i= -1;SETerrno(EBADF);
       
    15 +  trunced=0;
       
    16    if(s>=0)
       
    17     { if(ft_lock(type)&&(lseek(s,(off_t)0,SEEK_END),fdlock(s)))
       
    18  	nlog("Kernel-lock failed\n");
       
    19 @@ -120,13 +122,18 @@
       
    20        }
       
    21  writefin:
       
    22       i=type!=ft_PIPE&&fsync(s)&&errno!=EINVAL;	  /* EINVAL => wasn't a file */
       
    23 +     if ((i||len)&&lasttell>=0)
       
    24 +      { int serrno=errno;
       
    25 +	if(!ftruncate(s,lasttell)) trunced=1;
       
    26 +	SETerrno(serrno);
       
    27 +      }
       
    28       if(ft_lock(type))
       
    29        { int serrno=errno;		       /* save any error information */
       
    30  	if(fdunlock())
       
    31  	   nlog("Kernel-unlock failed\n");
       
    32  	SETerrno(serrno);
       
    33        }
       
    34 -     i=rclose(s)||i;
       
    35 +     i=rclose(s)||i; /* if this fails, we should truncate, but it's too late */
       
    36     }			   /* return an error even if nothing was to be sent */
       
    37    return i&&!len?-1:len;
       
    38  }
       
    39 @@ -237,7 +244,7 @@
       
    40  #endif
       
    41  	      default:writeerr(buf);
       
    42  	    }
       
    43 -	   if(lasttell>=0&&!truncate(boxname,lasttell)&&(logopened||verbose))
       
    44 +	   if(lasttell>=0&&trunced&&(logopened||verbose))
       
    45  	      nlog("Truncated file to former size\n");	    /* undo garbage */
       
    46  ret0:	   return 0;
       
    47  	 }