diff options
| author | Bond-009 <bond.009@outlook.com> | 2025-05-04 16:40:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-04 08:40:34 -0600 |
| commit | 0c3ba30de214eddcd6118c3b695b08e5482bf7ed (patch) | |
| tree | a862a90f6c78cd61f78e5af7b75611a37f527ccf /src | |
| parent | 4096c973c623a72525843d5fe278d1f36fbbc58a (diff) | |
Cleanup file related code (#14023)
Diffstat (limited to 'src')
| -rw-r--r-- | src/Jellyfin.Extensions/FileHelper.cs | 20 | ||||
| -rw-r--r-- | src/Jellyfin.LiveTv/Channels/ChannelManager.cs | 4 |
2 files changed, 22 insertions, 2 deletions
diff --git a/src/Jellyfin.Extensions/FileHelper.cs b/src/Jellyfin.Extensions/FileHelper.cs new file mode 100644 index 000000000..b1ccf8d47 --- /dev/null +++ b/src/Jellyfin.Extensions/FileHelper.cs @@ -0,0 +1,20 @@ +using System.IO; + +namespace Jellyfin.Extensions; + +/// <summary> +/// Provides helper functions for <see cref="File" />. +/// </summary> +public static class FileHelper +{ + /// <summary> + /// Creates, or truncates a file in the specified path. + /// </summary> + /// <param name="path">The path and name of the file to create.</param> + public static void CreateEmpty(string path) + { + using (File.OpenHandle(path, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) + { + } + } +} diff --git a/src/Jellyfin.LiveTv/Channels/ChannelManager.cs b/src/Jellyfin.LiveTv/Channels/ChannelManager.cs index 0ca294a28..5addcd26e 100644 --- a/src/Jellyfin.LiveTv/Channels/ChannelManager.cs +++ b/src/Jellyfin.LiveTv/Channels/ChannelManager.cs @@ -363,7 +363,7 @@ namespace Jellyfin.LiveTv.Channels Directory.CreateDirectory(Path.GetDirectoryName(path)); - FileStream createStream = File.Create(path); + FileStream createStream = AsyncFile.Create(path); await using (createStream.ConfigureAwait(false)) { await JsonSerializer.SerializeAsync(createStream, mediaSources, _jsonOptions).ConfigureAwait(false); @@ -866,7 +866,7 @@ namespace Jellyfin.LiveTv.Channels { Directory.CreateDirectory(Path.GetDirectoryName(path)); - var createStream = File.Create(path); + var createStream = AsyncFile.Create(path); await using (createStream.ConfigureAwait(false)) { await JsonSerializer.SerializeAsync(createStream, result, _jsonOptions).ConfigureAwait(false); |
