← Files Codex SecurityARCHIVED FILE

scripts/filesystem_identity.py

926 Bytes · Oct 2, 2026 · 00:04 UTC

↓ Download file

"""SQLite-safe serialization for platform filesystem identity values."""

from __future__ import annotations

import argparse


def serialize_filesystem_identity(value: int) -> int | str:
    """Preserve filesystem IDs that can exceed SQLite's signed 64-bit range.

    Python 3.12 can expose 64-bit device IDs and 128-bit inode IDs on Windows.
    Values that already fit remain integers for compatibility with older plugin
    versions. The prefix prevents SQLite from coercing larger hexadecimal values
    through the INTEGER affinity of the existing columns.
    """
    if -(1 << 63) <= value < (1 << 63):
        return value
    return f"stat:{value:x}"


def stored_filesystem_identity_matches(stored: object, current: int) -> bool:
    return stored == serialize_filesystem_identity(current)


def main() -> None:
    argparse.ArgumentParser(description=__doc__).parse_args()


if __name__ == "__main__":
    main()

SHA-256: 2b3a22761f28faa2f45f192ff14b17fd80f1f43d9d4174007c51d21f4cbf47c1