better handle missing MaxFileSize prop

This commit is contained in:
2024-02-23 00:30:42 -05:00
parent dfb8a3eccc
commit 038b8f2685
+6 -2
View File
@@ -43,13 +43,14 @@ ForEach ( $plan in $BackupPlans ) {
# Function to process each file
Function ProcessFile {
param([System.IO.FileInfo]$File)
Switch ( $File ) {
# Filter out if name matches an excluded path
{ $null -ne ($ExcludedPaths | Where-Object { $File.FullName.Replace('\','\\') -match $_.Replace('\','\\') }) } { Update-FilteredFiles $File }
# Filter out if file size is greater than plan maximum
{ $File.Length -gt $plan.MaxFileSize } { Update-FilteredFiles $File }
{ $File.Length -gt $MaxFileSize } { Update-FilteredFiles $File }
# Add item to $IncludeFiles
default { $IncludedFiles.Add($item.FullName, $item.Length) | Out-Null }
@@ -110,6 +111,9 @@ ForEach ( $plan in $BackupPlans ) {
ForEach ( $path in $IncludedPaths ) { Write-Output $path }
}
# Define $MaxFileSize if it exists, or set it to the max value of a long to bypass it
If ( $null -ne $plan.MaxFileSize ) { $MaxFileSize = $plan.MaxFileSize } Else { $MaxFileSize = [long]::MaxValue }
# Process each path in $IncludedPaths
ForEach ($path in $IncludedPaths ) {
@@ -117,7 +121,7 @@ ForEach ( $plan in $BackupPlans ) {
If ( !(Test-Path $path) ) { Continue }
# If $path is an individual file, process it separately
$item = Get-Item -Path $path
$item = Get-Item -Path $path -ErrorAction SilentlyContinue
If ( $item -is [System.IO.FileInfo] ) { ProcessFile $item ; Continue }
# Get all children of $path