Skip to content

Commit 0ecb9e4

Browse files
steventuxCopilot
andcommitted
Check for storage directory and files before archiving
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 7e23a82 commit 0ecb9e4

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

scripts/powershell/maintenance.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,26 @@ function Archive-PACS {
170170

171171
Write-Log "Archiving PACS files..." "INFO"
172172

173-
$pacsDir = Join-Path $BaseInstallPath "data\storage\*"
173+
$storageDir = Join-Path $BaseInstallPath "data\storage"
174174
$archiveZip = Join-Path $BaseInstallPath "data\storage.zip"
175175

176+
if (-not (Test-Path $storageDir)) {
177+
Write-Log "PACS storage directory not found: $storageDir" "WARNING"
178+
return
179+
}
180+
181+
$pacsDir = Join-Path $storageDir "*"
182+
$hasFiles = Get-ChildItem -Path $pacsDir -Force -ErrorAction SilentlyContinue | Select-Object -First 1
183+
if (-not $hasFiles) {
184+
Write-Log "No PACS files found to archive." "INFO"
185+
return
186+
}
187+
176188
Compress-Archive -Path $pacsDir -DestinationPath $archiveZip -Force
177189

178190
Write-Log "PACS files archived to $archiveZip." "INFO"
179191

180192
Remove-Item $pacsDir -Recurse -Force
181-
182193
Write-Log "PACS files removed from storage directory." "INFO"
183194

184195
Write-Log "PACS files archived successfully." "SUCCESS"

0 commit comments

Comments
 (0)