Refactor collectstatic by extracting parts of copy_file into other methods.