diff options
| author | crobibero <cody@robibe.ro> | 2020-08-18 20:20:32 -0600 |
|---|---|---|
| committer | crobibero <cody@robibe.ro> | 2020-08-18 20:20:32 -0600 |
| commit | b43a8fb9d35846f458212d0ad17f3d52c896ef6e (patch) | |
| tree | 339a40a3e2f2ee73a0ed73cef66fd4bc7c553fb9 /Emby.Server.Implementations/AppBase/ConfigurationHelper.cs | |
| parent | 2b5d515de79f2309219459c7223b8a56269737f8 (diff) | |
| parent | 93fe595e5e9863874c1973e4f2d7f3c85549d3f9 (diff) | |
Merge remote-tracking branch 'upstream/master' into package-install-repo
Diffstat (limited to 'Emby.Server.Implementations/AppBase/ConfigurationHelper.cs')
| -rw-r--r-- | Emby.Server.Implementations/AppBase/ConfigurationHelper.cs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Emby.Server.Implementations/AppBase/ConfigurationHelper.cs b/Emby.Server.Implementations/AppBase/ConfigurationHelper.cs index 0b681fddf..4c9ab33a7 100644 --- a/Emby.Server.Implementations/AppBase/ConfigurationHelper.cs +++ b/Emby.Server.Implementations/AppBase/ConfigurationHelper.cs @@ -1,3 +1,5 @@ +#nullable enable + using System; using System.IO; using System.Linq; @@ -22,7 +24,7 @@ namespace Emby.Server.Implementations.AppBase { object configuration; - byte[] buffer = null; + byte[]? buffer = null; // Use try/catch to avoid the extra file system lookup using File.Exists try @@ -36,19 +38,23 @@ namespace Emby.Server.Implementations.AppBase configuration = Activator.CreateInstance(type); } - using var stream = new MemoryStream(); + using var stream = new MemoryStream(buffer?.Length ?? 0); xmlSerializer.SerializeToStream(configuration, stream); // Take the object we just got and serialize it back to bytes - var newBytes = stream.ToArray(); + byte[] newBytes = stream.GetBuffer(); + int newBytesLen = (int)stream.Length; // If the file didn't exist before, or if something has changed, re-save - if (buffer == null || !buffer.SequenceEqual(newBytes)) + if (buffer == null || !newBytes.AsSpan(0, newBytesLen).SequenceEqual(buffer)) { Directory.CreateDirectory(Path.GetDirectoryName(path)); // Save it after load in case we got new items - File.WriteAllBytes(path, newBytes); + using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read)) + { + fs.Write(newBytes, 0, newBytesLen); + } } return configuration; |
