Fixing DistCopy - flush stream before moving tmp file

@raronson @charleso