From 087af652d5e38a5a9e6df47194896e9b06b34920 Mon Sep 17 00:00:00 2001 From: Louis Gesbert Date: Mon, 11 Aug 2014 18:46:46 +0200 Subject: [PATCH] Make sure to clean stale files on http download Should fix #1585 --- src/repositories/opamHTTP.ml | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/repositories/opamHTTP.ml b/src/repositories/opamHTTP.ml index aa72ee3a594..69e4e70e967 100644 --- a/src/repositories/opamHTTP.ml +++ b/src/repositories/opamHTTP.ml @@ -201,15 +201,34 @@ module B = struct ) let pull_url package dirname checksum remote_url = - log "pull-file"; let remote_url = OpamTypesBase.string_of_address remote_url in + log "pull-file into %a: %s" + (slog OpamFilename.Dir.to_string) dirname + remote_url; let filename = OpamFilename.of_string remote_url in let base = OpamFilename.basename filename in let local_file = OpamFilename.create dirname base in - if OpamFilename.exists local_file && - match checksum with - | None -> false - | Some c -> OpamFilename.digest local_file = c then ( + let check_sum f = match checksum with + | None -> false + | Some c -> OpamFilename.digest f = c + in + let files = OpamFilename.files dirname in + let uptodate = + let found, extra = + List.partition (fun f -> f = local_file && check_sum f) files + in + if extra <> [] && + OpamMisc.starts_with (* Just a safeguard *) + ~prefix:(OpamFilename.Dir.to_string (OpamPath.root ())) + (OpamFilename.Dir.to_string dirname) + then + (log "Removing stale files in download dir: %a" + (slog @@ List.map OpamFilename.to_string @> OpamMisc.pretty_list) + extra; + List.iter OpamFilename.remove extra); + found <> [] + in + if uptodate then ( OpamGlobals.msg "[%s] %s is in the local cache, using it.\n" (OpamGlobals.colorise `green (OpamPackage.to_string package)) (OpamFilename.Base.to_string base);