private static void PurgeDownloads(IHttpService http, NetFileCache cache) { if (http != null && cache != null) { foreach (Uri url in http.RequestedURLs) { cache.Remove(url); } } }
private static void PurgeDownloads(IHttpService http, NetFileCache cache) { log.Debug("Deleting downloads for failed inflation"); if (http != null && cache != null) { foreach (Uri url in http.RequestedURLs) { cache.Remove(url); } } }
public void StoreRemove() { Uri url = new Uri("http://example.com/"); string file = TestData.DogeCoinFlagZip(); Assert.IsFalse(cache.IsCached(url)); cache.Store(url, file); Assert.IsTrue(cache.IsCached(url)); cache.Remove(url); Assert.IsFalse(cache.IsCached(url)); }
private string DownloadPackage(Uri url, string identifier, DateTime?updated, Uri primaryUrl = null) { if (primaryUrl == null) { primaryUrl = url; } if (_overwriteCache && !_requestedURLs.Contains(url)) { // Discard cached file if command line says so, // but only the first time in each run _cache.Remove(url); } _requestedURLs.Add(url); var cachedFile = _cache.GetCachedFilename(primaryUrl, updated); if (!string.IsNullOrWhiteSpace(cachedFile)) { return(cachedFile); } else { var downloadedFile = Net.Download(url); string extension; switch (FileIdentifier.IdentifyFile(downloadedFile)) { case FileType.ASCII: extension = "txt"; break; case FileType.GZip: extension = "gz"; break; case FileType.Tar: extension = "tar"; break; case FileType.TarGz: extension = "tar.gz"; break; case FileType.Zip: extension = "zip"; string invalidReason; if (!NetFileCache.ZipValid(downloadedFile, out invalidReason)) { log.Debug($"{downloadedFile} is not a valid ZIP file: {invalidReason}"); throw new Kraken($"{url} is not a valid ZIP file: {invalidReason}"); } break; default: extension = "ckan-package"; break; } return(_cache.Store( primaryUrl, downloadedFile, string.Format("netkan-{0}.{1}", identifier, extension), move: true )); } }