Skip to content

Commit

Permalink
add error handling of window path length limit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
buidav committed Nov 16, 2024
1 parent cb2d5c8 commit ebd7106
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions PowerShell/ScubaGear/Modules/Orchestrator.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,29 @@ function Merge-JsonOutput {
$ReportJson = $ReportJson.replace("\u003e", ">")
$ReportJson = $ReportJson.replace("\u0027", "'")



# Check if the absolute final results output path is greater than the allowable windows file Path length
# Trim the GUID to save some character length space if it is.
$MAX_WINDOWS_PATH_LEN = 256
$CharactersToTrim = 13
$CurrentLocation = (Get-Location) | Select-Object -ExpandProperty ProviderPath
$JoinedFilePath = Join-Path -Path $CurrentLocation -ChildPath (Join-Path -Path $OutFolderPath -ChildPath "$($OutJsonFileName)_$($ReportUuid)")
$AbsoluteResultsFilePathLen = ([System.IO.Path]::GetFullPath($JoinedFilePath)).Length

if ($AbsoluteResultsFilePathLen -gt ($MAX_WINDOWS_PATH_LEN + $CharactersToTrim)) {
$PathLengthErrorMessage = "ScubaGear was executed in a location where the maximum file path length is greater than the allowable Windows File System limit `
Please execute ScubaGear in a location where for Window File Path limit is less than $($MAX_WINDOWS_PATH_LEN). The current length is $($AbsoluteResultsFilePathLen)"
throw $PathLengthErrorMessage
}
elseif ($AbsoluteResultsFilePathLen -gt $MAX_WINDOWS_PATH_LEN) {
$ReportUuid = $ReportUuid.Substring(0, $ReportUuid.Length - $CharactersToTrim)
$PathLengthErrorMessage = "The GUID appended to the ScubaResults file name was truncated by $CharactersToTrim `
because ScubaGear was executed in a location where the Windows Absolute file path was longer than $($MAX_WINDOWS_PATH_LEN)
This should not have affected the content of the final output but please proceed with caution when moving the file to other directories"
Write-Warning $PathLengthErrorMessage
}

# Save the file
$JsonFileName = Join-Path -Path $OutFolderPath "$($OutJsonFileName)_$($ReportUuid).json" `
-ErrorAction 'Stop'
Expand Down

0 comments on commit ebd7106

Please sign in to comment.