Design File-System Search with Symlink Safety
Design a read-only recursive file-search API with unit-aware size queries, composable metadata filters, and loop-safe symbolic-link traversal, then hand-write its core find method.
Design the objects and interfaces for a read-only file-system search API. The caller chooses a root directory, supplies metadata filters such as file-size bounds and a filename suffix, chooses whether traversal is recursive, and chooses whether symbolic links may be followed.
When links are followed, the search must never loop through self-links, ancestor links, or longer symbolic-link cycles. Path strings are display locations, not stable file identity: multiple paths may refer to the same file or directory, and a path can change while the underlying object remains the same.
For this exercise, assume all supplied filters use AND semantics and apply to regular-file metadata.
A size query may give a minimum, a maximum, or both, each as a quantity with a unit such as bytes, KB, MB, or GB; for this exercise, assume binary units (1 KB = 1,024 bytes, 1 MB = 1,024 KB, 1 GB = 1,024 MB), inclusive bounds, and that a query with an unknown unit, a negative quantity, or a minimum above its maximum is rejected before any traversal starts.
Return each stable file identity at most once, retaining the first logical path encountered for that identity. A symbolic link to a regular file may be matched when link following is enabled; a symbolic link to a directory may be traversed only when its stable target identity has not already been visited.
A missing or unreadable root fails the search, while a broken link or unreadable descendant is returned as a typed issue and eligible siblings continue. The search is best effort if the file system changes during traversal; it does not promise a snapshot.
After the design, hand-write the core find method; for this exercise, assume readable code or precise pseudocode is enough because it is reviewed by reading, so it does not need to compile or run.
File creation or deletion, content search, persistent indexing, distributed search, access-control policy design, and an operating-system file-system adapter are outside scope.