Skip to content
This repository was archived by the owner on Aug 16, 2025. It is now read-only.

Commit ba7ea5a

Browse files
committed
0.1.6
Features: - Added garbage creation prevention information field in JSON schema and some of the rules in default cleanup list Fixes: - Fixed wrong string definitions for reserved words in JSON schema - Fixed the dry run flow to display garbage cleaner version information before performing other operations - Improved notification when there is nothing to do - Iterating through files defined by a rule containing a wildcard character (`*`) will now be done only if at least one such file exists Documentation: - Added garbage creation prevention instructions to dry run documentation - Added quick dry run info to the main README - Added garbage creation prevention feature to the main README
1 parent 3bdd574 commit ba7ea5a

File tree

7 files changed

+149
-18
lines changed

7 files changed

+149
-18
lines changed

README.adoc

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ Written in PowerShell 7 with simple JSON configuration. Tested on PowerShell 7.4
2020
** *The default cleanup list does not require administrative privileges*
2121
** *Each entry in the default cleanup list is carefully reviewed by consulting official documentation to verify that it
2222
is safe to delete*
23-
** *Custom cleanup list which you can expand whenever you need, without having to wait for the update or submit a feature request*
23+
** *Custom cleanup lists which you can expand whenever you need, without having to wait for the update or submit a feature request*
2424
** *Custom cleanup lists which you can easily share with anyone or have them on multiple devices*
2525
* *Granular cleaning using filters like application, category,...*
26+
* *Built-in helpful instructions on how to prevent further garbage creation*
2627
* *No tracking, no telemetry, no pinging home, completely free and open source*
2728

2829
=== Preview of commands
@@ -178,11 +179,39 @@ this documentation shorter, we will not mention instructions for the custom clea
178179
just like in the example above. Just use the `-cleanupListFile` option and set the path to your own cleanup list.
179180
====
180181

182+
=== Dry run
183+
184+
You can dry run constUP Garbage Cleaner with:
185+
186+
[source,shell]
187+
----
188+
pwsh .\constup-garbage-cleaner.ps1 -dryRun
189+
----
190+
191+
This will detect garbage on your system, but will not delete it. This option is useful when you want to roughly preview
192+
what is going to be deleted.
193+
194+
==== Detailed dry run
195+
196+
To get more detailed information about the garbage on your system without cleaning it, run:
197+
198+
[source,shell]
199+
----
200+
pwsh .\constup-garbage-cleaner.ps1 -dryRun -detailed
201+
----
202+
203+
This will:
204+
205+
* List all garbage with their locations and sizes.
206+
* Each cleanup rule can have information on how to prevent garbage creation (relevant to that particular rule). Detailed
207+
dry run will show this information for garbage which was found on your system.
208+
181209
== More documentation
182210

183211
The following documentation is also available:
184212

185-
* link:doc/dry-run.adoc[Dry run] (with cleanup list configuration file error detection)
213+
* link:doc/dry-run.adoc[Dry run] (with garbage creation prevention instructions and cleanup list configuration file
214+
error detection)
186215
* link:doc/cleanup-list-file.adoc[Cleanup list file and listing available applications, categories,...]
187216
** link:doc/categories.adoc[Categories]
188217
* link:doc/advanced-use.adoc[Advanced use] (including cleaning by property filters, for example: application,

cleanup-list.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"category": "Windows",
3838
"entity_category": "log",
3939
"description": "WSLg (Windows Subsystem for Linux GUI) remote desktop client auto trace logs. Can be generated when using Docker. Can be dozens of gigabytes.",
40+
"instructions": "Real solution is not yet available, however there is a hack that works. To stop WSLg from making these files, stop WSL with `wsl --shutdown`, go to `~/AppData/Local/Temp/DiagOutputDir/`, delete the `RdClientAutoTrace` directory and create an empty file with the same name (`RdClientAutoTrace`) in its place. This will stop WSLg from creating new files.",
4041
"delete": {
4142
"type": "file",
4243
"location": "~/AppData/Local/Temp/DiagOutputDir/RdClientAutoTrace/RdClientAutoTrace-*.etl"
@@ -103,6 +104,7 @@
103104
"category": "installer",
104105
"entity_category": "cache",
105106
"description": "Scoop.sh installer cache. Contains packaged versions of all previously installed or updated applications.",
107+
"instructions": "Scoop does not support disabling cache in configuration. Use the `--no-cache` flag instead, when issuing commands. Example: `scoop update --all --no-cache`.",
106108
"delete": {
107109
"type": "file",
108110
"location": "~/scoop/cache/*.*"

cleanup-list.schema.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,22 @@
4444
"custom_category": {
4545
"type": "string"
4646
},
47-
"description": {
47+
"description": "object",
48+
"properties": {
49+
"type": "string"
50+
},
51+
"instructions": {
4852
"type": "string"
4953
},
5054
"delete": {
5155
"type": "object",
5256
"properties": {
53-
"type": {
57+
"type": "object",
58+
"properties": {
5459
"type": "string",
5560
"enum": ["file", "directory", "registry value", "registry key"]
56-
},
61+
}
62+
},
5763
"location": {
5864
"type": "string"
5965
}
@@ -73,7 +79,6 @@
7379
"delete",
7480
"active"
7581
]
76-
}
7782
},
7883
"additionalProperties": false
7984
}

constup-garbage-cleaner.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ param (
3636
. (Join-Path $PSScriptRoot ./src/remove-from-registry.ps1)
3737
. (Join-Path $PSScriptRoot ./src/math.ps1)
3838
. (Join-Path $PSScriptRoot ./src/get-entities.ps1)
39+
. (Join-Path $PSScriptRoot ./src/prevention-instructions.ps1)
3940

4041
if ($help) {
4142
Show-Help
@@ -106,14 +107,14 @@ if (Test-Path $cleanupListFile)
106107
}
107108
elseif ($dryRun)
108109
{
109-
$entities = Get-Entities -cleanupListFile $cleanupListFile -applications $applications -categories $categories -entityCategories $entityCategories -types $types -customCategories $customCategories
110-
111110
$version = Get-Content -Path (Join-Path $PSScriptRoot ./version)
112111
Write-Host "constUP Garbage Cleaner $version - dry run"
113112

113+
$entities = Get-Entities -cleanupListFile $cleanupListFile -applications $applications -categories $categories -entityCategories $entityCategories -types $types -customCategories $customCategories
114+
114115
if ($null -eq $entities)
115116
{
116-
Write-Host "Nothing to do."
117+
Write-Host "Everything is clean. Nothing to do."
117118

118119
exit 0
119120
}
@@ -168,6 +169,11 @@ if (Test-Path $cleanupListFile)
168169
Write-Host "There are no registry values to delete."
169170
}
170171
Write-Host "----------"
172+
173+
if ($entities.preventionInstructions.Count -gt 0)
174+
{
175+
Write-PreventionInstructions -preventionInstructions $entities.preventionInstructions
176+
}
171177
}
172178

173179
$size = $entities.totalSize
@@ -205,7 +211,7 @@ if (Test-Path $cleanupListFile)
205211
$entities = Get-Entities -cleanupListFile $cleanupListFile -applications $applications -categories $categories -entityCategories $entityCategories -types $types -customCategories $customCategories
206212

207213
if ($null -eq $entities) {
208-
Write-Host "Nothing to do."
214+
Write-Host "Everything is clean. Nothing to do."
209215

210216
exit 0
211217
}

doc/dry-run.adoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ some_obsolete_log
5353
5454
At the end, the dry run will also list the total savings, just like in the non-detailed mode.
5555
56+
=== Garbage creation prevention instructions
57+
58+
If you run a detailed dry run (`--dryRun --detailed`), you will also get instructions on how to prevent further creation
59+
of garbage. These instructions are available for some cleaning rules, where it makes sense.
60+
61+
The result will look something like this:
62+
63+
[source,text]
64+
----
65+
===Helpful info===
66+
Some useful information on how to prevent creation of garbage files which were found on your system:
67+
----------
68+
Rule name: scoop_cache
69+
Location: ~/scoop/cache/*.*
70+
Prevention instructions: Scoop does not support disabling cache in configuration. Use the `--no-cache` flag instead, when issuing commands. Example: `scoop update --all --no-cache`.
71+
----
72+
5673
=== Dry run also detects errors in cleanup list file
5774

5875
Whether you start dry run in detailed or non-detailed mode, it will report some of the errors found in your cleanup list

src/get-entities.ps1

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function Get-Entities {
99
[string[]]$customCategories = @()
1010
)
1111

12+
. (Join-Path $PSScriptRoot ./prevention-instructions.ps1)
13+
1214
$json = Get-Content -Raw $cleanupListFile | ConvertFrom-Json
1315
$filteredProperties = $json.PSObject.Properties | Where-Object {
1416
$_.Value.active -eq $true -and
@@ -24,25 +26,38 @@ function Get-Entities {
2426
$directories = New-Object System.Collections.Generic.List[object]
2527
$registryValues = New-Object System.Collections.Generic.List[object]
2628
$cleanerErrors = New-Object System.Collections.Generic.List[object]
29+
$preventionInstructions = New-Object System.Collections.Generic.List[object]
2730

2831
$sizeCounter = 0
2932
$registryCounter = 0
3033

3134
$filteredProperties | ForEach-Object {
3235
$location = $_.Value.delete.location
3336
$name = $_.Name
37+
$instructions = $_.Value.instructions
3438
switch ($_.Value.delete.type)
3539
{
3640
"file" {
3741
if ($location -like '*[*]*') {
38-
$matchingFiles = Get-ChildItem -Path $location -File
39-
foreach ($file in $matchingFiles) {
40-
$fileItem = @{}
41-
$fileItem.location = $file.FullName
42-
$fileItem.size = $file.Length
43-
$fileItem.rule = $name
44-
$files.Add($fileItem)
45-
$sizeCounter += $fileItem.size
42+
# first check if there are any files which match the pattern, then process them
43+
$potentialyMatchingFiles = Get-ChildItem -Path (Split-Path $location) -Filter (Split-Path $location -Leaf) -File
44+
if ($potentialyMatchingFiles.Count -gt 0)
45+
{
46+
$matchingFiles = Get-ChildItem -Path $location -File
47+
foreach ($file in $matchingFiles)
48+
{
49+
$fileItem = @{}
50+
$fileItem.location = $file.FullName
51+
$fileItem.size = $file.Length
52+
$fileItem.rule = $name
53+
$files.Add($fileItem)
54+
$sizeCounter += $fileItem.size
55+
}
56+
57+
if ($null -ne $instructions -and "" -ne $instructions) {
58+
$preventionInstructionsItem = Add-PreventionInstructions -name $name -location $location -instructions $instructions
59+
$preventionInstructions.Add($preventionInstructionsItem)
60+
}
4661
}
4762
} elseif (Test-Path -Path $location -PathType Leaf) {
4863
$fileItem = @{}
@@ -52,6 +67,11 @@ function Get-Entities {
5267
$fileItem.rule = $name
5368
$files.Add($fileItem)
5469
$sizeCounter += $fileItem.size
70+
71+
if ($null -ne $instructions -and "" -ne $instructions) {
72+
$preventionInstructionsItem = Add-PreventionInstructions -name $name -location $location -instructions $instructions
73+
$preventionInstructions.Add($preventionInstructionsItem)
74+
}
5575
}
5676
elseif (Test-Path -Path $location -PathType Container)
5777
{
@@ -69,6 +89,11 @@ function Get-Entities {
6989
$directoryItem.rule = $name
7090
$directories.Add($directoryItem)
7191
$sizeCounter += $size
92+
93+
if ($null -ne $instructions -and "" -ne $instructions) {
94+
$preventionInstructionsItem = Add-PreventionInstructions -name $name -location $location -instructions $instructions
95+
$preventionInstructions.Add($preventionInstructionsItem)
96+
}
7297
}
7398
elseif (Test-Path -Path $location -PathType Leaf)
7499
{
@@ -89,6 +114,11 @@ function Get-Entities {
89114
$registryValues.Add($registryValueItem)
90115
$registryCounter += 1
91116
}
117+
118+
if ($null -ne $instructions -and "" -ne $instructions) {
119+
$preventionInstructionsItem = Add-PreventionInstructions -name $name -location $location -instructions $instructions
120+
$preventionInstructions.Add($preventionInstructionsItem)
121+
}
92122
}
93123

94124
break
@@ -108,6 +138,11 @@ function Get-Entities {
108138
$registryCounter += 1
109139
}
110140
}
141+
142+
if ($null -ne $instructions -and "" -ne $instructions) {
143+
$preventionInstructionsItem = Add-PreventionInstructions -name $name -location $location -instructions $instructions
144+
$preventionInstructions.Add($preventionInstructionsItem)
145+
}
111146
}
112147
}
113148

@@ -125,6 +160,7 @@ function Get-Entities {
125160
$result.directories = $directories
126161
$result.registryValues = $registryValues
127162
$result.cleanerErrors = $cleanerErrors
163+
$result.preventionInstructions = $preventionInstructions
128164
$result.totalSize = $sizeCounter
129165
$result.totalRegistryEntries = $registryCounter
130166

src/prevention-instructions.ps1

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function Add-PreventionInstructions {
2+
param (
3+
[Parameter(Mandatory=$true)]
4+
[string]$name,
5+
[Parameter(Mandatory=$true)]
6+
[string]$location,
7+
[Parameter(Mandatory=$true)]
8+
[string]$instructions
9+
)
10+
11+
$preventionInstructionsItem = @{}
12+
$preventionInstructionsItem.name = $name
13+
$preventionInstructionsItem.location = $location
14+
$preventionInstructionsItem.instructions = $instructions
15+
16+
return $preventionInstructionsItem
17+
}
18+
19+
function Write-PreventionInstructions {
20+
param(
21+
[Parameter(Mandatory=$true)]
22+
[array]$preventionInstructions
23+
)
24+
25+
if ($preventionInstructions.Count -ne 0) {
26+
Write-Host "===Helpful info==="
27+
Write-Host "Some useful information on how to prevent creation of garbage files which were found on your system:"
28+
Write-Host "----------"
29+
$preventionInstructions | ForEach-Object {
30+
Write-Host "Rule name: $($_.name)"
31+
Write-Host "Location: $($_.location)"
32+
Write-Host "Prevention instructions: $($_.instructions)"
33+
Write-Host "----------"
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)