Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 440da17

Browse files
committed
Add support for deleting TempDirectory with read-only files
1 parent e0e5ded commit 440da17

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/UnitTests/Helpers/TestBaseClass.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected static PullRequest CreatePullRequest(User user, int id, ItemState stat
6464
null, null, null);
6565
return new PullRequest(0, uri, uri, uri, uri, uri, uri,
6666
id, state, title, "", createdAt, updatedAt,
67-
null, null,
67+
null, null,
6868
new GitReference(uri.ToString(), "foo:bar", "bar", "123", user, repo),
6969
new GitReference(uri.ToString(), "foo:baz", "baz", "123", user, repo),
7070
user, null, null, false, null,
@@ -87,8 +87,23 @@ public TempDirectory()
8787

8888
public void Dispose()
8989
{
90+
// Remove any read-only attributes
91+
SetFileAttributes(Directory, FileAttributes.Normal);
9092
Directory.Delete(true);
9193
}
94+
95+
static void SetFileAttributes(DirectoryInfo dir, FileAttributes attributes)
96+
{
97+
foreach (DirectoryInfo subdir in dir.GetDirectories())
98+
{
99+
SetFileAttributes(subdir, attributes);
100+
}
101+
102+
foreach (var file in dir.GetFiles())
103+
{
104+
File.SetAttributes(file.FullName, attributes);
105+
}
106+
}
92107
}
93108

94109
protected class TempRepository : TempDirectory

0 commit comments

Comments
 (0)