Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/c#/GeneralUpdate.Core/Configuration/ConfiginfoBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,9 @@ public Configinfo Build()
Bowl = _bowl,
Script = _script,
DriverDirectory = _driverDirectory,
BlackFiles = _blackFiles,
BlackFormats = _blackFormats,
SkipDirectorys = _skipDirectorys
BlackFiles = _blackFiles ?? new List<string>(),
BlackFormats = _blackFormats ?? new List<string>(),
SkipDirectorys = _skipDirectorys ?? new List<string>()
};

// Validate the built configuration
Expand Down
6 changes: 5 additions & 1 deletion src/c#/GeneralUpdate.Core/FileSystem/StorageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
/// <summary>
/// Recursively read all files in the folder path.
/// </summary>
private IEnumerable<FileNode> ReadFileNode(string path, string rootPath = null)

Check warning on line 255 in src/c#/GeneralUpdate.Core/FileSystem/StorageManager.cs

View workflow job for this annotation

GitHub Actions / build-and-test (ubuntu-latest)

Cannot convert null literal to non-nullable reference type.

Check warning on line 255 in src/c#/GeneralUpdate.Core/FileSystem/StorageManager.cs

View workflow job for this annotation

GitHub Actions / build-and-test (windows-latest)

Cannot convert null literal to non-nullable reference type.
{
var resultFiles = new List<FileNode>();
rootPath ??= path;
Expand Down Expand Up @@ -305,7 +305,11 @@

var dirs = Directory.GetDirectories(backupRoot)
.Select(d => new DirectoryInfo(d))
.OrderByDescending(d => d.CreationTime)
.OrderByDescending(d =>
{
var name = d.Name;
return Version.TryParse(name, out var v) ? v : new Version(0, 0);
})
Comment on lines +308 to +312
.Skip(keepVersions);

foreach (var dir in dirs)
Expand Down
7 changes: 5 additions & 2 deletions src/c#/GeneralUpdate.Core/Ipc/IProcessInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public EncryptedFileProcessInfoProvider(string? basePath = null)

public Task SendAsync(ProcessInfo info, CancellationToken token = default)
{
token.ThrowIfCancellationRequested();
var json = JsonSerializer.Serialize(info, ProcessInfoJsonContext.Default.ProcessInfo);
var plainBytes = Encoding.UTF8.GetBytes(json);
using var aes = Aes.Create();
Expand Down Expand Up @@ -101,20 +102,22 @@ public Task SendAsync(ProcessInfo info, CancellationToken token = default)
public class SharedMemoryProcessInfoProvider : IProcessInfoProvider
{
private readonly string _mapName;
private MemoryMappedFile? _mmf;
private const int MaxPayload = 4096;

public SharedMemoryProcessInfoProvider(string mapName = "GeneralUpdate.IPC.Shm")
=> _mapName = mapName;

public Task SendAsync(ProcessInfo info, CancellationToken token = default)
{
token.ThrowIfCancellationRequested();
var json = JsonSerializer.Serialize(info, ProcessInfoJsonContext.Default.ProcessInfo);
var bytes = Encoding.UTF8.GetBytes(json);
if (bytes.Length > MaxPayload - 4)
throw new InvalidOperationException($"ProcessInfo payload exceeds {MaxPayload - 4} bytes.");

using var mmf = MemoryMappedFile.CreateNew(_mapName, MaxPayload);
using var accessor = mmf.CreateViewAccessor(0, MaxPayload);
_mmf = MemoryMappedFile.CreateOrOpen(_mapName, MaxPayload);
using var accessor = _mmf.CreateViewAccessor(0, MaxPayload);
accessor.Write(0, bytes.Length);
accessor.WriteArray(4, bytes, 0, bytes.Length);
return Task.CompletedTask;
Expand Down
2 changes: 1 addition & 1 deletion tests/CoreTest/Ipc/IpcFallbackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public async Task AutoProvider_ThrowsWhenAllFail()
var info = CreateTestInfo("FailAll", "1.0.0");

await Assert.ThrowsAnyAsync<Exception>(() =>
provider.SendAsync(info, new CancellationTokenSource(TimeSpan.FromMilliseconds(100)).Token));
provider.SendAsync(info, new CancellationToken(true)));
}

[Fact]
Expand Down
Loading