apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Corey Olsen" <co...@bungeelabs.com>
Subject apr_file_copy change
Date Wed, 20 Feb 2008 18:30:46 GMT
I ran into a problem earlier today calling apr_file_copy where the
from_path and the to_path parameters are the same.  The issue is that in
apr_file_transfer_contents the from file is opened with the APR_READ
flag and then the to file (being the same) opens the file with APR_WRITE
| APR_CREATE | APR_TRUNCATE flags set.  This causes the file to be
truncated to 0 bytes and the transfer ends pretty quickly.

Is this a bug or is this expected behavior with the file_io subsystem?
I'm new to the apr source code so I'm attaching a diff of a change that
fixes the issue for me.  Please let me know if it is good or bad or

Corey Olsen

Index: file_io/unix/copy.c
--- file_io/unix/copy.c (revision 629544)
+++ file_io/unix/copy.c (working copy)
@@ -28,6 +28,11 @@
     apr_finfo_t finfo;
     apr_fileperms_t perms;

+    if (apr_strnatcmp(from_path, to_path) == 0) {
+      status = APR_SUCCESS;
+      return status;
+    }
     /* Open source file. */
     status = apr_file_open(&s, from_path, APR_READ, APR_OS_DEFAULT,
     if (status)

View raw message