Deleting after send_file

I’m writing an application that will allow users to select several files
from a list, and will then return a tar.gz archive to them. The relevant
part of the code looks something like this:


if system(“cd #{@dir}; tar czf tmp/#{@newfile} #{@add}”)
send_file("#{@dir}/tmp/#{@newfile}",:disposition => ‘attachment’)
flash[:notice] = “Download complete.”
#File.unlink("#{@newfile}")
else
flash[:notice] = “Download failed.”
redirect_to(:action => ‘view_selection’)
end

This is fine as written, but if I uncomment the File.unlink then the
file is apparently deleted before the download completes, and what I get
is an html error message with @newfile’s name.
Would anyone mind point out my mistake?