简体   繁体   中英

How to detect recursively linked directories?

Given the following scenario: I have a windows client which is connected to an SMB share. I want to recursively dive into directories on that share to do something with the files (imagine calculating sha1 hashes for them if a certain size is exceeded).

What I would normally do: recursive dirInfo.EnumerateDirectories() catching some exceptional cases like unauthorized access and queue the files to an operator thread (to calc the sha1 then).

The Challenge: Recursive symlinks. My testscenario is quite simple

me@smb:~$ ls -l /home/me/tmp/recursionStartsHere
lrwxrwxrwx recursion -> /home/me/tmp/recursionStartsHere

What I have tried (apart from googlin) is to use dirInfo.Attributes.HasFlag(FlagAttributes.ReparsePoint) to detect symlinks which (of course) does not work out. The brute force approach seems like indexing every single directory with an accumulated checksum from their contents - which may not even be collision free.

As I am out of practical ideas now, how can I tell a certain directory is (only) a symlink? Of course, I'd prefer a platform independent so my code works the same for remote SMB as well as on local NTFS drives.

There's an interesting blog entry by Troy:

http://troyparsons.com/blog/2012/03/symbolic-links-in-c-sharp/

Although I don't know whether it's working with SMB shares.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM