Skip to content

Commit

Permalink
Ensure temp files are non-shareable and delete on close (#1677)
Browse files Browse the repository at this point in the history
Fixes #1658
  • Loading branch information
twsouthwick authored Feb 28, 2024
1 parent c5fcbb0 commit 9e1dbb8
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,21 @@ public static bool EnableWriteableStream(this IFeatureCollection features)

private sealed class TemporaryFile : IDisposable
{
private const int DefaultBufferSize = 4096;

private readonly string _path;

public TemporaryFile()
{
_path = Path.GetTempFileName();
Stream = File.Create(_path);
Stream = new FileStream(_path, FileMode.Create, FileAccess.ReadWrite, FileShare.None, DefaultBufferSize, FileOptions.DeleteOnClose);
}

public Stream Stream { get; }

public void Dispose()
{
Stream.Dispose();
File.Delete(_path);
}
}
}

0 comments on commit 9e1dbb8

Please sign in to comment.