Incorrect folder check in SystemFolderWatcher
yoshiask opened this issue · comments
The problem
This method appears to check if a given path is a folder by stripping any trailing slashes and comparing that to
Path.GetDirectoryName(path)
. Because Path.GetDirectoryName
returns the path to the parent directory, this check will sometimes fail even for folders. For example:![image](https://user-images.githubusercontent.com/7549325/188366699-303fd574-3486-467f-88ee-01292885bd11.png)
Note this test will pass if the path does have a trailing slash, since in that case Path.GetDirectoryName
will effectively return the root of an arbitrary subdirectory in the given path, which of course is always the original path.
The solution
The only reliable way to check if a path is folder is by asking the filesystem, calling Directory.Exists(path)
like this:
OwlCore.Storage/src/SystemIO/SystemFolder.cs
Line 236 in 7efe338
Remarks
The IsFile
check has a similar issue; it will return true
for both files and directory paths without trailing slashes.
Good catch! Let's get this fixed.