owncloud/core — pull request #2491 by riso (2013-03-20 22:02:35+00:00)
Title: improved handling of xsendfile zip generation race condition

With the current X-Sendfile implementation the following behavior might happen:
1. Download of zip file **A** from web interface is started
2. Before that zip generation is completed cron is run

This causes the deletion of **A** and therefore an error to the client (notice that this cannot happen during file download because the webserver keeps the file open and denies the removal).

This PR helps avoiding this behavior by moving the file to the *oc-noclean* directory only when generation is completed.

Note that this is not a final fix for the issue (the race condition is mitigated but not removed) since it might happen that cron is run right after zip creation but before that the response is actually sent by PHP.

As of writing though I don't have a final fix since that would require some sort of callback on a completed download in order to perform the deletion of the temporary file only at that time (and avoid using cron altogether), but I don't think that this is possible due to the fact that the download is entirely managed by the webserver.