Blame SOURCES/procmail-3.22-truncate.patch

54be6b
--- procmail-3.22/src/mailfold.c.truncate	2007-03-27 13:24:05.000000000 +0200
54be6b
+++ procmail-3.22/src/mailfold.c	2007-03-27 13:25:06.000000000 +0200
54be6b
@@ -30,6 +30,7 @@
54be6b
 
54be6b
 int logopened,rawnonl;
54be6b
 off_t lasttell;
54be6b
+static int trunced;
54be6b
 static long lastdump;
54be6b
 static volatile int mailread;	/* if the mail is completely read in already */
54be6b
 static struct dyna_array confield;		  /* escapes, concatenations */
54be6b
@@ -81,6 +82,7 @@
54be6b
  long len;
54be6b
 { int i;long part;
54be6b
   lasttell=i= -1;SETerrno(EBADF);
54be6b
+  trunced=0;
54be6b
   if(s>=0)
54be6b
    { if(ft_lock(type)&&(lseek(s,(off_t)0,SEEK_END),fdlock(s)))
54be6b
 	nlog("Kernel-lock failed\n");
54be6b
@@ -120,13 +122,18 @@
54be6b
       }
54be6b
 writefin:
54be6b
      i=type!=ft_PIPE&&fsync(s)&&errno!=EINVAL;	  /* EINVAL => wasn't a file */
54be6b
+     if ((i||len)&&lasttell>=0)
54be6b
+      { int serrno=errno;
54be6b
+	if(!ftruncate(s,lasttell)) trunced=1;
54be6b
+	SETerrno(serrno);
54be6b
+      }
54be6b
      if(ft_lock(type))
54be6b
       { int serrno=errno;		       /* save any error information */
54be6b
 	if(fdunlock())
54be6b
 	   nlog("Kernel-unlock failed\n");
54be6b
 	SETerrno(serrno);
54be6b
       }
54be6b
-     i=rclose(s)||i;
54be6b
+     i=rclose(s)||i; /* if this fails, we should truncate, but it's too late */
54be6b
    }			   /* return an error even if nothing was to be sent */
54be6b
   return i&&!len?-1:len;
54be6b
 }
54be6b
@@ -237,7 +244,7 @@
54be6b
 #endif
54be6b
 	      default:writeerr(buf);
54be6b
 	    }
54be6b
-	   if(lasttell>=0&&!truncate(boxname,lasttell)&&(logopened||verbose))
54be6b
+	   if(lasttell>=0&&trunced&&(logopened||verbose))
54be6b
 	      nlog("Truncated file to former size\n");	    /* undo garbage */
54be6b
 ret0:	   return 0;
54be6b
 	 }