[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [metrics-lib/release] Resume previously aborted downloads.



commit a67a4713f64dca654928d10d6f5ff469540a47cf
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Wed Jul 4 20:54:14 2018 +0200

    Resume previously aborted downloads.
    
    So far, whenever DescriptorCollector fetches a remote file, it writes
    its contents to a local temporary file and later renames that file.
    The idea is to avoid incomplete downloads. However, if a local
    temporary file already exists from an earlier run, DescriptorCollector
    fails and skips the remote file. This is not intended.
    
    With this change, DescriptorCollector always overwrites a local
    temporary file when it finds one. It still doesn't delete incomplete
    temporary files that are not re-attempted later. But not skipping them
    is already a good start.
    
    Fixes #24153.
---
 CHANGELOG.md                                                          | 3 +++
 .../org/torproject/descriptor/index/DescriptorIndexCollector.java     | 4 +++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0e9ad5f..d6f79ae 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,9 @@
      after upgrading from Java 8 to 9. Applications must provide
      Apache Commons Codec 1.10 as dependency.
 
+ * Minor changes
+   - Make DescriptorCollector resume previously aborted downloads.
+
 
 # Changes in version 2.4.0 - 2018-05-23
 
diff --git a/src/main/java/org/torproject/descriptor/index/DescriptorIndexCollector.java b/src/main/java/org/torproject/descriptor/index/DescriptorIndexCollector.java
index be79386..873eb81 100644
--- a/src/main/java/org/torproject/descriptor/index/DescriptorIndexCollector.java
+++ b/src/main/java/org/torproject/descriptor/index/DescriptorIndexCollector.java
@@ -16,6 +16,7 @@ import java.nio.file.FileVisitResult;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.SimpleFileVisitor;
+import java.nio.file.StandardCopyOption;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.Map;
 import java.util.SortedMap;
@@ -120,7 +121,8 @@ public class DescriptorIndexCollector implements DescriptorCollector {
           destinationFile.getAbsolutePath());
       try (InputStream is = new URL(baseUrl + "/" + filepathname)
           .openStream()) {
-        Files.copy(is, tempDestinationFile.toPath());
+        Files.copy(is, tempDestinationFile.toPath(),
+            StandardCopyOption.REPLACE_EXISTING);
         if (tempDestinationFile.length() == entry.getValue().size) {
           tempDestinationFile.renameTo(destinationFile);
           destinationFile.setLastModified(lastModifiedMillis);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits