Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;NU1608;NU1109</NoWarn>
<Version>28.0.1</Version>
<Version>28.0.2</Version>
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>Markdown, Snippets, mdsnippets, documentation, MarkdownSnippets</PackageTags>
Expand All @@ -16,4 +16,4 @@
<ItemGroup>
<Using Include="System.ReadOnlySpan&lt;System.Char&gt;" Alias="CharSpan" />
</ItemGroup>
</Project>
</Project>
3 changes: 2 additions & 1 deletion src/MarkdownSnippets/Reading/FileSnippetExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public static IEnumerable<Snippet> Read(string path, int maxWidth = int.MaxValue
return [];
}

using var reader = File.OpenText(path);
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using var reader = new StreamReader(stream);
return Read(reader, path, maxWidth, newLine).ToList();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
Key: CodeKey,
Language: cs,
Value: The Code,
Error: ,
FileLocation: LockedFile.cs(1-3),
IsInError: false
}
]
23 changes: 23 additions & 0 deletions src/Tests/SnippetExtractor/SnippetExtractorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ await Verify(snippets)
}
}

[Fact]
public Task CanReadFileWhileLockedByAnotherProcess()
{
var temp = Path.Combine(Path.GetTempPath(), "LockedSnippetFile.cs");
try
{
File.WriteAllText(temp,
"""
#region CodeKey
The Code
#endregion
""");
using var lockingStream = new FileStream(temp, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
var snippets = FileSnippetExtractor.Read(temp);
return Verify(snippets)
.AddScrubber(_ => _.Replace(temp, "LockedFile.cs"));
}
finally
{
File.Delete(temp);
}
}

[Fact]
public Task CanExtractWithInnerWhiteSpace()
{
Expand Down
Loading