apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Branko ─îibej <br...@xbc.nu>
Subject Re: apr_file_copy change
Date Wed, 20 Feb 2008 20:57:10 GMT
Corey Olsen wrote:
> 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
> otherwise.
>   

Whether it's a bug is a matter of opinion. Unix shell "cp" checks for 
file identity, but one could argue that this is an application-level 
feature.

But your patch certainly isn't a solution. You can't disprove file 
identity by comparing file paths, that doesn't take links and loopback 
mountpoints and case-insensitive filesystems and such into account.

> Thanks,
> 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,
> pool);
>      if (status)
>   


Mime
View raw message