ZF-6258: File upload with rename filter pseudo random failing

Description

Using trunk (via svn:externals).

I noticed a while ago in the svn log that there has been an optimization added to Zend_File_Transfer to avoid moving a file twice when there is a rename filter in place.

But in the rename filter there is a check:


if (!file_exists($file['source'])) {
    return $value;
}

What this basically does it that it bails out silently (?) if the file is not there, returning the original given filename. But the problem is that the file is actually NOT there since it hasn't been moved yet (the rename optimization I guess) - so the rename filter returns the original name, instead of the new name, and the file is not renamed. The second time I try to upload the same file it magically works since there is a stale copy of the previous attempt.

Not sure I explained it the best way but I'm quite confused :) Ask, and I will try to provide more feedback, if necessary.

Comments

When "the file is not there", then is has not been transferred from the client to PHP. Because the file check is done on the file within the temporary directory.

No temporary file, means no upload, which means, no new name...

I knew that explanation would blew up. ;)

The file got to the server - it's in the /tmp dir under the name PHP gave it (something like /tmp/adyU639A) As far as I understand the Zend_File_Transfer component will then move it to the destination (set via setDestination()). Then the rename filter would be applied, moving it yet again to it's last location.

You've introduced a check for the rename filter in the adapter to skip one moving (which is a very good idea).

Let's write the locations where the file ends up in the non-optimized case:


PHP               Zend_File_Transfer               Rename filter
 /tmp/adyU639A -> /home/me/myapp/upload/car.jpg -> /home/me/myapp/cars/as5d675123

What the rename filter check (based on debuging I did) is for the existence of the second path (.../car.jpg) - which apparently does not exist since the file hasn't beed moved yet by the Zend_FIle_Transfer component.

Here are the places I think the bug can be found:


if ($rename !== null) {
    $filename = $rename->getNewName($directory . $content['name']);
    $key = array_search('Rename', $this->_files[$file]['filters']);
    unset($this->_files[$file]['filters'][$key]);
}

The path passes to getNewName() is the path in the middle (the example above).

Fixed with r14818 Problem occured when not giving source

Awesome! Thank you very much. :)