< Summary

Information
Class: LOCKnet.Data.PlainToEncryptedVaultMigrationArtifacts
Assembly: LOCKnet.Data
File(s): /home/runner/work/LOCKnet/LOCKnet/src/LOCKnet.Data/PlainToEncryptedVaultMigrationArtifacts.cs
Line coverage
89%
Covered lines: 25
Uncovered lines: 3
Coverable lines: 28
Total lines: 71
Line coverage: 89.2%
Branch coverage
56%
Covered branches: 13
Total branches: 23
Branch coverage: 56.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetEncryptedTempPath(...)100%11100%
GetPlainBackupPath(...)100%11100%
HasPendingArtifacts(...)50%44100%
Decide(...)57.89%201987.5%

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
 6810  internal static string GetEncryptedTempPath(string databasePath) => databasePath + EncryptedTempSuffix;
 11
 6912  internal static string GetPlainBackupPath(string databasePath) => databasePath + PlainBackupSuffix;
 13
 14  internal static bool HasPendingArtifacts(string? databasePath)
 1015    => databasePath is not null &&
 1016      (File.Exists(GetEncryptedTempPath(databasePath)) || File.Exists(GetPlainBackupPath(databasePath)));
 17
 18  internal static PlainToEncryptedVaultMigrationRecoveryDecision Decide(string? databasePath, VaultHeader header)
 519  {
 520    if (databasePath is null)
 121      return PlainToEncryptedVaultMigrationRecoveryDecision.None();
 22
 423    var tempPath = GetEncryptedTempPath(databasePath);
 424    var backupPath = GetPlainBackupPath(databasePath);
 425    var tempExists = File.Exists(tempPath);
 426    var backupExists = File.Exists(backupPath);
 27
 428    return header.StorageMigrationState switch
 429    {
 030      VaultStorageMigrationState.None => (tempExists || backupExists)
 031        ? PlainToEncryptedVaultMigrationRecoveryDecision.Fail("Persistierte Storage-Migrationsartefakte gefunden, aber k
 032        : PlainToEncryptedVaultMigrationRecoveryDecision.None(),
 133      VaultStorageMigrationState.InProgress => tempExists && !backupExists
 134        ? PlainToEncryptedVaultMigrationRecoveryDecision.ResumeExport(tempPath, backupPath)
 135        : PlainToEncryptedVaultMigrationRecoveryDecision.Fail("Storage-Migration als in Arbeit markiert, aber die erwart
 136      VaultStorageMigrationState.FinalizationPending => backupExists && !tempExists
 137        ? PlainToEncryptedVaultMigrationRecoveryDecision.FinalizeBackupCleanup(tempPath, backupPath)
 138        : PlainToEncryptedVaultMigrationRecoveryDecision.Fail("Storage-Migration wartet auf Finalisierung, aber die erwa
 139      VaultStorageMigrationState.Failed => (tempExists || backupExists)
 140        ? PlainToEncryptedVaultMigrationRecoveryDecision.Fail("Fehlgeschlagene Storage-Migration hat Artefakte hinterlas
 141        : PlainToEncryptedVaultMigrationRecoveryDecision.None(),
 142      _ => PlainToEncryptedVaultMigrationRecoveryDecision.Fail("Unbekannter Storage-Migrationszustand erkannt.", tempPat
 443    };
 544  }
 45}
 46
 47internal enum PlainToEncryptedVaultMigrationRecoveryAction
 48{
 49  None = 0,
 50  ResumeExport = 1,
 51  FinalizeBackupCleanup = 2,
 52  Fail = 3,
 53}
 54
 55internal sealed record PlainToEncryptedVaultMigrationRecoveryDecision(
 56  PlainToEncryptedVaultMigrationRecoveryAction Action,
 57  string? Message,
 58  string? EncryptedTempPath,
 59  string? PlainBackupPath)
 60{
 61  internal static PlainToEncryptedVaultMigrationRecoveryDecision None() => new(PlainToEncryptedVaultMigrationRecoveryAct
 62
 63  internal static PlainToEncryptedVaultMigrationRecoveryDecision ResumeExport(string tempPath, string backupPath)
 64    => new(PlainToEncryptedVaultMigrationRecoveryAction.ResumeExport, "Storage-Migration muss mit dem vorhandenen encryp
 65
 66  internal static PlainToEncryptedVaultMigrationRecoveryDecision FinalizeBackupCleanup(string tempPath, string backupPat
 67    => new(PlainToEncryptedVaultMigrationRecoveryAction.FinalizeBackupCleanup, "Storage-Migration hat die Ziel-Vault ers
 68
 69  internal static PlainToEncryptedVaultMigrationRecoveryDecision Fail(string message, string tempPath, string backupPath
 70    => new(PlainToEncryptedVaultMigrationRecoveryAction.Fail, message, tempPath, backupPath);
 71}