Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CHECKSUMS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
22D6D77DC30B753FC74E513EFE398EF4DA6E8A6AE62D0D3DE0C922F03A1ABC75 .github/CODEOWNERS
29648B9E8D00A9B27A6264289E5B10703B14E80C036E91FF8C00E8BBCD2E5800 RELEASE-NOTES.md
2B3DD07AB98C1F92378EE4BDC8204AD737F966D52C88BA226ED6F4A4EC5AA31E _config.yml
2BDA9BE3955A5C5CB94DA6A61A251776DC3135B4235357788EC32D93C6659EF6 docs/release-process.md
2CC8992E8DA313F6CBC6D7751BB734BBECBA643B795B37D34057B4DE553F8C7F .gitignore
2E2102953B196CE96FA75D81444AF56E3A249A5E5B07C9FB181F65BC0DB09489 .editorconfig
3506A8BEAF4110E30F2E125D618E0C44476E173AD92283A4DDD90C0B71F92D60 CHANGELOG.md
35388D74DC4D7174B5AC058CCE5FB512C88240DF4DB086EE0A81C9AFA3613717 .vscode/tasks.json
38A871D48BEB9A98E14B4D06B3056556C77924C448FC9DFCF70BF1DE22405F54 assets/banner-compact.svg
3A844B374BDB13EAFC32E96ACD1562E463BC740867741CCA374B086C65F90D4F .gitattributes
3F0BE5B3E0E2374698A1CA90E69F31B7B0B11A5B5801C40DBF9FB11EAD777FAF Tests/Runtime.Tests.ps1
440BC84BE1D09C5CD51366D32552B8318B8EB03D67ED3E02F8B4B179E087834D docs/logging.md
468E4648770DF273D018BC90F5DABD85E00BD5BBE6EFD9106EB436E278A8FE78 .github/workflows/ci.yml
4B1611351ADB567EAB568A68F6AFFA34BEC6652B600FABD327DDD9046A8B73FF docs/compatibility.md
51CA47A0CB49C782EC8BE60AA583A6EA828160347E1F44649506C300AC097670 assets/banner.svg
5236C66EA76CAD9F43C54D439E19B9E4E83DFEE159E19B44B90592B519D0C851 README.md
52E276805DC7BF24E12221266965614B2BBFC50270CFF3C2AD2B103B755CEF0F Scripts/Copy-OSDLogToFileShare.ps1
56531E99444653248D308A7918DAE6A7D8F8C0FB3B41FE055200FDA8538BECC6 assets/branding.json
5680E037241C06860FCAC7D8F6FF9AB2BBD6045D01A2E1F6271750222C29D494 _layouts/default.html
59854984853104DF5C353E2F681A15FC7924742F9A2E468C29AF248DCE45CE03 VERSION
Expand All @@ -29,6 +30,7 @@
6B6C7716FFCC77DF0FFA9D5E082E5040EDD2C3659C3842983D049E623B3821EF examples/README.md
6EC4415F361E7B41773C095592E4E5C2FC2A4F7D0D6F5C74BB1EA01A356A1C92 .github/ISSUE_TEMPLATE/bug_report.yml
6F255CD182D60581CAAC0CE468C47C32A26A9A1034EAED66031CF728412A908A Tests/Branding.Tests.ps1
7B5EE02DF0E20B53A806BED3B2760281439E8CC656EA62024F92E5F1BD3AA626 docs/development.md
7C35ABD79FE1F5346C10969D7F5CD0DEDF5D2CE3850D997AE3A3DB387FBFD565 CODE_OF_CONDUCT.md
7C48241074306AA35FF34F2E4C313B993ADA30A1033085D2D9CD00766908825F assets/README.md
7F00EF620F17FF1658F28201FA68203052E7F3F5DFED5593314157368E458C2B assets/copylog-flow-compact.svg
Expand All @@ -40,14 +42,13 @@
9D274A652C495A1368B760FFBCCD0CF5BA61A2C2F263B37A8AAF3C2607DC4F71 docs/distribution.md
9FE08577B65ED213A330F8B3BDA113478BEF85A043AB5A298A0939038BE918CB .github/ISSUE_TEMPLATE/config.yml
A047D4BF5DC341B6E460F0D3EABD52AA884ED92F0EE5A2B86847B3AEB3486609 assets/folder-arrow-right.svg
A24A15757CBDD393EE1029D1D00FFA91913F2DAE9E596657EB2BFB78B513DC69 Scripts/Copy-OSDLogToFileShare.ps1
A876032A2B36F7057673EAABF43790EB5274DE647F883EBA224C3CBBBFD43C2E docs/validation.md
AE0EBC700A81F090A59935F13672E9109DE6616D49E8FADC36003028DEB94202 docs/development.md
B742325E364BD5B9A311B00BEC3016E30B13274A1A4E8326A131A00E54EA7204 assets/favicon.svg
B8487D129B5573E9D7C7239FBF916D73373FC331F431D397194801FD08CA4812 SUPPORT.md
BB11493CAE1C3A5399A3259591473A35C71682AF903DE64C739AD296C5A4B014 .github/workflows/release.yml
BE400903F0FDBF54CA82A05AA16EC426300331EB21E28E894AD149B36DD8AE98 build/Invoke-Validation.ps1
BF528DC4807B5CD45B9513F4154551F3BD8BFDAD9BB4BA12A80C3FCBB7283063 .vscode/extensions.json
C1D445D112ECB795B5BC9E2ADE0F7289AEC0F4B20AF6274B28F02F8D90C64721 Tests/Runtime.Tests.ps1
C432B66C1111C49CEC50613A8E59972E3A49C35D0D0E15595915B378E1F2AE1E assets/css/style.scss
C92B63FE51F8793EECE9953ECD496046F6180F740D50E60C36628ECACF09EF0C Tests/Validation.Tests.ps1
CD206D807913077F8D0786FB344CC37758AE3080922EAA7AEFF0B78ABAB0665C .github/ISSUE_TEMPLATE/feature_request.yml
Expand All @@ -57,7 +58,6 @@ D53A73DF9FAEC678D2471E63C070672BE9A6EAC355B451DF9BF3776802A47446 assets/task-se
DF3A074261544800B739DEE93B071DE5383EFE796B874D7673AD69A5548F7A4A .github/FUNDING.yml
E204B2838AA20F8FEBDF74129FDC504C69809CF7044D03E90866E36BAD023DA6 SECURITY.md
E49B0BAD89C4CAF2A07BB3FA625FF431977115A81A39B455061E96534BE291A0 .github/dependabot.yml
ED325EAC9FDC9E81E30D660A7F94659C0D0D6993193E1287D1C273395E1CE8D0 docs/release-process.md
EE0B804F022C45EAC607A57181B672537C569787448D8C4BB31222CB50F7D43D Tests/Documentation.Tests.ps1
FB8E54D166ABBAE9FE74FBC83C3CEC617C245EE5330E9E09724DEE35D7C0C313 docs/troubleshooting.md
FBAF37306C261D6213F85AAE6A8B26233906E6BC48F345F9BC546D89538D226A docs/deployment.md
115 changes: 80 additions & 35 deletions Scripts/Copy-OSDLogToFileShare.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ function Get-SafeErrorMessage {
'Per-connection SMB controls are unavailable. An explicit AllowUnverifiedSmb decision is required.',
'Per-connection NTLM blocking is unavailable. An explicit AllowNtlmV2 decision with an existing NTLMv2-only client policy is required.',
'AllowNtlmV2 requires an existing LmCompatibilityLevel of 3 through 5. No policy was changed.',
'An SMB mapping already exists for the destination. It will not be reused or removed.'
'An SMB mapping already exists for the destination. It will not be reused or removed.',
'SMB connection cleanup failed after verified upload. Pending local archive retained.'
)
if ($Exception.Message -cin $KnownMessages) {
return $Exception.Message
Expand Down Expand Up @@ -407,6 +408,26 @@ function Add-LogSource {
})
}

function Get-LogSourceResult {
param(
[Parameter(Mandatory = $true)]
$Source,

[Parameter(Mandatory = $true)]
[string]$Status,

[AllowEmptyString()]
[string]$Message = ''
)

return [pscustomobject]@{
Name = $Source.Name
Source = $Source.Path
Status = $Status
Message = $Message
}
}

function Copy-LogSource {
param(
[Parameter(Mandatory = $true)]
Expand All @@ -424,22 +445,12 @@ function Copy-LogSource {

try {
if ([string]::IsNullOrWhiteSpace($Source.Path)) {
[void]$ManifestItems.Add([pscustomobject]@{
Name = $Source.Name
Source = $Source.Path
Status = 'NotFound'
Message = 'Source path is empty.'
})
[void]$ManifestItems.Add((Get-LogSourceResult -Source $Source -Status 'NotFound' -Message 'Source path is empty.'))
return
}

if (-not (Test-Path -LiteralPath $Source.Path)) {
[void]$ManifestItems.Add([pscustomobject]@{
Name = $Source.Name
Source = $Source.Path
Status = 'NotFound'
Message = ''
})
[void]$ManifestItems.Add((Get-LogSourceResult -Source $Source -Status 'NotFound'))
return
}

Expand All @@ -461,21 +472,11 @@ function Copy-LogSource {
Copy-Item -LiteralPath $Source.Path -Destination $Destination -Force -ErrorAction Stop
}

[void]$ManifestItems.Add([pscustomobject]@{
Name = $Source.Name
Source = $Source.Path
Status = 'Collected'
Message = ''
})
[void]$ManifestItems.Add((Get-LogSourceResult -Source $Source -Status 'Collected'))
}
catch {
$SafeError = Get-SafeErrorMessage -ErrorRecord $_
[void]$ManifestItems.Add([pscustomobject]@{
Name = $Source.Name
Source = $Source.Path
Status = 'Error'
Message = $SafeError
})
[void]$ManifestItems.Add((Get-LogSourceResult -Source $Source -Status 'Error' -Message $SafeError))
Write-Log -Level 'WARN' -Message "Source collection failed: $($Source.Path); $SafeError"
}
}
Expand Down Expand Up @@ -696,6 +697,9 @@ function Send-Archive {
$DriveName = 'OSDLOG' + ([guid]::NewGuid().ToString('N').Substring(0, 8))
$Mapped = $false
$DriveCreated = $false
$RemoteArchive = $null
$TransferError = $null
$CleanupFailures = New-Object System.Collections.ArrayList

try {
if (-not $AllowUnverifiedSmb -and $null -eq (Get-Command Get-SmbConnection -ErrorAction SilentlyContinue)) {
Expand Down Expand Up @@ -731,24 +735,55 @@ function Send-Archive {
throw "Remote archive size mismatch. Local=$LocalLength Remote=$RemoteLength"
}

return $RemoteArchive
}
catch {
$TransferError = $_
}
finally {
if ($null -ne $MappingOptions) {
$MappingOptions.Clear()
try {
if ($Mapped) {
Remove-SmbMapping -RemotePath $PathInfo.ShareRoot -Force -ErrorAction Stop
}
}
catch {
[void]$CleanupFailures.Add('SMB mapping')
Write-Log -Level 'ERROR' -Message "SMB mapping cleanup failed: $(Get-SafeErrorMessage -ErrorRecord $_)"
}
try {
if ($DriveCreated) {
Remove-PSDrive -Name $DriveName -Force -ErrorAction Stop
}
}
if ($Mapped) {
Remove-SmbMapping -RemotePath $PathInfo.ShareRoot -Force -ErrorAction Stop
catch {
[void]$CleanupFailures.Add('PSDrive')
Write-Log -Level 'ERROR' -Message "PSDrive cleanup failed: $(Get-SafeErrorMessage -ErrorRecord $_)"
}
if ($DriveCreated) {
Remove-PSDrive -Name $DriveName -Force -ErrorAction Stop
try {
if ($null -ne $MappingOptions) {
$MappingOptions.Clear()
}
}
catch {
[void]$CleanupFailures.Add('mapping options')
Write-Log -Level 'ERROR' -Message "SMB mapping option cleanup failed: $(Get-SafeErrorMessage -ErrorRecord $_)"
}
}

if ($null -ne $TransferError) {
throw $TransferError
}

return [pscustomobject]@{
RemoteArchive = $RemoteArchive
CleanupSucceeded = ($CleanupFailures.Count -eq 0)
CleanupFailures = @($CleanupFailures)
}
}

$ExitCode = 1
$StagingRoot = $null
$ArchivePath = $null
$UploadVerifiedWithCleanupFailure = $false

try {
Add-Type -AssemblyName System.IO.Compression.FileSystem
Expand Down Expand Up @@ -855,9 +890,13 @@ try {
for ($Attempt = 1; $Attempt -le $RetryCount; $Attempt++) {
try {
Write-Log -Message "Upload attempt $Attempt of $RetryCount."
$RemoteArchive = Send-Archive -ArchivePath $ArchivePath -DestinationShare $DestinationShare -Credential $script:Credential -TimeoutSeconds $TimeoutSeconds
Write-Log -Message "Upload verified: $RemoteArchive"
$UploadResult = Send-Archive -ArchivePath $ArchivePath -DestinationShare $DestinationShare -Credential $script:Credential -TimeoutSeconds $TimeoutSeconds
Write-Log -Message "Upload verified: $($UploadResult.RemoteArchive)"
$Uploaded = $true
if (-not $UploadResult.CleanupSucceeded) {
$UploadVerifiedWithCleanupFailure = $true
Write-Log -Level 'ERROR' -Message "Upload was verified, but SMB connection cleanup failed: $($UploadResult.CleanupFailures -join ', ')."
}
break
}
catch {
Expand All @@ -871,6 +910,9 @@ try {
if (-not $Uploaded) {
throw "Upload failed after $RetryCount attempt(s). Pending local archive retained: $ArchivePath"
}
if ($UploadVerifiedWithCleanupFailure) {
throw 'SMB connection cleanup failed after verified upload. Pending local archive retained.'
}

Remove-Item -LiteralPath $StagingRoot -Recurse -Force -ErrorAction Stop
Remove-Item -LiteralPath $ArchivePath -Force -ErrorAction Stop
Expand All @@ -885,7 +927,10 @@ finally {
$script:Credential = $null
}

if ($ExitCode -eq 0) {
if ($UploadVerifiedWithCleanupFailure) {
Write-Output 'OSD log archive uploaded and verified, but SMB connection cleanup failed. See CopyOSDLogs.log.'
}
elseif ($ExitCode -eq 0) {
Write-Output 'OSD log archive uploaded and verified successfully.'
}
else {
Expand Down
Loading
Loading