From e94b341a5bbc91badaafa34343e7b443762001dc Mon Sep 17 00:00:00 2001 From: kqjy Date: Tue, 31 Mar 2026 17:13:05 +0800 Subject: [PATCH] Add robust myfsio_core staleness detection with Python fallback; document Rust extension build in README --- README.md | 5 +++++ app/encryption.py | 4 ++++ app/integrity.py | 2 ++ app/s3_api.py | 4 ++++ app/storage.py | 8 ++++++++ 5 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 24b61d4..772178d 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,11 @@ source .venv/bin/activate # Install dependencies pip install -r requirements.txt +# (Optional) Build Rust native extension for better performance +# Requires Rust toolchain: https://rustup.rs +pip install maturin +cd myfsio_core && maturin develop --release && cd .. + # Start both servers python run.py diff --git a/app/encryption.py b/app/encryption.py index cb40199..f000176 100644 --- a/app/encryption.py +++ b/app/encryption.py @@ -21,6 +21,10 @@ if sys.platform != "win32": try: import myfsio_core as _rc + if not all(hasattr(_rc, f) for f in ( + "encrypt_stream_chunked", "decrypt_stream_chunked", + )): + raise ImportError("myfsio_core is outdated, rebuild with: cd myfsio_core && maturin develop --release") _HAS_RUST = True except ImportError: _rc = None diff --git a/app/integrity.py b/app/integrity.py index d42f5b2..2ca3eb5 100644 --- a/app/integrity.py +++ b/app/integrity.py @@ -12,6 +12,8 @@ from typing import Any, Dict, List, Optional try: import myfsio_core as _rc + if not hasattr(_rc, "md5_file"): + raise ImportError("myfsio_core is outdated, rebuild with: cd myfsio_core && maturin develop --release") _HAS_RUST = True except ImportError: _HAS_RUST = False diff --git a/app/s3_api.py b/app/s3_api.py index c1a6961..c4c3864 100644 --- a/app/s3_api.py +++ b/app/s3_api.py @@ -19,6 +19,10 @@ from defusedxml.ElementTree import fromstring try: import myfsio_core as _rc + if not all(hasattr(_rc, f) for f in ( + "verify_sigv4_signature", "derive_signing_key", "clear_signing_key_cache", + )): + raise ImportError("myfsio_core is outdated, rebuild with: cd myfsio_core && maturin develop --release") _HAS_RUST = True except ImportError: _rc = None diff --git a/app/storage.py b/app/storage.py index e148045..3ccf645 100644 --- a/app/storage.py +++ b/app/storage.py @@ -20,6 +20,14 @@ from typing import Any, BinaryIO, Dict, Generator, List, Optional try: import myfsio_core as _rc + if not all(hasattr(_rc, f) for f in ( + "validate_bucket_name", "validate_object_key", "md5_file", + "shallow_scan", "bucket_stats_scan", "search_objects_scan", + "stream_to_file_with_md5", "assemble_parts_with_md5", + "build_object_cache", "read_index_entry", "write_index_entry", + "delete_index_entry", "check_bucket_contents", + )): + raise ImportError("myfsio_core is outdated, rebuild with: cd myfsio_core && maturin develop --release") _HAS_RUST = True except ImportError: _rc = None