Skip to content

Commit 17332bb

Browse files
committed
handle Temp* race condition
1 parent e99fcfc commit 17332bb

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/Verify/TempDirectory.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ public static void Init()
6262

6363
VerifierSettings.GlobalScrubbers.Add((scrubber, _, _) =>
6464
{
65-
if (paths.Value == null)
65+
var pathsValue = paths.Value;
66+
if (pathsValue == null)
6667
{
6768
return;
6869
}
6970

70-
foreach (var path in paths.Value)
71+
foreach (var path in pathsValue)
7172
{
7273
scrubber.Replace(path, "{TempDirectory}");
7374
}
@@ -118,13 +119,14 @@ public TempDirectory()
118119
Path = IoPath.Combine(RootDirectory, IoPath.GetRandomFileName());
119120
Directory.CreateDirectory(Path);
120121

121-
if (paths.Value == null)
122+
var pathsValue = paths.Value;
123+
if (pathsValue == null)
122124
{
123125
paths.Value = [Path];
124126
}
125127
else
126128
{
127-
paths.Value!.Add(Path);
129+
pathsValue.Add(Path);
128130
}
129131
}
130132

@@ -135,7 +137,7 @@ public void Dispose()
135137
Directory.Delete(Path, true);
136138
}
137139

138-
paths.Value!.Remove(Path);
140+
paths.Value?.Remove(Path);
139141
}
140142

141143
/// <summary>

src/Verify/TempFile.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,14 @@ public TempFile(string? extension = null)
132132

133133
Path = IoPath.Combine(RootDirectory, fileName);
134134

135-
if (paths.Value == null)
135+
var pathsValue = paths.Value;
136+
if (pathsValue == null)
136137
{
137138
paths.Value = [Path];
138139
}
139140
else
140141
{
141-
paths.Value!.Add(Path);
142+
pathsValue.Add(Path);
142143
}
143144
}
144145

@@ -162,7 +163,7 @@ public void Dispose()
162163
File.Delete(Path);
163164
}
164165

165-
paths.Value!.Remove(Path);
166+
paths.Value?.Remove(Path);
166167
}
167168

168169
/// <summary>

0 commit comments

Comments
 (0)