Skip to content

Commit ce4f25c

Browse files
authored
Add configurable skip level for minor updates (#5113)
1 parent aeeca6d commit ce4f25c

9 files changed

Lines changed: 105 additions & 23 deletions

File tree

‎src/Languages/lang_en.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@
142142
"Skip hash check": "Skip hash check",
143143
"Uninstall previous versions when updated": "Uninstall previous versions when updated",
144144
"Skip minor updates for this package": "Skip minor updates for this package",
145+
"Ignore changes after the first": "Ignore changes after the first",
146+
"version numbers": "version numbers",
145147
"Automatically update this package": "Automatically update this package",
146148
"{0} installation options": "{0} installation options",
147149
"Latest": "Latest",

‎src/UniGetUI.Avalonia/ViewModels/DialogPages/InstallOptionsViewModel.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ public partial class InstallOptionsViewModel : ObservableObject
8484
public string SkipHashCheckBox_Content { get; } = CoreTools.Translate("Skip hash check");
8585
public string UninstallPrevCheckBox_Content { get; } = CoreTools.Translate("Uninstall previous versions when updated");
8686
public string SkipMinorCheckBox_Content { get; } = CoreTools.Translate("Skip minor updates for this package");
87+
public string SkipMinorLevelPrefix_Content { get; } = CoreTools.Translate("Ignore changes after the first");
88+
public string SkipMinorLevelSuffix_Content { get; } = CoreTools.Translate("version numbers");
8789
public string AutoUpdateCheckBox_Content { get; } = CoreTools.Translate("Automatically update this package");
8890
public string IgnoreUpdatesCheckBox_Content { get; } = CoreTools.Translate("Ignore future updates for this package");
8991

@@ -152,6 +154,9 @@ partial void OnSelectedProfileChanged(string? value)
152154
[ObservableProperty] private string? _selectedVersion;
153155

154156
[ObservableProperty] private bool _skipMinorChecked;
157+
// Index 0 => keep first 1 number significant (level 2), 1 => first 2 (level 3), 2 => first 3 (level 4).
158+
public ObservableCollection<string> SkipMinorLevelOptions { get; } = ["1", "2", "3"];
159+
[ObservableProperty] private int _skipMinorLevelIndex;
155160
[ObservableProperty] private bool _autoUpdateChecked;
156161
[ObservableProperty] private bool _ignoreUpdatesChecked;
157162

@@ -267,6 +272,7 @@ public InstallOptionsViewModel(IPackage package, OperationType operation, Instal
267272
SkipHashEnabled = caps.CanSkipIntegrityChecks;
268273
UninstallPrevChecked = options.UninstallPreviousVersionsOnUpdate;
269274
SkipMinorChecked = options.SkipMinorUpdates;
275+
SkipMinorLevelIndex = options.SkipMinorUpdatesLevel - 2; // level is validated to 2..4 by the getter
270276
AutoUpdateChecked = options.AutoUpdatePackage;
271277

272278
// Version
@@ -515,6 +521,7 @@ private InstallOptions SnapshotOptions()
515521
o.UninstallPreviousVersionsOnUpdate = UninstallPrevChecked;
516522
o.AutoUpdatePackage = AutoUpdateChecked;
517523
o.SkipMinorUpdates = SkipMinorChecked;
524+
o.SkipMinorUpdatesLevel = SkipMinorLevelIndex + 2;
518525
o.OverridesNextLevelOpts = !FollowGlobal;
519526

520527
var ver = SelectedVersion ?? "";
@@ -550,6 +557,7 @@ private void ApplyToOptions()
550557
_options.UninstallPreviousVersionsOnUpdate = s.UninstallPreviousVersionsOnUpdate;
551558
_options.AutoUpdatePackage = s.AutoUpdatePackage;
552559
_options.SkipMinorUpdates = s.SkipMinorUpdates;
560+
_options.SkipMinorUpdatesLevel = s.SkipMinorUpdatesLevel;
553561
_options.OverridesNextLevelOpts = s.OverridesNextLevelOpts;
554562
_options.PreRelease = s.PreRelease;
555563
_options.Version = s.Version;

‎src/UniGetUI.Avalonia/Views/DialogPages/InstallOptionsControl.axaml‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,28 @@
145145
<Border Height="1" Background="{DynamicResource AppBorderBrush}"
146146
automation:AutomationProperties.AccessibilityView="Raw"/>
147147

148-
<WrapPanel Orientation="Horizontal">
148+
<StackPanel Orientation="Vertical" Spacing="4">
149149
<CheckBox Content="{Binding IgnoreUpdatesCheckBox_Content, FallbackValue='Ignore future updates for this package'}"
150150
IsChecked="{Binding IgnoreUpdatesChecked}"
151-
automation:AutomationProperties.Name="{Binding IgnoreUpdatesCheckBox_Content}"
152-
Margin="0,0,16,4"/>
153-
<CheckBox Content="{Binding SkipMinorCheckBox_Content, FallbackValue='Skip minor updates'}"
154-
IsChecked="{Binding SkipMinorChecked}"
155-
automation:AutomationProperties.Name="{Binding SkipMinorCheckBox_Content}"
156-
Margin="0,0,16,4"/>
151+
automation:AutomationProperties.Name="{Binding IgnoreUpdatesCheckBox_Content}"/>
157152
<CheckBox Content="{Binding AutoUpdateCheckBox_Content, FallbackValue='Auto-update this package'}"
158153
IsChecked="{Binding AutoUpdateChecked}"
159-
automation:AutomationProperties.Name="{Binding AutoUpdateCheckBox_Content}"
160-
Margin="0,0,16,4"/>
161-
</WrapPanel>
154+
automation:AutomationProperties.Name="{Binding AutoUpdateCheckBox_Content}"/>
155+
<CheckBox Content="{Binding SkipMinorCheckBox_Content, FallbackValue='Skip minor updates'}"
156+
IsChecked="{Binding SkipMinorChecked}"
157+
automation:AutomationProperties.Name="{Binding SkipMinorCheckBox_Content}"/>
158+
<WrapPanel Orientation="Horizontal" Margin="28,0,0,0"
159+
IsEnabled="{Binding SkipMinorChecked}">
160+
<TextBlock Text="{Binding SkipMinorLevelPrefix_Content, FallbackValue='Ignore changes after the first'}"
161+
VerticalAlignment="Center" Margin="0,0,8,0" TextWrapping="Wrap"/>
162+
<ComboBox ItemsSource="{Binding SkipMinorLevelOptions}"
163+
SelectedIndex="{Binding SkipMinorLevelIndex}"
164+
automation:AutomationProperties.Name="{Binding SkipMinorLevelPrefix_Content}"
165+
VerticalAlignment="Center" MinWidth="64"/>
166+
<TextBlock Text="{Binding SkipMinorLevelSuffix_Content, FallbackValue='version numbers'}"
167+
VerticalAlignment="Center" Margin="8,0,0,0" TextWrapping="Wrap"/>
168+
</WrapPanel>
169+
</StackPanel>
162170

163171
</StackPanel>
164172
</Border>

‎src/UniGetUI.PackageEngine.Interfaces/IPackage.cs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,12 @@ public interface IPackage : INotifyPropertyChanged, IEquatable<IPackage>
151151
public Task<string?> GetInstallerFileName();
152152

153153
/// <summary>
154-
/// Checks whether a new update of this package is a minor update or not (0.0.x)
154+
/// Checks whether a new update of this package is a minor update or not, according to
155+
/// <paramref name="level"/> — the 1-based version-number position (2=Minor, 3=Patch, 4=Remainder)
156+
/// from which a change is still considered minor.
155157
/// </summary>
156-
/// <returns>False if the update is a major update or the update doesn't exist, true if it's a minor update</returns>
157-
public bool IsUpdateMinor();
158+
/// <returns>False if the most significant changed component is more significant than <paramref name="level"/> or the update doesn't exist, true otherwise</returns>
159+
public bool IsUpdateMinor(int level = InstallOptions.DefaultSkipMinorLevel);
158160

159161
/// <summary>
160162
/// Gets the applicable install options for this package

‎src/UniGetUI.PackageEngine.PackageLoader/UpgradablePackagesLoader.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ protected override async Task<bool> IsPackageValid(IPackage package)
3939
if (package.NewerVersionIsInstalled())
4040
return false;
4141

42-
if (package.IsUpdateMinor() && (await package.GetInstallOptions()).SkipMinorUpdates)
42+
var installOptions = await package.GetInstallOptions();
43+
if (installOptions.SkipMinorUpdates && package.IsUpdateMinor(installOptions.SkipMinorUpdatesLevel))
4344
{
4445
Logger.Info(
45-
$"Ignoring package {package.Id} because it is a minor update ({package.VersionString} -> {package.NewVersionString}) and SkipMinorUpdates is set to true."
46+
$"Ignoring package {package.Id} because it is a minor update ({package.VersionString} -> {package.NewVersionString}) below skip level {installOptions.SkipMinorUpdatesLevel} and SkipMinorUpdates is set to true."
4647
);
4748
return false;
4849
}

‎src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/InvalidImportedPackage.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public bool NewerVersionIsInstalled()
199199
return Task.FromResult<string?>("");
200200
}
201201

202-
public bool IsUpdateMinor()
202+
public bool IsUpdateMinor(int level = InstallOptions.DefaultSkipMinorLevel)
203203
{
204204
return false;
205205
}

‎src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Package.cs‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,17 +324,26 @@ public virtual bool NewerVersionIsInstalled()
324324
}
325325
}
326326

