Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filesystem notifications seemingly don't fire when they are supposed to (Windows 10, net6.0-windows) #310

Closed
IsaMorphic opened this issue May 2, 2022 · 8 comments

Comments

@IsaMorphic
Copy link

Hello,
I am having an issue with the most recent version of DokanNet (was happening with the previous version, too) where whenever I create, delete, or update files/directories in my mounted filesystem, I have to refresh the Windows Explorer view of the tree to see the changes reflected, even when the changes are triggered by Windows Explorer itself (i.e creating a new text file or folder).

You can see all of my code here. I used the Mirror sample as a starting point and worked from there. Relevant code is in ArchiveOperations.cs and Program.cs.
https://github.com/yodadude2003/DATOneArchiver/tree/dokan-driver/DATOneDriver

I don't know if its my code, or yours 😅

@Liryna
Copy link
Member

Liryna commented May 2, 2022

If a file is created inside the virtual volume, you should not have any issues.
It is only if the file is created outside of it like in the remote storage that it is virtually showing locally that your fs has to notify the change by using the extra API.

To see if it is your fs the issue, you can try to reproduce with the DotNet sample and the native one.
If they work, you will need to find out what is the difference.

@IsaMorphic
Copy link
Author

Okay, sounds good. I'll update you later this week once I have a chance to do that.

@IsaMorphic
Copy link
Author

Turns out I had time today xD
I tried to run the mirror sample and it works as expected. Seems like there is something I am missing in my own code. There are many differences so it will be difficult to narrow down exactly what the problem is 🥴

If I feel like pursuing this, I will post on this thread with the solution I find to help others who might happen upon this.
Otherwise consider this issue closed. Thanks :)

@Liryna
Copy link
Member

Liryna commented May 3, 2022

Don't hesitate to use procmon tool to compare the difference between the working sample and yours.
Like record the event when creating a simple file and see from there.

@IsaMorphic
Copy link
Author

Thank you for the suggestion! That will be helpful

@IsaMorphic
Copy link
Author

After hours of debugging, I found that the root cause of the issue was the fact that I hadn't implemented the FindFilesWithPattern method.

I had done so purposefully because the documentation mislead me, it said that the dokan library would handle it. Perhaps it should be made more clear that implementors must still include an implementation, just that they can use the Dokan pattern helper to simplify the code.

This is how my code ended up looking:

        public NtStatus FindFiles(string filePath, out IList<FileInformation> files, IDokanFileInfo info)
        {
            return FindFilesWithPattern(filePath, "*", out files, info);
        }

        public NtStatus FindFilesWithPattern(string filePath, string searchPattern, out IList<FileInformation> files, IDokanFileInfo info)
        {
            var node = archive.Root.Get(filePath, false);
            if (node == null)
            {
                files = null;
                return DokanResult.FileNotFound;
            }
            else if (node.Children == null)
            {
                files = null;
                return DokanResult.NotADirectory;
            }

            files = node.Children.Values
                .Where(n => DokanHelper.DokanIsNameInExpression(searchPattern, n.Name, true))
                .Select(n => new FileInformation
                {
                    Attributes = n.Children != null ? FileAttributes.Directory : FileAttributes.Normal,
                    FileName = n.Name,
                    Length = n.Stream?.Length ?? 0,
                }).ToList();

            return DokanResult.Success;
        }

@Liryna
Copy link
Member

Liryna commented May 4, 2022

Indeed! There is a TODO but no issue or documentation 😢 I created #311

// TODO(someone): Allow userland FS to set FindFiles preference at mount time and nullify the callback not used.

Thanks @yodadude2003 for sharing the info!

@IsaMorphic
Copy link
Author

Ah that's fair enough. You're welcome! 😁👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants