From 60389d7306fa308def01655a754cf9ec13b88ed5 Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Thu, 17 Nov 2016 13:23:25 +0000 Subject: [PATCH] download: If we have a last-modified date, set the mtime of the target file This only works for HTTP, not FTP. Should hopefully fix asgen considering suites as changed each time, which I think happened because the Packages file got the current mtime, so it was always considered to be newer. Fixes #35 --- src/asgen/utils.d | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/asgen/utils.d b/src/asgen/utils.d index eeab4791..88b0bac7 100644 --- a/src/asgen/utils.d +++ b/src/asgen/utils.d @@ -29,6 +29,8 @@ import std.range : chain; import std.algorithm : startsWith; import std.array : appender; import std.path : buildPath, dirName, buildNormalizedPath; +import std.typecons : Nullable; +import std.datetime : Clock, parseRFC822DateTime, SysTime; static import std.file; import asgen.logging; @@ -348,13 +350,15 @@ bool isRemote (const string uri) return (!match.empty); } -private void download (const string url, ref File dest, const uint retryCount = 5) @trusted +private immutable(Nullable!SysTime) download (const string url, ref File dest, const uint retryCount = 5) @trusted in { assert (url.isRemote); } body { import core.time; import std.net.curl : CurlException, HTTP, FTP; + Nullable!SysTime ret; + size_t onReceiveCb (File f, ubyte[] data) { f.rawWrite (data); @@ -370,6 +374,10 @@ body downloader.dataTimeout = dur!"seconds" (30); downloader.onReceive = (data) => onReceiveCb (dest, data); downloader.perform(); + if ("last-modified" in downloader.responseHeaders) { + auto lastmodified = downloader.responseHeaders["last-modified"]; + ret = parseRFC822DateTime(lastmodified); + } } else { auto downloader = FTP (url); downloader.connectTimeout = dur!"seconds" (30); @@ -389,6 +397,8 @@ body throw e; } } + + return ret; } /** @@ -449,10 +459,13 @@ body mkdirRecurse (dest.dirName); auto f = File (dest, "wb"); - scope (exit) f.close (); scope (failure) remove (dest); - download (url, f, retryCount); + auto time = download (url, f, retryCount); + + f.close (); + if (!time.isNull) + setTimes (dest, Clock.currTime, time); } /**