Monday 25 February 2019

Determine a file's path(s) relative to a directory, including symlinks

I have a directory with thousands of descendants. Given a file path (which is guaranteed to exist), I want to know where that file can be found inside that directory -- including via symlinks. (The motivation is that a file has changed and I need to know what parts of the directory tree are affected.)

For example, given:

  • The directory path is /base.
  • The real file path is /elsewhere/myfile.
  • /base is a symlink to /realbase
  • /realbase/foo is a symlink to /elsewhere.
  • /realbase/bar/baz is a symlink to /elsewhere/myfile.

I want to find the paths /base/foo/myfile and /base/bar/baz.

I could do this by recursively checking every symlink in /base, but this would be very slow. I'm hoping that there's a more graceful solution.



from Determine a file's path(s) relative to a directory, including symlinks

No comments:

Post a Comment