Skip to content

Commit 9fce99c

Browse files
committed
Fixing FSharpCompilationService file checks
1 parent 4a460f1 commit 9fce99c

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

src/WebJobs.Script/Description/DotNet/FSharp/FSharpCompilationService.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
using System.Text;
99
using System.Text.RegularExpressions;
1010
using System.Threading;
11+
using System.Threading.Tasks;
1112
using Microsoft.CodeAnalysis;
1213
using Microsoft.CodeAnalysis.Scripting;
1314
using Microsoft.CodeAnalysis.Scripting.Hosting;
1415
using Microsoft.FSharp.Compiler;
1516
using Microsoft.FSharp.Compiler.SimpleSourceCodeServices;
1617
using Microsoft.FSharp.Compiler.SourceCodeServices;
1718
using Microsoft.FSharp.Core;
19+
using static Microsoft.Azure.WebJobs.Script.FileUtility;
1820

1921
namespace Microsoft.Azure.WebJobs.Script.Description
2022
{
@@ -182,17 +184,25 @@ public ICompilation GetFunctionCompilation(FunctionMetadata functionMetadata)
182184
if (code == 0)
183185
{
184186
var assemblyBytes = File.ReadAllBytes(dllName);
185-
var pdbBytes = File.ReadAllBytes(pdbName);
187+
byte[] pdbBytes = null;
188+
if (File.Exists(pdbName))
189+
{
190+
pdbBytes = File.ReadAllBytes(pdbName);
191+
}
186192
var assembly = Assembly.Load(assemblyBytes, pdbBytes);
187193
assemblyOption = FSharpOption<Assembly>.Some(assembly);
188194
}
189195
}
190196
finally
191197
{
192-
File.Delete(scriptFilePath);
193-
File.Delete(dllName);
194-
File.Delete(pdbName);
198+
Task.WhenAll(DeleteIfExistsAsync(scriptFilePath), DeleteIfExistsAsync(dllName), DeleteIfExistsAsync(pdbName))
199+
.ContinueWith(t => t.Exception.Handle(e =>
200+
{
201+
// TODO: Trace
202+
return true;
203+
}), TaskContinuationOptions.OnlyOnFaulted);
195204
}
205+
196206
return new FSharpCompilation(errors, assemblyOption);
197207
}
198208

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
namespace Microsoft.Azure.WebJobs.Script
12+
{
13+
public static class FileUtility
14+
{
15+
public static Task DeleteIfExistsAsync(string path)
16+
{
17+
return Task.Run(() =>
18+
{
19+
if (File.Exists(path))
20+
{
21+
File.Delete(path);
22+
}
23+
});
24+
}
25+
}
26+
}

src/WebJobs.Script/WebJobs.Script.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@
408408
<Compile Include="EnvironmentSettingNames.cs" />
409409
<Compile Include="ExpandoObjectJsonConverter.cs" />
410410
<Compile Include="Extensions\ExceptionExtensions.cs" />
411+
<Compile Include="Extensions\FileUtility.cs" />
411412
<Compile Include="Extensions\HttpRequestMessageExtensions.cs" />
412413
<Compile Include="Extensions\IDictionaryExtensions.cs" />
413414
<Compile Include="Extensions\IMetricsLoggerExtensions.cs" />

0 commit comments

Comments
 (0)