Modules/businessdev.ALbuild.Containers/Private/Get-BcArtifactInventory.ps1

function Get-BcArtifactInventory {
    <#
    .SYNOPSIS
        Fingerprints an extracted BC artifact folder (file count + total bytes).
 
    .DESCRIPTION
        The completion marker used to record only a timestamp, which proves "the extraction finished"
        but says nothing about whether the content is STILL there. A cache that loses a folder later -
        an interrupted copy, a half-finished manual cleanup, a disk-full event, a stray delete - keeps
        its marker and is silently reused. That is exactly how a container ended up without
        C:\Applications.<country>, fell back to the source packages and failed to compile them.
 
        Counting files and summing their sizes catches every one of those: a missing folder changes the
        count, a truncated file changes the total. It is deliberately NOT a hash - an artifact is
        multi-GB and hashing it on every container start would cost more than the download it protects.
 
        'lastused' is excluded: the BC container image rewrites it on every use, so including it would
        make an untouched cache look changed. The marker file itself is excluded for the same reason.
 
    .PARAMETER Path
        The extracted artifact folder (e.g. <cache>\sandbox\<version>\de).
 
    .OUTPUTS
        PSCustomObject: Files (int), Bytes (long).
    #>

    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $Path
    )

    $files = 0
    $bytes = [long] 0
    foreach ($item in (Get-ChildItem -LiteralPath $Path -Recurse -File -Force -ErrorAction SilentlyContinue)) {
        if ($item.Name -eq 'lastused' -or $item.Name -eq '.albuild-complete') { continue }
        $files++
        $bytes += $item.Length
    }
    return [PSCustomObject]@{ Files = $files; Bytes = $bytes }
}