Explorar o código

better stream disposal

Luke Pulverenti %!s(int64=12) %!d(string=hai) anos
pai
achega
887c280a1b

+ 4 - 5
MediaBrowser.Server.Implementations/Providers/ProviderManager.cs

@@ -427,17 +427,16 @@ namespace MediaBrowser.Server.Implementations.Providers
             //Tell the watchers to ignore
             //Tell the watchers to ignore
             _directoryWatchers.TemporarilyIgnore(path);
             _directoryWatchers.TemporarilyIgnore(path);
 
 
-            //Make the mod
-
             dataToSave.Position = 0;
             dataToSave.Position = 0;
 
 
             try
             try
             {
             {
                 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))
                 {
                 {
-                    await dataToSave.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false);
-
-                    dataToSave.Dispose();
+                    using (var input = dataToSave)
+                    {
+                        await input.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false);
+                    }
 
 
                     // If this is ever used for something other than metadata we can add a file type param
                     // If this is ever used for something other than metadata we can add a file type param
                     item.ResolveArgs.AddMetadataFile(path);
                     item.ResolveArgs.AddMetadataFile(path);