From 233656abb9417819ea7044067dd194831ae10340 Mon Sep 17 00:00:00 2001 From: "Dylan R. E. Moonfire" Date: Mon, 6 Dec 2021 23:02:23 -0600 Subject: [PATCH] fix: handle directory.Exists caching --- src/MfGames.IO/Extensions/DirectoryInfoExtensions.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/MfGames.IO/Extensions/DirectoryInfoExtensions.cs b/src/MfGames.IO/Extensions/DirectoryInfoExtensions.cs index df53189..ae5cbe9 100644 --- a/src/MfGames.IO/Extensions/DirectoryInfoExtensions.cs +++ b/src/MfGames.IO/Extensions/DirectoryInfoExtensions.cs @@ -29,7 +29,7 @@ namespace MfGames.IO.Extensions directory.Parent.CreateIfMissing(); // If the directory doesn't exist, create it. - if (!directory.Exists) + if (!Directory.Exists(directory.FullName)) { directory.Create(); } @@ -84,8 +84,9 @@ namespace MfGames.IO.Extensions } // If the directory is null, just return null. Same with - // non-existing directories. - if (directory is not { Exists: true }) + // non-existing directories. We don't use directory.Exists here + // because it seems to be cached and we get incorrect data. + if (directory == null || !File.Exists(directory.FullName)) { return null; }