Skip to content

Commit 271f420

Browse files
committed
making project compile
1 parent 2691326 commit 271f420

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
namespace Azure.Functions.Cli.Helpers
5+
{
6+
public static class FileLockHelper
7+
{
8+
private const string DefaultLockFileName = "func.lock";
9+
private static readonly string _templatesLockFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".azurefunctions");
10+
11+
public static async Task<T> WithFileLockAsync<T>(string lockFileName, Func<Task<T>> action)
12+
{
13+
lockFileName ??= DefaultLockFileName;
14+
var lockFile = Path.Combine(_templatesLockFilePath, lockFileName);
15+
16+
for (int attempt = 0; attempt < 20; attempt++)
17+
{
18+
FileStream stream = null;
19+
try
20+
{
21+
stream = new FileStream(
22+
lockFile,
23+
FileMode.OpenOrCreate,
24+
FileAccess.ReadWrite,
25+
FileShare.Delete);
26+
27+
return await action();
28+
}
29+
catch (IOException)
30+
{
31+
stream?.Dispose();
32+
await Task.Delay(1000);
33+
}
34+
finally
35+
{
36+
stream?.Dispose();
37+
}
38+
}
39+
40+
throw new IOException($"Could not acquire file lock on {lockFile} after multiple attempts.");
41+
}
42+
43+
public static Task WithFileLockAsync(string lockFileName, Func<Task> action)
44+
{
45+
return WithFileLockAsync(lockFileName, async () =>
46+
{
47+
await action();
48+
return true;
49+
});
50+
}
51+
}
52+
}

test/TestFunctionApps/TestCustomHandlerProject/TurnThisExecutable

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)