| 4400 | manual = sys.platform.startswith("linux") |
| 4401 | |
| 4402 | class Handler(FileSystemEventHandler): |
| 4403 | def on_any_event(self, event): |
| 4404 | nonlocal last_trigger, pending, override_snapshot, config_changed |
| 4405 | nonlocal ignore_patterns, ignored, directory_removed |
| 4406 | if event.is_directory: |
| 4407 | if not manual or _is_read_only_event(event): |
| 4408 | return |
| 4409 | path = Path(os.fsdecode(event.src_path)).resolve() |
| 4410 | if path.parent not in watched: |
| 4411 | return |
| 4412 | # Files below a moved/deleted directory may have no individual |
| 4413 | # events. Reconcile only subtrees that were actually watched. |
| 4414 | if path in watched and event.event_type in {"deleted", "moved"}: |
| 4415 | directory_removed = True |
| 4416 | last_trigger = time.monotonic() |
| 4417 | pending = True |
| 4418 | if event.event_type == "created": |
| 4419 | add_tree(path, emit_existing=True) |
| 4420 | elif event.event_type == "deleted": |
| 4421 | remove_tree(path) |
| 4422 | elif event.event_type == "moved": |
| 4423 | remove_tree(path) |
| 4424 | dest = Path(os.fsdecode(event.dest_path)).resolve() |
| 4425 | if under_root(dest): |
| 4426 | add_tree(dest, emit_existing=True) |
| 4427 | return |
| 4428 | if _is_read_only_event(event): |
| 4429 | return |
| 4430 | path = Path(os.fsdecode(event.src_path)).resolve() |
| 4431 | if manual and ( |
| 4432 | path.parent not in watched or not path.parent.exists() |
| 4433 | ): |
| 4434 | return |
| 4435 | if path.name in {".graphifyignore", ".gitignore"}: |
| 4436 | ignore_patterns = _load_graphifyignore( |
| 4437 | watch_root_for_ignore, gitignore=ignore_gitignore |
| 4438 | ) |
| 4439 | ignored = ignored_predicate( |
| 4440 | watch_root_for_ignore, gitignore=ignore_gitignore |
| 4441 | ) |
| 4442 | if manual: |
| 4443 | remove_tree(watch_root_for_ignore) |
| 4444 | add_tree(watch_root_for_ignore, emit_existing=False) |
| 4445 | return |
| 4446 | # Atomic replacement reports the new root config in dest_path. |
| 4447 | dest_raw = getattr(event, "dest_path", None) |
| 4448 | dest_path = Path(os.fsdecode(dest_raw)).resolve() if dest_raw else None |
| 4449 | if path == root_config_path or dest_path == root_config_path: |
| 4450 | override_snapshot = activate_language_overrides(watch_root_for_ignore) |
| 4451 | config_changed = True |
| 4452 | last_trigger = time.monotonic() |
| 4453 | pending = True |
| 4454 | return |
| 4455 | # Check .graphifyignore BEFORE the extension/dotfile/out filters so |
| 4456 | # the cheapest short-circuit for users with broad ignore patterns |
| 4457 | # (node_modules/, .venv/, build/, …) fires first. _is_ignored |
| 4458 | # tolerates absolute paths outside watch_root via its internal |
| 4459 | # relative_to guard, so a stray symlinked event won't raise. |