Skip to content

Commit c4427f0

Browse files
Microsoft Graph DevX ToolingMicrosoft Graph DevX Tooling
authored andcommitted
Removing more cached files
1 parent e23f9ea commit c4427f0

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

tools/GenerateModules.ps1

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ if ($ModuleToGenerate.Count -eq 0) {
7272
#This is to ensure that the autorest temp folder is cleared before generating the modules
7373
$TempPath = [System.IO.Path]::GetTempPath()
7474
# Check if there is any folder with autorest in the name
75-
$AutoRestTempFolder = Get-ChildItem -Path $TempPath -Recurse -Directory
75+
$AutoRestTempFolder = Get-ChildItem -Path $TempPath -Recurse -Directory | Where-Object { $_.Name -match "autorest" }
7676

7777
# Go through each folder and forcefully delete autorest related files
7878
$AutoRestTempFolder | ForEach-Object {
@@ -91,7 +91,15 @@ $AutoRestTempFolder | ForEach-Object {
9191
}
9292
}
9393

94-
94+
#Delete any file in temp folder with the extension .tmp or .log or .db
95+
Get-ChildItem -Path $TempPath -Recurse | Where-Object { $_.Extension -match ".tmp|.log|.db" } | ForEach-Object {
96+
$File = $_
97+
Write-Debug "Removing cached file $File"
98+
if (Test-Path $File.FullName) {
99+
#Remove the file
100+
Remove-Item -Path $File.FullName -Force
101+
}
102+
}
95103
$Stopwatch = [system.diagnostics.stopwatch]::StartNew()
96104
$CpuCount = (Get-CimInstance Win32_Processor).NumberOfLogicalProcessors
97105
$Throttle = [math]::Min(4, $cpuCount / 2) # Use half the CPU count but max 4
@@ -118,7 +126,7 @@ $ModuleToGenerate | ForEach-Object -Parallel {
118126
[string] $Path
119127
)
120128
$OpenFiles = @()
121-
$Files = Get-ChildItem -Path $Path -Recurse -Directory
129+
$Files = Get-ChildItem -Path $Path -Recurse -Directory | Where-Object { $_.Name -match "autorest" }
122130
$Files | ForEach-Object {
123131
$File = $_
124132
try {
@@ -136,7 +144,21 @@ $ModuleToGenerate | ForEach-Object -Parallel {
136144
if ($OpenFiles.Count -gt 0) {
137145
$OpenFiles = Get-OpenFiles -Path $TempPath
138146
}
139-
147+
148+
#Delete any file in temp folder with the extension .tmp or .log or .db
149+
Get-ChildItem -Path $TempPath -Recurse | Where-Object { $_.Extension -match ".tmp|.log|.db|.db-shm|.db-wal" } | ForEach-Object {
150+
$File = $_
151+
Write-Debug "Removing cached file $File"
152+
if (Test-Path $File.FullName) {
153+
#Remove the file
154+
try{
155+
Remove-Item -Path $File.FullName -Force
156+
}
157+
catch {
158+
Write-Warning "Failed to remove file $File"
159+
}
160+
}
161+
}
140162

141163

142164
} -ThrottleLimit $Throttle

0 commit comments

Comments
 (0)