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

Endless tree with System.IO.Directory.GetFiles #50247

Closed
LiranBinshtok opened this issue Mar 25, 2021 · 5 comments
Closed

Endless tree with System.IO.Directory.GetFiles #50247

LiranBinshtok opened this issue Mar 25, 2021 · 5 comments

Comments

@LiranBinshtok
Copy link

Description

when using Directory.GetFiles ( with all directories flag ) on a folder that contains subfolder and one of those holds a symbolic link
to the parent folder, the result will be an endless tree.

run this at terminal:
mkdir ~/test
mkdir ~/test/test1
mkdir ~/test/test1/test2
ln -s ~/test ~/test/test1/test2

then run this code:

namespace Tests { class Program { static void Main(string[] args) { var res = Directory.GetFiles("/Users/{youruser}/test","", SearchOption.AllDirectories); } } }

result: endless tree.

expected behavior: skip symbolic link

Configuration

.net core version: 3.1
OS: mac OS 11.2.1 Big Sur

Regression?

Other information

@mairaw mairaw transferred this issue from dotnet/core Mar 25, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Mar 25, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@Symbai
Copy link

Symbai commented Mar 25, 2021

According to the docs this is an expected behavior: https://docs.microsoft.com/en-us/dotnet/api/system.io.searchoption?view=net-5.0#remarks

@Zintom
Copy link

Zintom commented Mar 28, 2021

MSDN states this is expected behaviour, granted it would be nice to have a SearchOption.IgnoreSymLinks, or even a IgnoreRecursiveSymLinks option which would check if the Symbolic Link happens to point to a directory which has already been checked.

@iSazonov
Copy link
Contributor

iSazonov commented Mar 28, 2021

PowerShell has this many years. You can explicitly set FollowSymlink switch to follow symlinks in dir (aka Get-ChildItems).
But it is very expensive because this automatically turns on cycle checks for recursion.
It is very native design.

So if we want SearchOption.IgnoreSymLinks we should discuss SearchOption.CheckCycles too.
(For reference #24271 (comment))

@jozkee
Copy link
Member

jozkee commented May 20, 2021

This should be addressed with #52666.
Closing as duplicate.

@jozkee jozkee closed this as completed May 20, 2021
@jozkee jozkee removed the untriaged New issue has not been triaged by the area owner label May 20, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jun 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants