0

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
mbx
  • 6,292
  • 6
  • 58
  • 91

1 Answers1

1

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.

fan711
  • 716
  • 3
  • 13
  • While this is a nice way to tell target on NTFS it doesn't work for recursively linked directories on smb share. – mbx Jun 22 '13 at 13:30
  • The link is broken so there's now no information in the answer. – Ed Bayiates Apr 01 '19 at 18:26
  • Since the article is quite long I'm posting an archive link here instead of updating the answer: https://web.archive.org/web/20180205072300/http://troyparsons.com/blog/2012/03/symbolic-links-in-c-sharp/ Frankly I don't recall the details after these years ;) – fan711 Apr 16 '19 at 13:11