Modules/businessdev.ALbuild.Containers/Private/Get-BcArtifactLastUse.ps1
|
function Get-BcArtifactLastUse { <# .SYNOPSIS Reads when a cached artifact version was last handed to a build. .DESCRIPTION Returns the timestamp written by Set-BcArtifactLastUse, or $null when there is none (a version cached before this existed, or one nothing has used since). $null means "no evidence of use" and the caller decides - the prune treats it as prunable, because an unstamped version has not been handed out by any build running this module version. .PARAMETER VersionFolder The <root>\<type>\<version> folder to read. .OUTPUTS System.DateTime, or $null. #> [CmdletBinding()] [OutputType([datetime])] param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $VersionFolder ) $marker = Join-Path -Path $VersionFolder -ChildPath '.albuild-lastuse' if (-not (Test-Path -LiteralPath $marker)) { return $null } try { $raw = (Get-Content -LiteralPath $marker -Raw -ErrorAction Stop).Trim() $parsed = [datetime]::MinValue if ([datetime]::TryParse($raw, [ref] $parsed)) { return $parsed } # Unreadable content still proves someone wrote it - fall back to the file's own timestamp. return (Get-Item -LiteralPath $marker -ErrorAction Stop).LastWriteTime } catch { return $null } } |