瀏覽代碼

better disposal around using

Luke Pulverenti 12 年之前
父節點
當前提交
196f3eb574
共有 1 個文件被更改,包括 9 次插入9 次删除
  1. 9 9
      MediaBrowser.Server.Implementations/Providers/ProviderManager.cs

+ 9 - 9
MediaBrowser.Server.Implementations/Providers/ProviderManager.cs

@@ -468,17 +468,17 @@ namespace MediaBrowser.Server.Implementations.Providers
 
 
             try
             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);
                         await dataToSave.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false);
                     }
                     }