Skip to content

Commit 3e4031d

Browse files
committed
test updates
1 parent 0559e8e commit 3e4031d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Tests/FileServiceTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public void Cleanup()
5454
return;
5555
}
5656

57+
RemoveReadOnlyAttributes(_tempDir);
58+
5759
for (int attempt = 0; attempt < 5; attempt++)
5860
{
5961
try
@@ -68,6 +70,7 @@ public void Cleanup()
6870
throw;
6971
}
7072

73+
RemoveReadOnlyAttributes(_tempDir);
7174
Thread.Sleep(100);
7275
}
7376
catch (IOException)
@@ -580,5 +583,42 @@ private string CreateDirWithFiles(string dirName, (string fileName, string conte
580583
return dirPath;
581584
}
582585

586+
private void RemoveReadOnlyAttributes(string path)
587+
{
588+
try
589+
{
590+
if (Directory.Exists(path))
591+
{
592+
DirectoryInfo directoryInfo = new DirectoryInfo(path);
593+
directoryInfo.Attributes &= ~FileAttributes.ReadOnly;
594+
595+
foreach (string filePath in Directory.GetFiles(path, "*", SearchOption.AllDirectories))
596+
{
597+
try
598+
{
599+
File.SetAttributes(filePath, FileAttributes.Normal);
600+
}
601+
catch
602+
{
603+
}
604+
}
605+
606+
foreach (string dirPath in Directory.GetDirectories(path, "*", SearchOption.AllDirectories))
607+
{
608+
try
609+
{
610+
File.SetAttributes(dirPath, FileAttributes.Normal);
611+
}
612+
catch
613+
{
614+
}
615+
}
616+
}
617+
}
618+
catch
619+
{
620+
}
621+
}
622+
583623
#endregion
584624
}

0 commit comments

Comments
 (0)