algorithm - Efficient way to walk directory tree containing link cycles -
algorithm - Efficient way to walk directory tree containing link cycles -
is there more efficient way walk directory tree contains link cycles tracking files have been visited?
for illustration consider walking directory containing these files:
symlink "parent" -> ".." symlink "uh_oh" -> "/" regular file "reg" symlink "reg2" -> "reg"
you should track directories have been visited, per first example, otherwise there no improve solution maintaining visited flags every file.
maintaining flags easier if there portable way of getting short unique identifier mounted filesystem. then, need think through consequences of mount , umount operations occurring during scan, particularly since such scan might take quite long time if filesystem tree includes remote filesystems.
in theory, can "filesystem id" stafvfs
interface, in practice not totally portable. quoting man statfs
linux distro:
nobody knows f_fsid
supposed contain…
…the general thought f_fsid
contains random stuff such pair (f_fsid,ino)
uniquely determines file. operating systems utilize (a variation on) device number, or device number combined filesystem type. several oses restrict giving out f_fsid field superuser (and 0 unprivileged users), because field used in filehandle of filesystem when nfs-exported, , giving out security concern.
this latter restriction -- f_fsid
presented 0 non-privileged users -- not violate posix standard cited above, because standard includes general disclaimer: "it unspecified whether members of statvfs
construction have meaningful values on file systems."
algorithm filesystems symlink directory-walk symlink-traversal
Comments
Post a Comment