apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roo...@apache.org
Subject svn commit: r373455 - in /apr/apr/branches/0.9.x: CHANGES file_io/win32/seek.c test/testfile.c
Date Mon, 30 Jan 2006 07:04:37 GMT
Author: rooneg
Date: Sun Jan 29 23:04:30 2006
New Revision: 373455

URL: http://svn.apache.org/viewcvs?rev=373455&view=rev
Log:
Merge r373453 into 0.9.x, with necessary changes to tests to account for
the old test framework.

Original log message:

Fix bug #38438, seeks are broken for files opened for append in xthread
mode on win32.

Submitted by: M Joonas Pihlaja <jpihlaja cc.helsinki.fi>
Test by: Garrett Rooney

* file_io/win32/seek.c
  (apr_file_seek): Fix APR_END case of APR_XTHREAD case.

* test/testfile.c
  (test_xthread): New test.
  (testfile): Run new test.

* CHANGES: Note change.

Modified:
    apr/apr/branches/0.9.x/CHANGES
    apr/apr/branches/0.9.x/file_io/win32/seek.c
    apr/apr/branches/0.9.x/test/testfile.c

Modified: apr/apr/branches/0.9.x/CHANGES
URL: http://svn.apache.org/viewcvs/apr/apr/branches/0.9.x/CHANGES?rev=373455&r1=373454&r2=373455&view=diff
==============================================================================
--- apr/apr/branches/0.9.x/CHANGES (original)
+++ apr/apr/branches/0.9.x/CHANGES Sun Jan 29 23:04:30 2006
@@ -1,5 +1,8 @@
 Changes with APR 0.9.8
 
+  *) Fix seeks with files opened in xthread mode for append on win32.
+     [M Joonas Pihlaja <jpihlaja cc.helsinki.fi>, Garrett Rooney]
+
   *) Keep testpipe.c from hanging on win32. [Garrett Rooney]
 
   *) Cause apr_file_write_full on win32 to consider the timeout value set by 

Modified: apr/apr/branches/0.9.x/file_io/win32/seek.c
URL: http://svn.apache.org/viewcvs/apr/apr/branches/0.9.x/file_io/win32/seek.c?rev=373455&r1=373454&r2=373455&view=diff
==============================================================================
--- apr/apr/branches/0.9.x/file_io/win32/seek.c (original)
+++ apr/apr/branches/0.9.x/file_io/win32/seek.c Sun Jan 29 23:04:30 2006
@@ -99,8 +99,8 @@
         
             case APR_END:
                 rc = apr_file_info_get(&finfo, APR_FINFO_SIZE, thefile);
-                if (rc == APR_SUCCESS && finfo.size - *offset < 0)
-                    thefile->filePtr = finfo.size - *offset;
+                if (rc == APR_SUCCESS && finfo.size + *offset >= 0)
+                    thefile->filePtr = finfo.size + *offset;
                 break;
 
             default:

Modified: apr/apr/branches/0.9.x/test/testfile.c
URL: http://svn.apache.org/viewcvs/apr/apr/branches/0.9.x/test/testfile.c?rev=373455&r1=373454&r2=373455&view=diff
==============================================================================
--- apr/apr/branches/0.9.x/test/testfile.c (original)
+++ apr/apr/branches/0.9.x/test/testfile.c Sun Jan 29 23:04:30 2006
@@ -596,6 +596,55 @@
     apr_file_remove(fname, p);
 }
 
+static void test_xthread(CuTest *tc)
+{
+    apr_file_t *f;
+    const char *fname = "data/testxthread.dat";
+    apr_status_t rv;
+    apr_int32_t flags = APR_CREATE|APR_READ|APR_WRITE|APR_APPEND|APR_XTHREAD;
+    char buf[128] = { 0 };
+
+    /* Test for bug 38438, opening file with append + xthread and seeking to 
+       the end of the file resulted in writes going to the beginning not the
+       end. */
+
+    apr_file_remove(fname, p);
+
+    rv = apr_file_open(&f, fname, flags, APR_UREAD|APR_UWRITE, p);
+    CuAssert(tc, "open test file", rv == APR_SUCCESS);
+
+    rv = apr_file_puts("hello", f);
+    CuAssert(tc, "write should succeed", rv == APR_SUCCESS);
+
+    apr_file_close(f);
+    
+    rv = apr_file_open(&f, fname, flags, APR_UREAD|APR_UWRITE, p);
+    CuAssert(tc, "open test file", rv == APR_SUCCESS);
+
+    /* Seek to the end. */
+    {
+        apr_off_t offset = 0;
+
+        rv = apr_file_seek(f, APR_END, &offset);
+    }
+
+    rv = apr_file_puts("world", f);
+    CuAssert(tc, "more writes should succeed", rv == APR_SUCCESS);
+
+    /* Back to the beginning. */
+    {
+        apr_off_t offset = 0;
+        
+        rv = apr_file_seek(f, APR_SET, &offset);
+    }
+    
+    apr_file_read_full(f, buf, sizeof(buf), NULL);
+
+    CuAssertStrEquals(tc, "helloworld", buf);
+
+    apr_file_close(f);
+}
+
 CuSuite *testfile(void)
 {
     CuSuite *suite = CuSuiteNew("File I/O");
@@ -623,6 +672,7 @@
     SUITE_ADD_TEST(suite, test_truncate);
     SUITE_ADD_TEST(suite, test_fail_write_flush);
     SUITE_ADD_TEST(suite, test_fail_read_flush);
+    SUITE_ADD_TEST(suite, test_xthread);
 
     return suite;
 }



Mime
View raw message