fix: protect against non-existent directories while finding

This commit is contained in:
Dylan R. E. Moonfire 2021-12-06 22:31:01 -06:00
parent 53aacbf862
commit 2b562e8c34

View file

@ -21,7 +21,7 @@ namespace MfGames.IO.Extensions
// Ignore blanks.
if (directory == null)
{
return directory;
return null;
}
// Check the parent first. We don't have to worry about null because
@ -83,14 +83,18 @@ namespace MfGames.IO.Extensions
throw new ArgumentNullException(nameof(match));
}
// If the directory is null, just return null.
if (directory == null)
// If the directory is null, just return null. Same with
// non-existing directories.
if (directory is not { Exists: true })
{
return null;
}
// Check this directory for a match, otherwise move up.
if (match(directory)) return directory;
if (match(directory))
{
return directory;
}
directory = directory.Parent;
}