fix: protect against non-existent directories while finding
This commit is contained in:
parent
53aacbf862
commit
2b562e8c34
1 changed files with 8 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Reference in a new issue