327-
public virtual bool IsUpdateMinor()
327+
// 1-based position of the most significant version component that changed
328+
// (1=Major, 2=Minor, 3=Patch, 4=Remainder), or 0 if identical/unparseable.
329+
private int HighestChangedVersionComponent()
330+
{
331+
if (NormalizedVersion == CoreTools.Version.Null || NormalizedNewVersion == CoreTools.Version.Null)
332+
return 0;
333+
if (NormalizedVersion.Major != NormalizedNewVersion.Major) return 1;
334+
if (NormalizedVersion.Minor != NormalizedNewVersion.Minor) return 2;
335+
if (NormalizedVersion.Patch != NormalizedNewVersion.Patch) return 3;
336+
if (NormalizedVersion.Remainder != NormalizedNewVersion.Remainder) return 4;
337+
return 0;
338+
}
339+
340+
public virtual bool IsUpdateMinor(int level = InstallOptions.DefaultSkipMinorLevel)
328341
{
329342
if (!IsUpgradable)
330343
return false;
331344

332-
return NormalizedVersion.Major == NormalizedNewVersion.Major
333-
&& NormalizedVersion.Minor == NormalizedNewVersion.Minor
334-
&& (
335-
NormalizedVersion.Patch != NormalizedNewVersion.Patch
336-
|| NormalizedVersion.Remainder != NormalizedNewVersion.Remainder
337-
);
345+
int changed = HighestChangedVersionComponent();
346+
return changed >= level;
338347
}
339348

