Skip to content

Commit

Permalink
Ensure file streams are closed after use
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDesmond-ca committed Dec 2, 2022
1 parent db9f949 commit 03a56e7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/LibYear.Core/LibYear.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>7.0.0</Version>
<Version>7.0.1</Version>
<TargetFramework>net6.0</TargetFramework>
<Product>libyear</Product>
<PackageId>LibYear.Core</PackageId>
Expand Down
4 changes: 4 additions & 0 deletions src/LibYear.Core/ProjectFileManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO.Abstractions;
using System.Text;
using LibYear.Core.FileTypes;

namespace LibYear.Core;
Expand Down Expand Up @@ -61,6 +62,8 @@ private async Task<IProjectFile> ReadFile(IFileSystemInfo fileInfo)
var path = fileInfo.FullName;
var stream = _fileSystem.FileStream.New(path, FileMode.Open, FileAccess.Read, FileShare.Read);
var contents = await new StreamReader(stream).ReadToEndAsync();
stream.Close();

if (IsCsProjFile(fileInfo))
return new CsProjFile(path, contents);
if (IsDirectoryBuildPropsFile(fileInfo))
Expand All @@ -82,6 +85,7 @@ public async Task<IReadOnlyCollection<string>> Update(SolutionResult result)

var stream = _fileSystem.FileStream.New(project.ProjectFile.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
await new StreamWriter(stream).WriteAsync(update);
stream.Close();
updated.Add(project.ProjectFile.FileName);
}

Expand Down
2 changes: 1 addition & 1 deletion src/LibYear/LibYear.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>7.0.0</Version>
<Version>7.0.1</Version>
<OutputType>Exe</OutputType>
<PackAsTool>true</PackAsTool>
<Product>libyear</Product>
Expand Down

0 comments on commit 03a56e7

Please sign in to comment.