Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit a6e31c8

Browse files
author
Mikhail Arkhipov
authored
Fix issue with writing caches (#1122)
1 parent fee28c5 commit a6e31c8

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/Core/Impl/Extensions/IOExtensions.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,14 @@ public static string ReadTextWithRetry(this IFileSystem fs, string file) {
124124
public static void WriteTextWithRetry(this IFileSystem fs, string filePath, string text) {
125125
for (var retries = 100; retries > 0; --retries) {
126126
try {
127-
fs.WriteAllText(filePath, text);
128-
return;
129-
} catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException) {
127+
using (var stream = fs.OpenWithRetry(filePath, FileMode.Create, FileAccess.Write, FileShare.Read)) {
128+
if (stream != null) {
129+
var bytes = Encoding.UTF8.GetBytes(text);
130+
stream.Write(bytes, 0, bytes.Length);
131+
return;
132+
}
133+
}
134+
} catch (IOException) { } catch (UnauthorizedAccessException) {
130135
Thread.Sleep(10);
131136
}
132137
}

0 commit comments

Comments
 (0)