work around sequential schedule validation limit (#2655)
* remove readalltext * remove unused method * remove fileexists * remove folderexists * remove readalllines * remove fake local file system * show playlist name in playout build errors * add basic sequential schedule validator tests * work around sequential schedule validation limit
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO.Abstractions;
|
||||
using System.Security.Cryptography;
|
||||
using Bugsnag;
|
||||
using ErsatzTV.Core.Domain;
|
||||
using ErsatzTV.Core.Interfaces.Metadata;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ErsatzTV.Core.Metadata;
|
||||
|
||||
public class LocalFileSystem(IClient client, ILogger<LocalFileSystem> logger) : ILocalFileSystem
|
||||
public class LocalFileSystem(IFileSystem fileSystem, IClient client, ILogger<LocalFileSystem> logger) : ILocalFileSystem
|
||||
{
|
||||
public Unit EnsureFolderExists(string folder)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (folder != null && !Directory.Exists(folder))
|
||||
if (folder != null && !fileSystem.Directory.Exists(folder))
|
||||
{
|
||||
Directory.CreateDirectory(folder);
|
||||
fileSystem.Directory.CreateDirectory(folder);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -30,7 +30,7 @@ public class LocalFileSystem(IClient client, ILogger<LocalFileSystem> logger) :
|
||||
{
|
||||
try
|
||||
{
|
||||
return File.GetLastWriteTimeUtc(path);
|
||||
return fileSystem.File.GetLastWriteTimeUtc(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -38,16 +38,13 @@ public class LocalFileSystem(IClient client, ILogger<LocalFileSystem> logger) :
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsLibraryPathAccessible(LibraryPath libraryPath) =>
|
||||
Directory.Exists(libraryPath.Path);
|
||||
|
||||
public IEnumerable<string> ListSubdirectories(string folder)
|
||||
{
|
||||
if (Directory.Exists(folder))
|
||||
if (fileSystem.Directory.Exists(folder))
|
||||
{
|
||||
try
|
||||
{
|
||||
return Directory.EnumerateDirectories(folder);
|
||||
return fileSystem.Directory.EnumerateDirectories(folder);
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
@@ -65,11 +62,11 @@ public class LocalFileSystem(IClient client, ILogger<LocalFileSystem> logger) :
|
||||
|
||||
public IEnumerable<string> ListFiles(string folder)
|
||||
{
|
||||
if (Directory.Exists(folder))
|
||||
if (fileSystem.Directory.Exists(folder))
|
||||
{
|
||||
try
|
||||
{
|
||||
return Directory.EnumerateFiles(folder, "*", SearchOption.TopDirectoryOnly)
|
||||
return fileSystem.Directory.EnumerateFiles(folder, "*", SearchOption.TopDirectoryOnly)
|
||||
.Where(path => !Path.GetFileName(path).StartsWith("._", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
@@ -88,11 +85,11 @@ public class LocalFileSystem(IClient client, ILogger<LocalFileSystem> logger) :
|
||||
|
||||
public IEnumerable<string> ListFiles(string folder, string searchPattern)
|
||||
{
|
||||
if (folder is not null && Directory.Exists(folder))
|
||||
if (folder is not null && fileSystem.Directory.Exists(folder))
|
||||
{
|
||||
try
|
||||
{
|
||||
return Directory.EnumerateFiles(folder, searchPattern, SearchOption.TopDirectoryOnly)
|
||||
return fileSystem.Directory.EnumerateFiles(folder, searchPattern, SearchOption.TopDirectoryOnly)
|
||||
.Where(path => !Path.GetFileName(path).StartsWith("._", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
@@ -111,14 +108,15 @@ public class LocalFileSystem(IClient client, ILogger<LocalFileSystem> logger) :
|
||||
|
||||
public IEnumerable<string> ListFiles(string folder, params string[] searchPatterns)
|
||||
{
|
||||
if (folder is not null && Directory.Exists(folder))
|
||||
if (folder is not null && fileSystem.Directory.Exists(folder))
|
||||
{
|
||||
try
|
||||
{
|
||||
return searchPatterns
|
||||
.SelectMany(searchPattern =>
|
||||
Directory.EnumerateFiles(folder, searchPattern, SearchOption.TopDirectoryOnly)
|
||||
.Where(path => !Path.GetFileName(path).StartsWith("._", StringComparison.OrdinalIgnoreCase)))
|
||||
fileSystem.Directory.EnumerateFiles(folder, searchPattern, SearchOption.TopDirectoryOnly)
|
||||
.Where(path =>
|
||||
!Path.GetFileName(path).StartsWith("._", StringComparison.OrdinalIgnoreCase)))
|
||||
.Distinct();
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
@@ -135,22 +133,18 @@ public class LocalFileSystem(IClient client, ILogger<LocalFileSystem> logger) :
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
public bool FileExists(string path) => File.Exists(path);
|
||||
|
||||
public bool FolderExists(string folder) => Directory.Exists(folder);
|
||||
|
||||
public async Task<Either<BaseError, Unit>> CopyFile(string source, string destination)
|
||||
{
|
||||
try
|
||||
{
|
||||
string directory = Path.GetDirectoryName(destination) ?? string.Empty;
|
||||
if (!Directory.Exists(directory))
|
||||
if (!fileSystem.Directory.Exists(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
fileSystem.Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
await using FileStream sourceStream = File.OpenRead(source);
|
||||
await using FileStream destinationStream = File.Create(destination);
|
||||
await using FileSystemStream sourceStream = fileSystem.File.OpenRead(source);
|
||||
await using FileSystemStream destinationStream = fileSystem.File.Create(destination);
|
||||
await sourceStream.CopyToAsync(destinationStream);
|
||||
|
||||
return Unit.Default;
|
||||
@@ -166,14 +160,14 @@ public class LocalFileSystem(IClient client, ILogger<LocalFileSystem> logger) :
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (string file in Directory.GetFiles(folder))
|
||||
foreach (string file in fileSystem.Directory.GetFiles(folder))
|
||||
{
|
||||
File.Delete(file);
|
||||
fileSystem.File.Delete(file);
|
||||
}
|
||||
|
||||
foreach (string directory in Directory.GetDirectories(folder))
|
||||
foreach (string directory in fileSystem.Directory.GetDirectories(folder))
|
||||
{
|
||||
Directory.Delete(directory, true);
|
||||
fileSystem.Directory.Delete(directory, true);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -184,20 +178,17 @@ public class LocalFileSystem(IClient client, ILogger<LocalFileSystem> logger) :
|
||||
return Unit.Default;
|
||||
}
|
||||
|
||||
public Task<string> ReadAllText(string path) => File.ReadAllTextAsync(path);
|
||||
public Task<string[]> ReadAllLines(string path) => File.ReadAllLinesAsync(path);
|
||||
|
||||
[SuppressMessage("Security", "CA5351:Do Not Use Broken Cryptographic Algorithms")]
|
||||
public async Task<byte[]> GetHash(string path)
|
||||
{
|
||||
using var md5 = MD5.Create();
|
||||
await using var stream = File.OpenRead(path);
|
||||
await using var stream = fileSystem.File.OpenRead(path);
|
||||
return await md5.ComputeHashAsync(stream);
|
||||
}
|
||||
|
||||
public string GetCustomOrDefaultFile(string folder, string file)
|
||||
{
|
||||
string path = Path.Combine(folder, file);
|
||||
return FileExists(path) ? path : Path.Combine(folder, $"_{file}");
|
||||
return fileSystem.File.Exists(path) ? path : Path.Combine(folder, $"_{file}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user