Skip to content

Commit

Permalink
Merge #2947 Only stage auto-epoch when creating new file
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Jan 7, 2020
2 parents 058ba5f + 667e169 commit ab383aa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ All notable changes to this project will be documented in this file.
- [Netkan] Request fewer GitHub releases and cache string URLs in Netkan (#2950 by: HebaruSan)
- [GUI] Create ~/.local/share/applications/ if it doesn't exist on Linux (#1848 by: DinCahill; reviewed: ayan4ml, politas, dannydi12)
- [Netkan] Catch nested GameData folders in Netkan (#2948 by: HebaruSan; reviewed: techman83)
- [Netkan] Only stage auto-epoch when creating new file (#2947 by: HebaruSan; reviewed: DasSkelett)

## v1.26.6 (Leonov)

Expand Down
3 changes: 3 additions & 0 deletions Netkan/CmdLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ internal class CmdLineOptions
[Option("queues", HelpText = "Input,Output queue names for Queue Inflator mode")]
public string Queues { get; set; }

[Option("highest-version", HelpText = "Highest known version for auto-epoching")]
public string HighestVersion { get; set; }

[Option("validate-ckan", HelpText = "Name of .ckan file to check for errors")]
public string ValidateCkan { get; set; }

Expand Down
15 changes: 14 additions & 1 deletion Netkan/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using log4net.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using CKAN.Versioning;
using CKAN.NetKAN.Model;
using CKAN.NetKAN.Processors;
using CKAN.NetKAN.Transformers;
Expand Down Expand Up @@ -87,7 +88,14 @@ public static int Main(string[] args)
Options.GitHubToken,
Options.PreRelease
);
var ckans = inf.Inflate(Options.File, netkan, new TransformOptions(ParseReleases(Options.Releases), null));
var ckans = inf.Inflate(
Options.File,
netkan,
new TransformOptions(
ParseReleases(Options.Releases),
ParseHighestVersion(Options.HighestVersion)
)
);
foreach (Metadata ckan in ckans)
{
WriteCkan(ckan);
Expand Down Expand Up @@ -123,6 +131,11 @@ public static int Main(string[] args)
return val == "all" ? (int?)null : int.Parse(val);
}

private static ModuleVersion ParseHighestVersion(string val)
{
return val == null ? null : new ModuleVersion(val);
}

private static void ProcessArgs(string[] args)
{
if (args.Any(i => i == "--debugger"))
Expand Down
12 changes: 8 additions & 4 deletions Netkan/Transformers/EpochTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,21 @@ public IEnumerable<Metadata> Transform(Metadata metadata, TransformOptions opts)
else if (opts.HighestVersion != null)
{
// Ensure we are greater or equal to the previous max
ModuleVersion currentV = new ModuleVersion((string)json["version"]);
ModuleVersion startV = new ModuleVersion((string)json["version"]);
ModuleVersion currentV = startV;
while (currentV < opts.HighestVersion)
{
Log.DebugFormat("Auto-epoching out of order version: {0} < {1}",
currentV, opts.HighestVersion);
// Tell the Indexer to be careful
opts.Staged = true;
opts.StagingReason = $"Auto-epoching out of order version: {currentV} < {opts.HighestVersion}";
// Increment epoch if too small
currentV = currentV.IncrementEpoch();
}
if (startV < opts.HighestVersion && opts.HighestVersion < currentV)
{
// New file, tell the Indexer to be careful
opts.Staged = true;
opts.StagingReason = $"Auto-epoching out of order version: {startV} < {opts.HighestVersion} < {currentV}";
}
json["version"] = currentV.ToString();
}

Expand Down

0 comments on commit ab383aa

Please sign in to comment.