summaryrefslogtreecommitdiff
path: root/tests/src/performance/Scenario/JitBench/Utilities/FileTasks.cs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/performance/Scenario/JitBench/Utilities/FileTasks.cs')
-rw-r--r--tests/src/performance/Scenario/JitBench/Utilities/FileTasks.cs46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/src/performance/Scenario/JitBench/Utilities/FileTasks.cs b/tests/src/performance/Scenario/JitBench/Utilities/FileTasks.cs
index 5e9efa2ffb..e5391cafd0 100644
--- a/tests/src/performance/Scenario/JitBench/Utilities/FileTasks.cs
+++ b/tests/src/performance/Scenario/JitBench/Utilities/FileTasks.cs
@@ -178,6 +178,9 @@ namespace JitBench
}
try
{
+ // On some systems, directories/files created programmatically are created with attributes
+ // that prevent them from being deleted. Set those attributes to be normal
+ SetAttributesNormal(path);
Directory.Delete(path, true);
return;
}
@@ -194,6 +197,18 @@ namespace JitBench
}
}
+ public static void SetAttributesNormal(string path)
+ {
+ foreach (var subDir in Directory.GetDirectories(path))
+ {
+ SetAttributesNormal(subDir);
+ }
+ foreach (var file in Directory.GetFiles(path))
+ {
+ File.SetAttributes(file, FileAttributes.Normal);
+ }
+ }
+
public static void MoveDirectory(string sourceDirName, string destDirName, ITestOutputHelper output)
{
if (output != null)
@@ -225,6 +240,37 @@ namespace JitBench
}
}
+ public static void MoveFile(string sourceFileName, string destFileName, ITestOutputHelper output)
+ {
+ if (output != null)
+ {
+ output.WriteLine("Moving " + sourceFileName + " -> " + destFileName);
+ }
+ int retries = 10;
+ for (int i = 0; i < retries; i++)
+ {
+ if (!File.Exists(sourceFileName) && File.Exists(destFileName))
+ {
+ return;
+ }
+ try
+ {
+ File.Move(sourceFileName, destFileName);
+ return;
+ }
+ catch (IOException e) when (i < retries - 1)
+ {
+ output.WriteLine($" Attempt #{i + 1} failed: {e.Message}");
+ }
+ catch (UnauthorizedAccessException e) when (i < retries - 1)
+ {
+ output.WriteLine($" Attempt #{i + 1} failed: {e.Message}");
+ }
+ // if something has a transient lock on the file waiting may resolve the issue
+ Thread.Sleep((i + 1) * 10);
+ }
+ }
+
public static void CreateDirectory(string path, ITestOutputHelper output)
{
output.WriteLine("Creating " + path);