Skip to content

Commit 3c32669

Browse files
committed
Prevent updating a signed bundle
1 parent 753ce59 commit 3c32669

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/EasySign.CommandLine/BundleWorker.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
using Spectre.Console;
66

7-
using static System.Net.Mime.MediaTypeNames;
8-
97
namespace SAPTeam.EasySign.CommandLine
108
{
119
public abstract partial class CommandProvider<TBundle, TConfiguration>
@@ -79,7 +77,10 @@ protected bool LoadBundle(bool readOnly = true)
7977
/// <param name="continueOnError">
8078
/// A value indicating whether to continue adding files if an error occurs.
8179
/// </param>
82-
protected virtual void RunAdd(StatusContext statusContext, string[] files, bool replace, bool recursive, bool continueOnError)
80+
/// <param name="force">
81+
/// A value indicating whether to force the addition of files to a signed bundle.
82+
/// </param>
83+
protected virtual void RunAdd(StatusContext statusContext, string[] files, bool replace, bool recursive, bool continueOnError, bool force)
8384
{
8485
Logger.LogInformation("Running add command");
8586

@@ -94,6 +95,13 @@ protected virtual void RunAdd(StatusContext statusContext, string[] files, bool
9495
statusContext.Status("[yellow]Loading Bundle[/]");
9596

9697
if (!LoadBundle(false)) return;
98+
99+
if (!force && Bundle.Signatures.Entries.Count > 0)
100+
{
101+
Logger.LogError("Bundle is already signed, cannot add files");
102+
AnsiConsole.MarkupLine($"[{Color.Red}]Cannot add files to a signed bundle[/]");
103+
return;
104+
}
97105
}
98106

99107
statusContext.Status("[yellow]Adding Files[/]");

src/EasySign.CommandLine/CommandProvider.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public Command Add
9393
Option<bool> continueOpt = new Option<bool>("--continue", "Continue adding files if an error occurs");
9494
continueOpt.AddAlias("-c");
9595

96+
Option<bool> forceOpt = new Option<bool>("--force", "Add files even if the bundle is signed");
97+
9698
Command command = new Command("add", "Create new bundle or update an existing one")
9799
{
98100
BundlePath,
@@ -102,11 +104,11 @@ public Command Add
102104
continueOpt,
103105
};
104106

105-
command.SetHandler((bundlePath, files, replace, recursive, continueOnError) =>
107+
command.SetHandler((bundlePath, files, replace, recursive, continueOnError, force) =>
106108
{
107109
InitializeBundle(bundlePath);
108-
Utilities.RunInStatusContext("[yellow]Preparing[/]", ctx => RunAdd(ctx, files, replace, recursive, continueOnError));
109-
}, BundlePath, filesArg, replaceOpt, recursiveOpt, continueOpt);
110+
Utilities.RunInStatusContext("[yellow]Preparing[/]", ctx => RunAdd(ctx, files, replace, recursive, continueOnError, force));
111+
}, BundlePath, filesArg, replaceOpt, recursiveOpt, continueOpt, forceOpt);
110112

111113
return command;
112114
}

0 commit comments

Comments
 (0)