From 386fa86f91ddbb9bb3a33adfe9904c62e646ebdf Mon Sep 17 00:00:00 2001 From: Sven Pfleiderer Date: Fri, 21 Jan 2022 16:56:35 -0800 Subject: [PATCH] Try to simplify cleaning up file references --- src/Runner.Worker/StepsRunner.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Runner.Worker/StepsRunner.cs b/src/Runner.Worker/StepsRunner.cs index 3bce4b0ce..55577ab7e 100644 --- a/src/Runner.Worker/StepsRunner.cs +++ b/src/Runner.Worker/StepsRunner.cs @@ -359,8 +359,9 @@ namespace GitHub.Runner.Worker var stepSummaryFilePath = executionContext.GetGitHubContext("step_summary"); Trace.Info($"Reading step summary data from {stepSummaryFilePath}"); + Trace.Info($"File exists: {stepSummaryFilePath} {File.Exists(stepSummaryFilePath)}"); - var fileStream = new FileStream(stepSummaryFilePath, FileMode.Open, FileAccess.Read, FileShare.Read); + using (var fileStream = new FileStream(stepSummaryFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var sr = new StreamReader(fileStream)) { Trace.Info($"Step summary data: {sr.ReadToEnd()}"); @@ -375,9 +376,9 @@ namespace GitHub.Runner.Worker Directory.CreateDirectory(stepSummaryDirectory); var stepSummaryFilePath = Path.Combine(stepSummaryDirectory, $"{Guid.NewGuid().ToString()}.md"); - Trace.Info($"Using step summary file '{stepSummaryFilePath}'"); - var fileStream = File.Create(stepSummaryFilePath); - fileStream.Close(); + using (File.Create(stepSummaryFilePath)) { + Trace.Info($"Using step summary file '{stepSummaryFilePath}'"); + } return stepSummaryFilePath; }