Example #1
0
 private static void PurgeDownloads(IHttpService http, NetFileCache cache)
 {
     if (http != null && cache != null)
     {
         foreach (Uri url in http.RequestedURLs)
         {
             cache.Remove(url);
         }
     }
 }
Example #2
0
 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);
         }
     }
 }
Example #3
0
        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));
        }
Example #4
0
        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
                           ));
            }
        }