Avoiding Android Symbolic Link loop

浪尽此生 提交于 2020-01-16 09:36:39

问题


Is it possible in Android to have a SymLink (Symbolic Link) that leads to a point higher in the directory tree than the initial directory, so leading to a loop? For example:

/
  Parent
    Child
      SymLink to directory '/Parent'

This would loop if you try to crawl it with File.listFiles().

If so, how can one avoid it, other than not following SymLinks?

Sure, we could check if a link points to a parent directory, but more complicated structures would break that:

/
  Parent1
    SymLink to /Parent2
  Parent2
    SymLink to /Parent1

Right now, the best idea I have is to track all canonical directories already crawled, and refuse to crawl a directory if it has already been crawled, which seems excessive.

Does anyone have any better solutions?

NB: this is part of my attempt to find a solution to Crawling Android File System gets stuck in possible SymLink loop, so can be seen in that context if needed, and more code can be found there.

来源:https://stackoverflow.com/questions/59678418/avoiding-android-symbolic-link-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!