pubg/includes/ps1/lockfile.ps1
Thijs Stobbelaar bc678c2123 longer timeout
2023-11-15 13:15:57 +01:00

46 lines
No EOL
1.1 KiB
PowerShell

function new-lock {
[CmdletBinding()]
param (
[Parameter()]
[string]
$by
)
Write-Output 'Setting lock'
$lock = $true
$timeout = 15
$i = 0
while ($lock) {
if ($env:temp) {
$lockFile = Join-Path -Path $env:temp -ChildPath 'lockfile_pubg.lock'
}
else {
$lockFile = "/tmp/lockfile_pubg.lock"
}
if (Test-Path -Path $lockFile) {
Write-Host "Job is already running. Sleeping 10 seconds"
Start-Sleep -Seconds 10
}else{
$lock = $false
}
if($i -ge $timeout){
Write-Output "Timed out"
exit
}
$i++
}
New-Item -ItemType File -Path $lockFile | Out-Null
if ($by) {
$by | Out-File -FilePath $lockFile -Append
}
}
function remove-lock {
Write-Output 'Removing lock'
if ($env:temp) {
$lockFile = Join-Path -Path $env:temp -ChildPath 'lockfile_pubg.lock'
}
else {
$lockFile = "/tmp/lockfile_pubg.lock"
}
Remove-Item -Path $lockFile
}