Progmasoft Git

tazel

A build system for C, C++, Objective-C, Objective-C++ and Zig, with C# project files.

Clonegit clone https://git.progmasoft.com/tazel

fix(cli): let Ctrl+C stop clean while it waits for the state lock

Motivation: clean ran on the synchronous path, which has no cancellation
token, so it waited for the state lock with CancellationToken.None while
every other locking command could be stopped.

Changes: CleanCommand gets its own arm in RunAsync, CleanLocked, which
passes the command's token to LockState; the case leaves RunAtOnce.
Behavior is otherwise unchanged.

Verification: Release build with warnings as errors (0 errors); full
suite 803 passed, 1 skipped.
Commit
2cc831c17a9a825ce37faba24e8aee2986470cdd
Author
Leitwolf11 ·
Parents
00fa9c8fdeed

Files · Download .tar.gz

Changes

 src/Progmasoft.Tazel/Cli/Commands.cs | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/Progmasoft.Tazel/Cli/Commands.cs b/src/Progmasoft.Tazel/Cli/Commands.cs
index 2c7558b..837d82d 100644
--- a/src/Progmasoft.Tazel/Cli/Commands.cs
+++ b/src/Progmasoft.Tazel/Cli/Commands.cs
@@ -64,6 +64,7 @@ internal sealed partial class Commands(Reporter reporter, string workingDirector
             ToolWrapperCommand wrapper => Task.FromResult(CreateWrapper(wrapper)),
             OptionsCommand options => Task.FromResult(new ConfigurationCommands(reporter, workingDirectory).Options(options)),
             ValidateCommand validate => Task.FromResult(new ConfigurationCommands(reporter, workingDirectory).Validate(validate.Kind, validate.Scope)),
+            CleanCommand clean => Task.FromResult(CleanLocked(clean, cancel)),
             _ => Task.FromResult(RunAtOnce(command)),
         };
     }
@@ -98,11 +99,6 @@ internal sealed partial class Commands(Reporter reporter, string workingDirector
                 return 0;
             case DotnetWhatIsCommand whatIs:
                 return WhatIs(whatIs.Term);
-            case CleanCommand clean:
-                {
-                    using var held = clean.DryRun ? null : LockState("clean", CancellationToken.None);
-                    return Clean(clean.Expunge, clean.DryRun);
-                }
             case CacheKeygenCommand keygen:
                 {
                     var (publicKey, signingKey) = Cache.CacheKey.Generate(keygen.Algorithm);
@@ -512,6 +508,13 @@ internal sealed partial class Commands(Reporter reporter, string workingDirector
     private Project.StateLock? LockState(string command, CancellationToken cancel) =>
         ModuleFiles.RootOf(workingDirectory) is { } root ? Project.StateLock.Acquire(root, command, reporter.Status, cancel) : null;
 
+    // clean holds the state lock unless it only lists; Ctrl+C stops the wait for it as for the other commands.
+    private int CleanLocked(CleanCommand clean, CancellationToken cancel)
+    {
+        using var held = clean.DryRun ? null : LockState("clean", cancel);
+        return Clean(clean.Expunge, clean.DryRun);
+    }
+
     private async Task<int> WithStateLockAsync(string command, Func<Task<int>> work, CancellationToken cancel)
     {
         using var held = LockState(command, cancel);