ContainerHandling/Flush-ContainerHelperCache.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<#
 .Synopsis
  Flush Caches used in ContainerHelper
 .Description
  Extract all files from a Container Image necessary to start a generic container with these files
 .Parameter cache
  Specify which cache you want to flush (default is all)
  - calSourceCache is the C/AL Source Cache
  - alSourceCache is the AL Source Cache
  - filesCache is the files extracted from other images
  - applicationCache are the test applications runtime cache (15.x containers)
  - bakFolderCache are version specific backup sets
 .Example
  Flush-ContainerHelperCache -cache calSourceCache
#>

function Flush-ContainerHelperCache {
    [CmdletBinding()]
    Param (
        [ValidateSet('all','calSourceCache','alSourceCache','applicationCache','bakFolderCache','filesCache')]
        [string] $cache = 'all'
    )

    $folders = @()
    if ($cache -eq 'all' -or $cache -eq 'calSourceCache') {
        $folders += @("extensions\original-*-??","extensions\original-*-??-newsyntax")
    }

    if ($cache -eq 'all' -or $cache -eq 'filesCache') {
        $folders += @("*-??-files")
    }

    if ($cache -eq 'all' -or $cache -eq 'alSourceCache') {
        $folders += @("extensions\original-*-??-al")
    }

    if ($cache -eq 'all' -or $cache -eq 'applicationCache') {
        $folders += @("extensions\applications-*-??","sandbox-applications-*-??","onprem-applications-*-??")
    }

    if ($cache -eq 'all' -or $cache -eq 'bakFolderCache') {
        $folders += @("sandbox-*-bakfolders","onprem-*-bakfolders")
    }

    $folders | ForEach-Object {
        $folder = Join-Path $hostHelperFolder $_
        Get-Item $folder | ?{ $_.PSIsContainer } | ForEach-Object {
            Write-Host "Removing Cache $($_.FullName)"
            Remove-Item -Path $_.FullName -Recurse -Force
        }
    }
}
Export-ModuleMember -Function Flush-ContainerHelperCache