Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: KSP-CKAN/CKAN
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e825bdef9d52
Choose a base ref
...
head repository: KSP-CKAN/CKAN
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 114a227ea79b
Choose a head ref
  • 2 commits
  • 4 files changed
  • 2 contributors

Commits on Sep 27, 2018

  1. Copy the full SHA
    254cf8b View commit details

Commits on Oct 7, 2018

  1. Copy the full SHA
    114a227 View commit details
Showing with 34 additions and 1 deletion.
  1. +3 −0 CHANGELOG.md
  2. +21 −1 Netkan/Program.cs
  3. +7 −0 Netkan/Services/CachingHttpService.cs
  4. +3 −0 Netkan/Services/IHttpService.cs
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.

## v1.25.4

### Features
- [Netkan] Purge downloads that failed to index from Netkan cache (#2526 by: HebaruSan; reviewed: politas)

## v1.25.3 (Woomera)

### Features
22 changes: 21 additions & 1 deletion Netkan/Program.cs
Original file line number Diff line number Diff line change
@@ -28,6 +28,10 @@ public static class Program

public static int Main(string[] args)
{
// Keep these for purging downloads in the exception handler
NetFileCache cache = null;
IHttpService http = null;

try
{
ProcessArgs(args);
@@ -50,7 +54,8 @@ public static int Main(string[] args)

var moduleService = new ModuleService();
var fileService = new FileService();
var http = new CachingHttpService(FindCache(new KSPManager(new ConsoleUser(false))));
cache = FindCache(new KSPManager(new ConsoleUser(false)));
http = new CachingHttpService(cache);

var netkan = ReadNetkan();
Log.Info("Finished reading input");
@@ -87,6 +92,9 @@ public static int Main(string[] args)
{
e = e.GetBaseException() ?? e;

// Purge anything we download for a failed indexing attempt from the cache to allow re-downloads
PurgeDownloads(http, cache);

Log.Fatal(e.Message);

if (Options == null || Options.Debug)
@@ -189,5 +197,17 @@ private static void WriteCkan(Metadata metadata)

Log.InfoFormat("Transformation written to {0}", finalPath);
}

private static void PurgeDownloads(IHttpService http, NetFileCache cache)
{
if (http != null && cache != null)
{
foreach (Uri url in http.RequestedURLs)
{
cache.Remove(url);
}
}
}

}
}
7 changes: 7 additions & 0 deletions Netkan/Services/CachingHttpService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;

namespace CKAN.NetKAN.Services
{
internal sealed class CachingHttpService : IHttpService
{
private readonly NetFileCache _cache;
private HashSet<Uri> _requestedURLs = new HashSet<Uri>();

public CachingHttpService(NetFileCache cache)
{
@@ -13,6 +15,8 @@ public CachingHttpService(NetFileCache cache)

public string DownloadPackage(Uri url, string identifier, DateTime? updated)
{
_requestedURLs.Add(url);

var cachedFile = _cache.GetCachedFilename(url, updated);

if (!string.IsNullOrWhiteSpace(cachedFile))
@@ -65,5 +69,8 @@ public string DownloadText(Uri url)
{
return Net.DownloadText(url);
}

public IEnumerable<Uri> RequestedURLs { get { return _requestedURLs; } }

}
}
3 changes: 3 additions & 0 deletions Netkan/Services/IHttpService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
using System.Collections.Generic;

namespace CKAN.NetKAN.Services
{
internal interface IHttpService
{
string DownloadPackage(Uri url, string identifier, DateTime? updated);
string DownloadText(Uri url);

IEnumerable<Uri> RequestedURLs { get; }
}
}