mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-07 06:17:14 -04:00
improve stream disposal
This commit is contained in:
parent
156453cc42
commit
baa779fb31
@ -410,11 +410,13 @@ namespace MediaBrowser.Server.Implementations.IO
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileStream stream = null;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
stream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
|
using (new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
|
||||||
|
{
|
||||||
|
//file is not locked
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@ -424,14 +426,6 @@ namespace MediaBrowser.Server.Implementations.IO
|
|||||||
//or does not exist (has already been processed)
|
//or does not exist (has already been processed)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (stream != null)
|
|
||||||
stream.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
//file is not locked
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -457,9 +457,9 @@ namespace MediaBrowser.Server.Implementations.Providers
|
|||||||
{
|
{
|
||||||
var ms = new MemoryStream();
|
var ms = new MemoryStream();
|
||||||
|
|
||||||
using (var input = dataToSave)
|
using (dataToSave)
|
||||||
{
|
{
|
||||||
await input.CopyToAsync(ms).ConfigureAwait(false);
|
await dataToSave.CopyToAsync(ms).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ms.Position = 0;
|
ms.Position = 0;
|
||||||
@ -470,9 +470,9 @@ namespace MediaBrowser.Server.Implementations.Providers
|
|||||||
{
|
{
|
||||||
using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous))
|
using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous))
|
||||||
{
|
{
|
||||||
using (var input = dataToSave)
|
using (dataToSave)
|
||||||
{
|
{
|
||||||
await input.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false);
|
await dataToSave.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user