From a9ba6d98cb4cf4c34d1f8d8702878bfedbbc3ad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 1 Dec 2020 19:23:05 +0100 Subject: [PATCH] Fix bogus file access denied error after listDirectory calls on Windows. Makes sure that `FindClose` gets called before `listDirectory` returns to avoid a race-condition, where a successive modification of the directory fails with "access denied". --- source/vibe/core/file.d | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/vibe/core/file.d b/source/vibe/core/file.d index 430db57..7213c03 100644 --- a/source/vibe/core/file.d +++ b/source/vibe/core/file.d @@ -375,7 +375,7 @@ void listDirectory(string path, scope bool delegate(FileInfo info) @safe del) auto ch = createChannel!S(); TaskSettings ts; ts.priority = 10 * Task.basePriority; - runWorkerTaskH(ioTaskSettings, (string path, Channel!S ch) nothrow { + auto t = runWorkerTaskH(ioTaskSettings, (string path, Channel!S ch) nothrow { scope (exit) ch.close(); try { foreach (DirEntry ent; dirEntries(path, SpanMode.shallow)) { @@ -389,6 +389,11 @@ void listDirectory(string path, scope bool delegate(FileInfo info) @safe del) } }, path, ch); + scope (exit) { + t.interrupt(); + t.joinUninterruptible(); + } + S itm; while (ch.tryConsumeOne(itm)) { if (itm.error.length)