Return max mtime of any source file under root, skipping build directories. Uses os.scandir() for efficiency. Detects BOTH structural changes (file add/remove) AND content modifications (file writes), unlike get_max_dir_mtime() which only detects structural changes. Args: r
(root: Path, exts: frozenset[str] | None = None)
| 25 | |
| 26 | |
| 27 | def _get_max_source_file_mtime(root: Path, exts: frozenset[str] | None = None) -> float: |
| 28 | """Return max mtime of any source file under root, skipping build directories. |
| 29 | |
| 30 | Uses os.scandir() for efficiency. Detects BOTH structural changes (file |
| 31 | add/remove) AND content modifications (file writes), unlike |
| 32 | get_max_dir_mtime() which only detects structural changes. |
| 33 | |
| 34 | Args: |
| 35 | root: Root directory to scan |
| 36 | exts: Set of file extensions to check (default: _CPP_SOURCE_EXTS). |
| 37 | Pass _PY_SOURCE_EXTS to scan Python files instead. |
| 38 | |
| 39 | Returns 0.0 on missing root or any OS error. |
| 40 | """ |
| 41 | if exts is None: |
| 42 | exts = _CPP_SOURCE_EXTS |
| 43 | max_mtime = 0.0 |
| 44 | stack = [str(root)] |
| 45 | while stack: |
| 46 | current = stack.pop() |
| 47 | try: |
| 48 | with os.scandir(current) as it: |
| 49 | for entry in it: |
| 50 | try: |
| 51 | name = entry.name |
| 52 | if entry.is_dir(follow_symlinks=False): |
| 53 | if name not in _SKIP_DIR_NAMES and not any( |
| 54 | name.startswith(p) for p in _SKIP_DIR_PREFIXES |
| 55 | ): |
| 56 | stack.append(entry.path) |
| 57 | elif entry.is_file(follow_symlinks=False): |
| 58 | _, ext = os.path.splitext(name) |
| 59 | if ext.lower() in exts: |
| 60 | mtime = entry.stat(follow_symlinks=False).st_mtime |
| 61 | if mtime > max_mtime: |
| 62 | max_mtime = mtime |
| 63 | except OSError: |
| 64 | pass |
| 65 | except OSError: |
| 66 | pass |
| 67 | return max_mtime |
| 68 | |
| 69 | |
| 70 | class FingerprintManager: |