Skip to content

walk() crashes on out-of-tree root symlinks (Bazel convenience symlinks): _rel calls .resolve() #27

Description

@martyschneider-bear

Summary

codebase-index index crashes with ValueError: ... is not in the subpath of ... on any repository that has a root-level symlink pointing outside the repo. Bazel's convenience symlinks (bazel-bin, bazel-out, bazel-testlogs, bazel-<workspace>) are the common trigger, but any out-of-tree symlink in the walked root will do it. The crash happens before any file is indexed.

Environment

  • codebase-index 1.8.0 (pipx)
  • Python 3.11
  • Linux

Repro

  1. Use a repo with a root symlink that points outside the tree. A Bazel workspace after a build is the easy case: it creates bazel-out -> ~/.cache/bazel/.../bazel-out, etc.
  2. codebase-index init
  3. codebase-index index

Traceback (abridged)

indexer/pipeline.py -> build_index -> discovery/walker.py:walk -> _rel
  return path.resolve().relative_to(root).as_posix()
ValueError: '/home/.../.cache/bazel/.../bazel-out' is not in the subpath of '/home/.../repo'

Root cause

discovery/walker.py:_rel:

def _rel(root: Path, path: Path) -> str:
    return path.resolve().relative_to(root).as_posix()

os.walk lists the symlink in dirnames; the directory filter calls _rel on it while building the argument to is_ignored; .resolve() follows the symlink out of the tree, and .relative_to(root) then raises.

There is no user-side workaround: is_ignored_dir is backed by the hardcoded BUILTIN_DENYLIST (not configurable), and extra_ignore is evaluated via is_ignored after _rel has already thrown. Adding bazel-* patterns to extra_ignore still crashes.

Suggested fix

Drop the .resolve():

def _rel(root: Path, path: Path) -> str:
    return path.relative_to(root).as_posix()

os.walk uses followlinks=False by default, so it never descends into the symlinked directory, and it already yields paths lexically under root. .resolve() is unnecessary here and is the sole cause of the crash. Alternatively, guard relative_to with a try/except and skip out-of-tree paths.

Reproduced on v1.8.0. v1.9.0 likely affected too if the walker is unchanged (not verified).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions