Skip to content

Commit 4e4a0ad

Browse files
committed
Add 'clean --all' to wipe all cached apps
1 parent 00df9f8 commit 4e4a0ad

3 files changed

Lines changed: 58 additions & 2 deletions

File tree

plans/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ executor needs no context beyond the plan file itself.
1111
|---|------|----------|--------|------------|--------|
1212
| 001 | [Harden background cache cleanup](001-harden-cache-cleanup.md) | P1 | S || DONE |
1313
| 002 | [End-to-end cache behavior tests](002-e2e-cache-tests.md) | P1 | M || DONE |
14-
| 003 | [`go clean --all`](003-clean-all.md) | P2 | S | 001 | TODO |
14+
| 003 | [`go clean --all`](003-clean-all.md) | P2 | S | 001 | DONE |
1515
| 004 | [Readme: cache and cleaning docs](004-readme-cache-docs.md) | P2 | S | 003 | TODO |
1616

1717
Recommended order: **001 → 002 → 003 → 004**.

src/Tests/CleanupManagerTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,44 @@ public void Cleanup_saves_settings_even_when_a_delete_fails()
5656
Assert.NotNull(SettingsStore.Load(settingsPath).LastCleanupUtc);
5757
}
5858

59+
[Fact]
60+
public void Cleanup_with_zero_days_deletes_fresh_directories()
61+
{
62+
var root = CreateTempDir();
63+
var settingsRoot = CreateTempDir();
64+
var settingsPath = Path.Combine(settingsRoot, "go.toml");
65+
var first = CreateSubDir(root, "first");
66+
var second = CreateSubDir(root, "second");
67+
68+
Directory.SetLastWriteTimeUtc(first, DateTime.UtcNow);
69+
Directory.SetLastWriteTimeUtc(second, DateTime.UtcNow);
70+
71+
var exit = CleanupManager.Cleanup(days: 0, root: root, settingsPath: settingsPath);
72+
73+
Assert.Equal(0, exit);
74+
Assert.False(Directory.Exists(first));
75+
Assert.False(Directory.Exists(second));
76+
}
77+
78+
[Fact]
79+
public void Cleanup_with_zero_days_preserves_files_in_root()
80+
{
81+
var root = CreateTempDir();
82+
var settingsRoot = CreateTempDir();
83+
var settingsPath = Path.Combine(settingsRoot, "go.toml");
84+
var subdir = CreateSubDir(root, "cached");
85+
var looseFile = Path.Combine(root, "go.toml");
86+
File.WriteAllText(looseFile, "settings");
87+
88+
Directory.SetLastWriteTimeUtc(subdir, DateTime.UtcNow);
89+
90+
var exit = CleanupManager.Cleanup(days: 0, root: root, settingsPath: settingsPath);
91+
92+
Assert.Equal(0, exit);
93+
Assert.False(Directory.Exists(subdir));
94+
Assert.True(File.Exists(looseFile));
95+
}
96+
5997
[Fact]
6098
public void SettingsStore_roundtrips_last_cleanup_utc()
6199
{

src/go/Program.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,26 @@ state.App is not null &&
4848
/// Deletes cached publish artifacts for a file-based .NET app.
4949
/// </summary>
5050
/// <param name="input">Path to an existing .cs file.</param>
51-
static int CleanAsync([Argument] string input)
51+
/// <param name="all">Delete cached artifacts for all apps instead.</param>
52+
static int CleanAsync([Argument] string? input = null, bool all = false)
5253
{
54+
if (all)
55+
{
56+
if (input is not null)
57+
{
58+
ConsoleApp.LogError("Specify either a .cs file or --all, not both.");
59+
return 1;
60+
}
61+
62+
return CleanupManager.Cleanup(days: 0);
63+
}
64+
65+
if (input is null)
66+
{
67+
ConsoleApp.LogError("Specify a .cs file to clean, or --all to clean all cached apps.");
68+
return 1;
69+
}
70+
5371
if (!TryResolveEntryPoint(input, out var publishDir, out var stamp))
5472
return 1;
5573

0 commit comments

Comments
 (0)