< Summary

Information
Class: LOCKnet.Data.PlainToEncryptedVaultMigrationRecoveryDecision
Assembly: LOCKnet.Data
File(s): /home/runner/work/LOCKnet/LOCKnet/src/LOCKnet.Data/PlainToEncryptedVaultMigrationArtifacts.cs
Line coverage
88%
Covered lines: 8
Uncovered lines: 1
Coverable lines: 9
Total lines: 71
Line coverage: 88.8%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Action()100%11100%
get_Message()100%11100%
get_EncryptedTempPath()100%210%
get_PlainBackupPath()100%11100%
None()100%11100%
ResumeExport(...)100%11100%
FinalizeBackupCleanup(...)100%11100%
Fail(...)100%11100%

File(s)

/home/runner/work/LOCKnet/LOCKnet/src/LOCKnet.Data/PlainToEncryptedVaultMigrationArtifacts.cs

#LineLine coverage
 1using LOCKnet.Core.DataAbstractions;
 2
 3namespace LOCKnet.Data;
 4
 5internal static class PlainToEncryptedVaultMigrationArtifacts
 6{
 7  internal const string EncryptedTempSuffix = ".migration.encrypted.tmp";
 8  internal const string PlainBackupSuffix = ".migration.plain.bak";
 9
 10  internal static string GetEncryptedTempPath(string databasePath) => databasePath + EncryptedTempSuffix;
 11
 12  internal static string GetPlainBackupPath(string databasePath) => databasePath + PlainBackupSuffix;
 13
 14  internal static bool HasPendingArtifacts(string? databasePath)
 15    => databasePath is not null &&
 16      (File.Exists(GetEncryptedTempPath(databasePath)) || File.Exists(GetPlainBackupPath(databasePath)));
 17
 18  internal static PlainToEncryptedVaultMigrationRecoveryDecision Decide(string? databasePath, VaultHeader header)
 19  {
 20    if (databasePath is null)
 21      return PlainToEncryptedVaultMigrationRecoveryDecision.None();
 22
 23    var tempPath = GetEncryptedTempPath(databasePath);
 24    var backupPath = GetPlainBackupPath(databasePath);
 25    var tempExists = File.Exists(tempPath);
 26    var backupExists = File.Exists(backupPath);
 27
 28    return header.StorageMigrationState switch
 29    {
 30      VaultStorageMigrationState.None => (tempExists || backupExists)
 31        ? PlainToEncryptedVaultMigrationRecoveryDecision.Fail("Persistierte Storage-Migrationsartefakte gefunden, aber k
 32        : PlainToEncryptedVaultMigrationRecoveryDecision.None(),
 33      VaultStorageMigrationState.InProgress => tempExists && !backupExists
 34        ? PlainToEncryptedVaultMigrationRecoveryDecision.ResumeExport(tempPath, backupPath)
 35        : PlainToEncryptedVaultMigrationRecoveryDecision.Fail("Storage-Migration als in Arbeit markiert, aber die erwart
 36      VaultStorageMigrationState.FinalizationPending => backupExists && !tempExists
 37        ? PlainToEncryptedVaultMigrationRecoveryDecision.FinalizeBackupCleanup(tempPath, backupPath)
 38        : PlainToEncryptedVaultMigrationRecoveryDecision.Fail("Storage-Migration wartet auf Finalisierung, aber die erwa
 39      VaultStorageMigrationState.Failed => (tempExists || backupExists)
 40        ? PlainToEncryptedVaultMigrationRecoveryDecision.Fail("Fehlgeschlagene Storage-Migration hat Artefakte hinterlas
 41        : PlainToEncryptedVaultMigrationRecoveryDecision.None(),
 42      _ => PlainToEncryptedVaultMigrationRecoveryDecision.Fail("Unbekannter Storage-Migrationszustand erkannt.", tempPat
 43    };
 44  }
 45}
 46
 47internal enum PlainToEncryptedVaultMigrationRecoveryAction
 48{
 49  None = 0,
 50  ResumeExport = 1,
 51  FinalizeBackupCleanup = 2,
 52  Fail = 3,
 53}
 54
 555internal sealed record PlainToEncryptedVaultMigrationRecoveryDecision(
 556  PlainToEncryptedVaultMigrationRecoveryAction Action,
 357  string? Message,
 058  string? EncryptedTempPath,
 559  string? PlainBackupPath)
 60{
 161  internal static PlainToEncryptedVaultMigrationRecoveryDecision None() => new(PlainToEncryptedVaultMigrationRecoveryAct
 62
 63  internal static PlainToEncryptedVaultMigrationRecoveryDecision ResumeExport(string tempPath, string backupPath)
 164    => new(PlainToEncryptedVaultMigrationRecoveryAction.ResumeExport, "Storage-Migration muss mit dem vorhandenen encryp
 65
 66  internal static PlainToEncryptedVaultMigrationRecoveryDecision FinalizeBackupCleanup(string tempPath, string backupPat
 167    => new(PlainToEncryptedVaultMigrationRecoveryAction.FinalizeBackupCleanup, "Storage-Migration hat die Ziel-Vault ers
 68
 69  internal static PlainToEncryptedVaultMigrationRecoveryDecision Fail(string message, string tempPath, string backupPath
 270    => new(PlainToEncryptedVaultMigrationRecoveryAction.Fail, message, tempPath, backupPath);
 71}