Make DescriptorCollector resume previously aborted downloads
Today I noticed that DescriptorCollector
skips files when it runs into a temporary file from a previously aborted download. Example:
[WARN] Cannot fetch remote file server-descriptors-2017-10.tar.xz from https://collector.torproject.org. Skipping that file.
java.nio.file.FileAlreadyExistsException: backup/archive/relay-descriptors/server-descriptors/.server-descriptors-2017-10.tar.xz
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:88)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:434)
at java.nio.file.Files.newOutputStream(Files.java:216)
at java.nio.file.Files.copy(Files.java:3016)
at org.torproject.descriptor.index.DescriptorIndexCollector.fetchRemoteFiles(DescriptorIndexCollector.java:123)
at org.torproject.descriptor.index.DescriptorIndexCollector.collectDescriptors(DescriptorIndexCollector.java:83)
at Archive.main(Archive.java:12)
This is rather unexpected. The main reason for using a temporary file is to avoid overwriting an existing file and risking to leave the user with only a broken file if the download gets interrupted. But the temporary file should not prevent us from making a download that may succeed.
Let's change the behavior here to delete any temporary files we run into or simply overwriting them.