Skip to content

Commit

Permalink
Merge pull request #270 from steffen-wilke/master
Browse files Browse the repository at this point in the history
Make sure that the config.ps1 is not locked before accessing it from the init.ps1 script.
  • Loading branch information
KostyaSha authored Jul 18, 2019
2 parents e22e6fe + af78779 commit cf89724
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@ while (-not (Test-Path $CONFIG)) {
sleep 1
}

function Test-FileLock {
param (
[parameter(Mandatory=$true)]
[string]$Path
)

$oFile = New-Object System.IO.FileInfo $Path

try
{
$oStream = $oFile.Open([System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None)
if ($oStream)
{
$oStream.Close()
}
$false
}
catch
{
# file is locked by a process.
$true
}
}

while (Test-FileLock $CONFIG) {
Write-Output "Config file is still being created, sleeping for 1 second"
sleep 1
}

Write-Output "Found config file $CONFIG"
. "$CONFIG"

Expand Down

0 comments on commit cf89724

Please sign in to comment.