340349
public virtual Task<InstallOptions> GetInstallOptions() =>

‎src/UniGetUI.PackageEngine.Serializable/InstallOptions.cs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class InstallOptions : SerializableComponent<InstallOptions>
1212
private const string AS_ADMIN = "RunAsAdministrator";
1313
private const string PRERELEASE = "PreRelease";
1414
private const string SKIP_MINOR = "SkipMinorUpdates";
15+
private const string SKIP_MINOR_LEVEL = "SkipMinorUpdatesLevel";
1516
private const string REMOVE_DATA_UNINST = "RemoveDataOnUninstall";
1617
private const string CLEAR_PREV_VER = "UninstallPreviousVersionsOnUpdate";
1718
private const string ABORT_PRE_INST_FAIL = "AbortOnPreInstallFail";
@@ -65,6 +66,7 @@ public class InstallOptions : SerializableComponent<InstallOptions>
6566
POST_UPD_CMD,
6667
PRE_UNINST_CMD,
6768
POST_UNINST_CMD,
69+
SKIP_MINOR_LEVEL,
6870
];
6971

7072
public readonly IReadOnlyList<string> _listKeys =
@@ -104,6 +106,15 @@ public bool SkipMinorUpdates
104106
get => _boolVal[SKIP_MINOR];
105107
set => _boolVal[SKIP_MINOR] = value;
106108
}
109+
110+
// The version-number position (1=Major, 2=Minor, 3=Patch, 4=Remainder) from which a change is
111+
// still considered "minor" and therefore skippable. Default 3 reproduces the legacy behaviour.
112+
public const int DefaultSkipMinorLevel = 3;
113+
public int SkipMinorUpdatesLevel
114+
{
115+
get => int.TryParse(_strVal[SKIP_MINOR_LEVEL], out int v) && v is >= 2 and <= 4 ? v : DefaultSkipMinorLevel;
116+
set => _strVal[SKIP_MINOR_LEVEL] = value == DefaultSkipMinorLevel ? "" : value.ToString();
117+
}
107118
public bool RemoveDataOnUninstall
108119
{
109120
get => _boolVal[REMOVE_DATA_UNINST];

‎src/UniGetUI.PackageEngine.Tests/UpgradablePackagesLoaderTests.cs‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,47 @@ public async Task EvaluatePackageAsync_SkipsMinorUpdatesWhenConfigured()
6666
Assert.False(await loader.EvaluatePackageAsync(package));
6767
}
6868

69+
[Fact]
70+
public async Task EvaluatePackageAsync_RespectsSkipMinorLevel()
71+
{
72+
var manager = new PackageManagerBuilder().Build();
73+
_ = new InstalledPackagesLoader([manager]);
74+
_ = new DiscoverablePackagesLoader([manager]);
75+
var loader = new TestUpgradablePackagesLoader([manager]);
76+
77+
// A 3rd-position (patch) change on a four-part version.
78+
var package = new PackageBuilder()
79+
.WithManager(manager)
80+
.WithId("Contoso.FourPart")
81+
.WithVersion("3.4.5.6")
82+
.WithNewVersion("3.4.6.6")
83+
.Build();
84+
85+
// Level 4 => only 4th-position changes count as minor, so this patch change must NOT be skipped.
86+
InstallOptionsFactory.SaveForPackage(
87+
new InstallOptions
88+
{
89+
OverridesNextLevelOpts = true,
90+
SkipMinorUpdates = true,
91+
SkipMinorUpdatesLevel = 4,
92+
},
93+
package
94+
);
95+
Assert.True(await loader.EvaluatePackageAsync(package));
96+
97+
// Default level (3) => a 3rd-position change is minor and must be skipped.
98+
InstallOptionsFactory.SaveForPackage(
99+
new InstallOptions
100+
{
101+
OverridesNextLevelOpts = true,
102+
SkipMinorUpdates = true,
103+
SkipMinorUpdatesLevel = InstallOptions.DefaultSkipMinorLevel,
104+
},
105+
package
106+
);
107+
Assert.False(await loader.EvaluatePackageAsync(package));
108+
}
109+
69110
[Fact]
70111
public async Task EvaluatePackageAsync_SkipsIgnoredAndSupersededPackages()
71112
{

0 commit comments

Comments
 (0)