Skip to content
Open
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
10 changes: 5 additions & 5 deletions .github/workflows/cxx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ jobs:
arch: amd64_arm64

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Clone test repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: walbourn/directxmathtest
path: Tests
Expand All @@ -87,7 +87,7 @@ jobs:

- name: 'Clean up'
working-directory: ${{ github.workspace }}
run: Remove-Item -Path out -Recurse -Force
run: .\build\PurgeFolder.ps1 -Path out

- name: 'Configure CMake (C++11)'
working-directory: ${{ github.workspace }}
Expand All @@ -99,7 +99,7 @@ jobs:

- name: 'Clean up'
working-directory: ${{ github.workspace }}
run: Remove-Item -Path out -Recurse -Force
run: .\build\PurgeFolder.ps1 -Path out

- name: 'Configure CMake (C++14)'
working-directory: ${{ github.workspace }}
Expand All @@ -111,7 +111,7 @@ jobs:

- name: 'Clean up'
working-directory: ${{ github.workspace }}
run: Remove-Item -Path out -Recurse -Force
run: .\build\PurgeFolder.ps1 -Path out

- name: 'Configure CMake (C++20)'
working-directory: ${{ github.workspace }}
Expand Down
59 changes: 59 additions & 0 deletions build/PurgeFolder.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<#
.SYNOPSIS
Purges a folder once it is no longer locked.

.DESCRIPTION
Continuously attempts to remove the specified folder. If the folder
is locked or in use, the script waits for a configurable interval and
retries until either the folder is removed or a timeout is reached.

.PARAMETER Path
The folder to remove.

.PARAMETER RetrySeconds
Number of seconds to wait between retry attempts.

.PARAMETER TimeoutSeconds
Maximum number of seconds to wait before giving up.

.EXAMPLE
.\PurgeFolder.ps1 -Path "C:\Temp\MyFolder" -Verbose
#>

[CmdletBinding()]
param(
[Parameter(Mandatory = $true, Position = 0)]
[ValidateNotNullOrEmpty()]
[string]$Path,

[Parameter()]
[ValidateRange(1, 86400)]
[int]$RetrySeconds = 5,

[Parameter()]
[ValidateRange(1, 86400)]
[int]$TimeoutSeconds = 300
)

if (-not (Test-Path -LiteralPath $Path -PathType Container)) {
throw "'$Path' does not exist or is not a folder."
}

$stopTime = (Get-Date).AddSeconds($TimeoutSeconds)

while (Test-Path -LiteralPath $Path -PathType Container) {

if ((Get-Date) -gt $stopTime) {
throw "Timed out waiting for folder '$Path' to become available after $TimeoutSeconds seconds."
}

try {
Remove-Item -LiteralPath $Path -Recurse -Force -ErrorAction Stop

Write-Verbose "Successfully purged folder '$Path'."
}
catch {
Write-Verbose "Folder is locked or in use. Retrying in $RetrySeconds second(s)..."
Start-Sleep -Seconds $RetrySeconds
}
}
Loading