Skip to content

Commit 9e1dbb8

Browse files
authored
Ensure temp files are non-shareable and delete on close (#1677)
Fixes #1658
1 parent c5fcbb0 commit 9e1dbb8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/DocumentFormat.OpenXml.Framework/Packaging/WriteableStreamExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,21 @@ public static bool EnableWriteableStream(this IFeatureCollection features)
3535

3636
private sealed class TemporaryFile : IDisposable
3737
{
38+
private const int DefaultBufferSize = 4096;
39+
3840
private readonly string _path;
3941

4042
public TemporaryFile()
4143
{
4244
_path = Path.GetTempFileName();
43-
Stream = File.Create(_path);
45+
Stream = new FileStream(_path, FileMode.Create, FileAccess.ReadWrite, FileShare.None, DefaultBufferSize, FileOptions.DeleteOnClose);
4446
}
4547

4648
public Stream Stream { get; }
4749

4850
public void Dispose()
4951
{
5052
Stream.Dispose();
51-
File.Delete(_path);
5253
}
5354
}
5455
}

0 commit comments

Comments
 (0)