apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject svn commit: r1241173 - in /apr/apr/branches/1.4.x: ./ CHANGES file_io/unix/seek.c
Date Mon, 06 Feb 2012 20:54:17 GMT
Author: bojan
Date: Mon Feb  6 20:54:16 2012
New Revision: 1241173

URL: http://svn.apache.org/viewvc?rev=1241173&view=rev
Log:
Backport r1044440 from trunk to 1.4.x.
Fix file_trunc for buffered files. Make sure the write buffer is flushed before truncate call

Modified:
    apr/apr/branches/1.4.x/   (props changed)
    apr/apr/branches/1.4.x/CHANGES
    apr/apr/branches/1.4.x/file_io/unix/seek.c

Propchange: apr/apr/branches/1.4.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Feb  6 20:54:16 2012
@@ -1,2 +1,2 @@
 /apr/apr/branches/1.5.x:1083592,1183724,1240474
-/apr/apr/trunk:733052,747990,748361,748371,748565,748888,748902,748988,749810,760443,782838,783398,783958,784633,784773,788588,793192-793193,794118,794485,795267,799497,800627,809745,809854,810472,811455,813063,821306,829490,831641,835607,905040,908427,910419,917837-917838,979891,983618,990435,1072165,1078845,1183683,1183685-1183686,1183688,1183698,1236970,1237078,1237507,1240472
+/apr/apr/trunk:733052,747990,748361,748371,748565,748888,748902,748988,749810,760443,782838,783398,783958,784633,784773,788588,793192-793193,794118,794485,795267,799497,800627,809745,809854,810472,811455,813063,821306,829490,831641,835607,905040,908427,910419,917837-917838,979891,983618,990435,1044440,1072165,1078845,1183683,1183685-1183686,1183688,1183698,1236970,1237078,1237507,1240472

Modified: apr/apr/branches/1.4.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/CHANGES?rev=1241173&r1=1241172&r2=1241173&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/CHANGES [utf-8] (original)
+++ apr/apr/branches/1.4.x/CHANGES [utf-8] Mon Feb  6 20:54:16 2012
@@ -1,6 +1,9 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 1.4.6
 
+  *) Flush write buffer before truncate call on a file.
+     [Mladen Turk]
+
   *) Security: oCERT-2011-003
      Randomise hashes by providing a seed. 
      [Bojan Smojver, Branko ─îibej, Ruediger Pluem et al.]

Modified: apr/apr/branches/1.4.x/file_io/unix/seek.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/file_io/unix/seek.c?rev=1241173&r1=1241172&r2=1241173&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/file_io/unix/seek.c (original)
+++ apr/apr/branches/1.4.x/file_io/unix/seek.c Mon Feb  6 20:54:16 2012
@@ -33,7 +33,7 @@ static apr_status_t setptr(apr_file_t *t
     if (newbufpos >= 0 && newbufpos <= thefile->dataRead) {
         thefile->bufpos = newbufpos;
         rv = APR_SUCCESS;
-    } 
+    }
     else {
         if (lseek(thefile->filedes, pos, SEEK_SET) != -1) {
             thefile->bufpos = thefile->dataRead = 0;
@@ -98,6 +98,30 @@ APR_DECLARE(apr_status_t) apr_file_seek(
 
 apr_status_t apr_file_trunc(apr_file_t *fp, apr_off_t offset)
 {
+    if (fp->buffered) {
+        int rc = 0;
+        file_lock(fp);
+        if (fp->direction == 1 && fp->bufpos != 0) {
+            apr_off_t len = fp->filePtr + fp->bufpos;
+            if (offset < len) {
+                /* New file end fall below our write buffer limit.
+                 * Figure out if and what needs to be flushed.
+                 */
+                apr_off_t off = len - offset;
+                if (off >= 0 && off <= fp->bufpos)
+                    fp->bufpos = fp->bufpos - (size_t)off;
+                else
+                    fp->bufpos = 0;
+            }
+            rc = apr_file_flush_locked(fp);
+            /* Reset buffer positions for write mode */
+            fp->bufpos = fp->direction = fp->dataRead = 0;
+        }
+        if (rc) {
+            return rc;
+        }
+        file_unlock(fp);
+    }
     if (ftruncate(fp->filedes, offset) == -1) {
         return errno;
     }



Mime
View raw message