Files
PCL-ISE/tests/LauncherUpdateFileOperations.cs
T
Coldsmile_7 e831d0dfe0
Release PCL-ISE / release (push) Canceled after 0s
feat: prepare PCL-ISE 0.1.2 update test release
2026-10-27 23:57:25 +08:00

36 lines
1.7 KiB
C#

using System;
using System.IO;
// Faults affect only the named target in an isolated functional test directory.
public sealed class TestLauncherUpdateFileOperations : LauncherUpdateFileOperations {
public string TargetPath;
public int CopyFailuresRemaining;
public bool LeavePartialFile;
public bool CorruptInstalledFile;
public bool FailBackup;
public bool FailRestore;
public bool FailCleanup;
public override void CopyFile(string source, string target, bool overwrite) {
bool installsTarget = string.Equals(target, TargetPath, StringComparison.OrdinalIgnoreCase)
&& source.EndsWith(".new", StringComparison.OrdinalIgnoreCase);
if (FailBackup && string.Equals(target, TargetPath + ".bak", StringComparison.OrdinalIgnoreCase))
throw new IOException("Test: backup could not be written");
if (FailRestore && string.Equals(source, TargetPath + ".bak", StringComparison.OrdinalIgnoreCase))
throw new IOException("Test: restore could not be written");
if (installsTarget && CopyFailuresRemaining > 0) {
CopyFailuresRemaining--;
if (LeavePartialFile) File.WriteAllText(target, "incomplete new program");
throw new IOException("Test: new program copy interrupted");
}
base.CopyFile(source, target, overwrite);
if (installsTarget && CorruptInstalledFile) File.WriteAllText(target, "incomplete new program");
}
public override void DeleteFile(string target) {
if (FailCleanup && target.EndsWith(".new", StringComparison.OrdinalIgnoreCase))
throw new IOException("Test: staged file temporarily busy");
base.DeleteFile(target);
}
}