From 31201179b3c6b8aacca1a931a1870b3fb0715ae0 Mon Sep 17 00:00:00 2001 From: Badrish Chandramouli Date: Wed, 8 Feb 2023 11:37:36 -0800 Subject: [PATCH] delete directory --- cs/test/TestUtils.cs | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/cs/test/TestUtils.cs b/cs/test/TestUtils.cs index 2b6b3cfbf..07c04ef5c 100644 --- a/cs/test/TestUtils.cs +++ b/cs/test/TestUtils.cs @@ -49,11 +49,9 @@ internal static void DeleteDirectory(string path, bool wait = false) } } - bool retry = true; - while (retry) + for (; ; Thread.Yield()) { // Exceptions may happen due to a handle briefly remaining held after Dispose(). - retry = false; try { Directory.Delete(path, true); @@ -61,21 +59,10 @@ internal static void DeleteDirectory(string path, bool wait = false) catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException) { - if (!wait) - { - try { Directory.Delete(path, true); } - catch { } - return; - } - retry = true; } + if (!wait || !Directory.Exists(path)) + break; } - - if (!wait) - return; - - while (Directory.Exists(path)) - Thread.Yield(); } ///