From 196f3eb574d6a5275eb99450ddca06e6837c68dc Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 10 May 2013 13:51:10 -0400 Subject: [PATCH] better disposal around using --- .../Providers/ProviderManager.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Providers/ProviderManager.cs b/MediaBrowser.Server.Implementations/Providers/ProviderManager.cs index 840e8265dc..5dfa31b09e 100644 --- a/MediaBrowser.Server.Implementations/Providers/ProviderManager.cs +++ b/MediaBrowser.Server.Implementations/Providers/ProviderManager.cs @@ -468,17 +468,17 @@ namespace MediaBrowser.Server.Implementations.Providers try { - // If the file already exists but is hidden, the below save will throw an UnauthorizedAccessException - var existingFileInfo = new FileInfo(path); - - if (existingFileInfo.Exists && existingFileInfo.Attributes.HasFlag(FileAttributes.Hidden)) + using (dataToSave) { - existingFileInfo.Delete(); - } + // If the file already exists but is hidden, the below save will throw an UnauthorizedAccessException + var existingFileInfo = new FileInfo(path); - using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous)) - { - using (dataToSave) + if (existingFileInfo.Exists && existingFileInfo.Attributes.HasFlag(FileAttributes.Hidden)) + { + existingFileInfo.Delete(); + } + + using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous)) { await dataToSave.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false); }