This commit is contained in:
1 parent
5d549ff66a
commit
e831d0dfe0
28 files changed
+1026
-286
No files matched your search
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user