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

FileSystemWatcher to a directory symlink that points to a file doesn't raise exception on windows 8.1 or lower #53010

Open
jozkee opened this issue May 20, 2021 · 5 comments

Comments

@jozkee
Copy link
Member

jozkee commented May 20, 2021

Description

On cmd:

# create file
echo text > file.txt 

# create directory symlink to file
mklink /d linktofile file.txt

On .NET:

using System;
using System.IO;

namespace fsw
{
    class Program
    {
        static void Main(string[] args)
        {
            using var watcher = new FileSystemWatcher("linktofile");
            watcher.EnableRaisingEvents = true; // This should've thrown.

            Console.WriteLine("Watching...");
            Console.ReadKey();
        }
    }
}

Configuration

.NET 5 and .NET 6 preview
OS: Windows 8.1 or 7.
Windows 10 throws which is what I expected since a directory symlink to a file is a bad symlink.

Regression?

No

Other information

The only problem I see is consistency.

cc @carlossanlop

@ghost
Copy link

ghost commented May 20, 2021

Tagging subscribers to this area: @carlossanlop
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

On cmd:

# create file
echo text > file.txt 

# create directory symlink to file
mklink /d linktofile file.txt

On .NET:

using System;
using System.IO;

namespace fsw
{
    class Program
    {
        static void Main(string[] args)
        {
            using var watcher = new FileSystemWatcher("linktofile");
            watcher.EnableRaisingEvents = true; // This should've thrown.

            Console.WriteLine("Watching...");
            Console.ReadKey();
        }
    }
}

Configuration

.NET 5 and .NET 6 preview
OS: Windows 8.1 or lower.
Windows 10 throws which is what I expected since a directory symlink to a file is a bad symlink.

Regression?

No

Other information

The only problem I see is consistency.

cc @carlossanlop

Author: Jozkee
Assignees: -
Labels:

area-System.IO, os-windows

Milestone: Future

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label May 20, 2021
@carlossanlop carlossanlop removed the untriaged New issue has not been triaged by the area owner label May 21, 2021
@carlossanlop
Copy link
Member

Were you able to determine the root cause?

@jozkee
Copy link
Member Author

jozkee commented May 21, 2021

CreateFileW with FILE_FLAG_BACKUP_SEMANTICS attribute throws if the path is to a self-referencing directory symlink in windows 10. In 7 and 8.1, it does not.

See related https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#directories.

@carlossanlop
Copy link
Member

Thanks. So if those Windows versions do not throw, are you suggesting we detect the self-referencing dir symlink ourselves?

@jozkee
Copy link
Member Author

jozkee commented May 21, 2021

Yes, it could be an option. We most probably want to only do that for those versions and avoid the manual validation (potentially involves a sys-call) in win10, which currently throws as expected.

Another option is to find an alternative API that throws in such case and that also returns a handle for a directory, not sure if exists.

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

No branches or pull requests

2 participants