This commit is contained in:
Bond_009
2021-10-03 19:52:38 +02:00
parent 9718c0b2ee
commit 9af16fcb6c
18 changed files with 77 additions and 74 deletions

View File

@@ -113,11 +113,19 @@ namespace MediaBrowser.LocalMetadata.Savers
{
var directory = Path.GetDirectoryName(path) ?? throw new ArgumentException($"Provided path ({path}) is not valid.", nameof(path));
Directory.CreateDirectory(directory);
// On Windows, savint the file will fail if the file is hidden or readonly
FileSystem.SetAttributes(path, false, false);
// use FileShare.None as this bypasses dotnet bug dotnet/runtime#42790 .
using (var filestream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
var fileStreamOptions = new FileStreamOptions()
{
Mode = FileMode.Create,
Access = FileAccess.Write,
Share = FileShare.None,
PreallocationSize = stream.Length
};
using (var filestream = new FileStream(path, fileStreamOptions))
{
stream.CopyTo(filestream);
}