[英]How to detect recursively linked directories?
Given the following scenario: I have a windows client which is connected to an SMB share. 给定以下情况:我有一个Windows客户端,该客户端连接到SMB共享。 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).
我想递归地深入该共享上的目录以对文件进行处理(如果超出一定大小,可以为它们计算sha1哈希值)。
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). 我通常要做的是:递归
dirInfo.EnumerateDirectories()
捕获一些特殊情况,例如未经授权的访问,并将文件排队到操作员线程中(然后计算sha1)。
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. 我尝试过的(除了googlin之外)是使用
dirInfo.Attributes.HasFlag(FlagAttributes.ReparsePoint)
来检测符号链接(当然)不能解决问题。 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.
当然,我希望独立于平台,因此我的代码在远程SMB以及本地NTFS驱动器上的工作原理相同。
There's an interesting blog entry by Troy: 特洛伊(Troy)有一个有趣的博客条目:
http://troyparsons.com/blog/2012/03/symbolic-links-in-c-sharp/ http://troyparsons.com/blog/2012/03/symbolic-links-in-c-sharp/
Although I don't know whether it's working with SMB shares. 虽然我不知道它是否适用于SMB股票。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.