]> hydra-www.ietfng.org Git - acmetensortoys-ctfws-android/commitdiff
CheckedAsyncDownloader: add last-modified-time parameter
authorNathaniel Wesley Filardo <nwfilardo@gmail.com>
Tue, 2 Jun 2020 19:20:34 +0000 (20:20 +0100)
committerNathaniel Wesley Filardo <nwfilardo@gmail.com>
Tue, 1 Mar 2022 18:50:25 +0000 (18:50 +0000)
mobile/src/main/java/com/acmetensortoys/ctfwstimer/utils/CheckedAsyncDownloader.java

index cf87a77255ff87a0680150fdd5a57aee4a263b5e..742a3baf1368019e8116abc6b082cafb895fc74b 100644 (file)
@@ -33,14 +33,16 @@ public class CheckedAsyncDownloader extends AsyncTask<CheckedAsyncDownloader.DL,
         public final byte[] sha256;
         public final File dest;
         public final long lengthLimit; /* In bytes, or 0 for no limit */
+        private final long dltime; /* seconds since unix epoch */
         private Result result;
-        private long dlsize;
+        private long dlsize; /* valid only if result OK or ALREADY */
 
-        public DL(URL url, byte[] sha256, long lim, File dest) {
+        public DL(URL url, byte[] sha256, long lim, long ts, File dest) {
             this.url = url;
             this.sha256 = sha256;
             this.dest = dest;
             this.lengthLimit = lim;
+            this.dltime = ts;
             this.result = Result.RES_UNTRIED;
             this.dlsize = 0;
         }
@@ -50,12 +52,17 @@ public class CheckedAsyncDownloader extends AsyncTask<CheckedAsyncDownloader.DL,
             this.sha256 = dl.sha256;
             this.dest = dl.dest;
             this.lengthLimit = dl.lengthLimit;
+            this.dltime = dl.dltime;
             this.result = dl.result;
             this.dlsize = dl.dlsize;
         }
 
         public Result getResult() { return result; }
-        public long getDlsize() { return dlsize ; }
+
+        /** Valid only if result OK or ALREADY */
+        public long getDlsize() { return dlsize; }
+        /** TAI seconds since UNIX epoch; valid only if result OK or ALREADY */
+        public long getDLtime() { return dltime; }
     }
 
     @Override
@@ -165,6 +172,9 @@ public class CheckedAsyncDownloader extends AsyncTask<CheckedAsyncDownloader.DL,
                 continue;
             }
 
+            //noinspection ResultOfMethodCallIgnored
+            oft.setLastModified(dl.dltime*1000); // value in milliseconds, sigh
+
             if (!oft.renameTo(dl.dest)) {
                 dl.result = Result.ERR_WRITE;
                 //noinspection ResultOfMethodCallIgnored