The copy() function will report failure when copying a 0 byte file, even 
though a duplicate file has successfully been created.
The problem occurs because _php_stream_copy_to_stream function inside stream.c 
does not check if the source file is 0 bytes and returns haveread bytes, 
which in case of blank file is 0. This later on get interpreted as a failure 
to copy file.

Below is a patch against the latest CVS, which fixes this problem.

--- streams.c     Thu Aug  8 19:57:50 2002
+++ streams.c   Thu Aug  8 19:51:36 2002
@@ -473,6 +473,12 @@

                if (fstat(srcfd, &sbuf) == 0) {
                        void *srcfile;
+
+                       /* in the event the source file's size is 0 bytes, 
return 1 to
+                        * indicate success, because opening the file for 
write had already
+                        * created a copy
+                        * */
+                       if (sbuf.st_size == 0) return 1;

                        if (maxlen > sbuf.st_size || maxlen == 0)
                                maxlen = sbuf.st_size;

The bug can be replicated with a php script listed below.

<?php
        touch("mini");
        var_dump(copy("mini", "mini2"));
?>

Ilia Alshanetsky

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to