36 lines
1.7 KiB
C#
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);
|
|
}
|
|
}
|