switched to use the shutdown hook to delete residue files after transmitting a zipped file

This commit is contained in:
hyung-hwan 2015-04-14 07:09:59 +00:00
parent b3040e5c47
commit e1a3fe625b

View File

@ -626,6 +626,16 @@ class Code extends Controller
return $this->_do_diff ($projectid, $path, $rev1, $rev2, TRUE); return $this->_do_diff ($projectid, $path, $rev1, $rev2, TRUE);
} }
protected function _clear_zip_residue ($filename)
{
$dir_name = $filename . '.d';
$zip_name = $filename . '.zip';
codepot_delete_files ($dir_name, TRUE);
@unlink ($zip_name);
@unlink ($filename);
}
function fetch ($projectid = '', $path = '', $rev = SVN_REVISION_HEAD) function fetch ($projectid = '', $path = '', $rev = SVN_REVISION_HEAD)
{ {
$this->load->model ('ProjectModel', 'projects'); $this->load->model ('ProjectModel', 'projects');
@ -710,6 +720,12 @@ class Code extends Controller
$forced_zip_name = $forced_name . '.zip'; $forced_zip_name = $forced_name . '.zip';
// deleting residue files after @readfile() didn't
// work reliably when file download has been
// interrupted or cancelled. using the shutdown
// hook seemed more reliable.
@register_shutdown_function (array($this, '_clear_zip_residue'), $filename);
header ('Content-Description: File Transfer'); header ('Content-Description: File Transfer');
header ('Content-Type: application/zip'); header ('Content-Type: application/zip');
header ('Content-Disposition: attachment; filename='. $forced_zip_name); header ('Content-Disposition: attachment; filename='. $forced_zip_name);
@ -721,9 +737,7 @@ class Code extends Controller
// meaningless to show the error page after headers // meaningless to show the error page after headers
// have been sent event if readfile fails. // have been sent event if readfile fails.
codepot_delete_files ($dir_name, TRUE); exit (0); // it looks like the shutdown callback is not called without exit().
@unlink ($zip_name);
@unlink ($filename);
} }
} }
} }