Is there an algorithm to decide if a symlink loops?
21
votes
7
answers
14490
views
Unix systems usually just error out if they are confronted with a path that contains a symlink loop or just too many symlinks, because they have a limit to the number of symlinks they will traverse in one path lookup. But is there a way to actually decide if a given path resolves to something or contains a loop, even if it contains more links than a unix is willing to follow? Or is this a formally undecidable problem? And if it can be decided, can it be decided in a reasonable amount of time/memory (e.g. without having to visit all files on a filesystem)?
Some examples:
a/b/c/d
where a/b is a symlink to ../e
and e is a symlink to f
and f is a symlink to a/b
a/b/c/d
where a/b/c is a symlink to ../c
a/b/c/d
where a/b/c is a symlink to ../c/d
a/b/c/d
where a/b/c is a symlink to /a/b/e
where a/b/e is a symlink to /a/b/f
where a/b/f is a symlink to /a/b/g
**Edit**:
To clarify, I am not asking about finding loops in the file system, I am asking about a decision algorithm that decides of a given path whether it resolves to a definite file/directory or whether it does not resolve at all. For example in the following system, there is a loop, but the given path still resolves fine:
/ -- a -- b
where b is a symlink to /a
This directory tree clearly has a cycle, but the path
a/b/b/b/b/b
still resolves fine to /a
.
Asked by JanKanis
(1421 rep)
Nov 6, 2013, 11:25 PM
Last activity: Jul 28, 2021, 12:01 PM
Last activity: Jul 28, 2021, 12:01 PM