You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by mt...@apache.org on 2010/12/10 18:06:50 UTC
svn commit: r1044440 - /apr/apr/trunk/file_io/unix/seek.c
Author: mturk
Date: Fri Dec 10 17:06:49 2010
New Revision: 1044440
URL: http://svn.apache.org/viewvc?rev=1044440&view=rev
Log:
Fix file_trunc for buffered files. Make sure the write buffer is flushed before truncate call
Modified:
apr/apr/trunk/file_io/unix/seek.c
Modified: apr/apr/trunk/file_io/unix/seek.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/seek.c?rev=1044440&r1=1044439&r2=1044440&view=diff
==============================================================================
--- apr/apr/trunk/file_io/unix/seek.c (original)
+++ apr/apr/trunk/file_io/unix/seek.c Fri Dec 10 17:06:49 2010
@@ -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;
}
Re: svn commit: r1044440 - /apr/apr/trunk/file_io/unix/seek.c
Posted by Jim Jagielski <ji...@jaguNET.com>.
On Dec 10, 2010, at 12:19 PM, Mladen Turk wrote:
> On 12/10/2010 06:06 PM, mturk@apache.org wrote:
>> Author: mturk
>> Date: Fri Dec 10 17:06:49 2010
>> New Revision: 1044440
>>
>> URL: http://svn.apache.org/viewvc?rev=1044440&view=rev
>> Log:
>> Fix file_trunc for buffered files. Make sure the write buffer is flushed before truncate call
>>
>> Modified:
>> apr/apr/trunk/file_io/unix/seek.c
>>
>
>
> Any problem with porting that to the stable branches?
> In case of buffered files apr_file_trunc just doesn't
> work if there is something in the write buffer below
> the truncation point.
>
No prob from my PoV... +1
Re: svn commit: r1044440 - /apr/apr/trunk/file_io/unix/seek.c
Posted by Mladen Turk <mt...@apache.org>.
On 12/10/2010 06:06 PM, mturk@apache.org wrote:
> Author: mturk
> Date: Fri Dec 10 17:06:49 2010
> New Revision: 1044440
>
> URL: http://svn.apache.org/viewvc?rev=1044440&view=rev
> Log:
> Fix file_trunc for buffered files. Make sure the write buffer is flushed before truncate call
>
> Modified:
> apr/apr/trunk/file_io/unix/seek.c
>
Any problem with porting that to the stable branches?
In case of buffered files apr_file_trunc just doesn't
work if there is something in the write buffer below
the truncation point.
Regards
--
^TM