improve stream disposal
This commit is contained in:
parent
156453cc42
commit
baa779fb31
|
@ -410,11 +410,13 @@ namespace MediaBrowser.Server.Implementations.IO
|
|||
return false;
|
||||
}
|
||||
|
||||
FileStream stream = null;
|
||||
|
||||
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
|
||||
{
|
||||
|
@ -424,14 +426,6 @@ namespace MediaBrowser.Server.Implementations.IO
|
|||
//or does not exist (has already been processed)
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (stream != null)
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
//file is not locked
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -457,9 +457,9 @@ namespace MediaBrowser.Server.Implementations.Providers
|
|||
{
|
||||
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;
|
||||
|
@ -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 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