Changed is_valid_pk() from sync to async to properly wait for file
creation without blocking. This is a breaking change but we're in
active development.
Changes:
- is_valid_pk() signature: fn -> async fn
- Replaced std:🧵:sleep with tokio::time::sleep
- Updated all 6 call sites in pmoplaylist to add .await:
- WriteHandle::push()
- WriteHandle::push_set()
- ReadHandle::pop()
- ReadHandle::peek()
- ReadHandle::remaining()
- ReadHandle::get_all()
Benefits:
- Non-blocking wait for file creation during ingestion
- More idiomatic async Rust code
- Better integration with tokio runtime
When add_from_reader() returns after prebuffering, the file may not
exist on disk yet due to tokio::spawn() scheduling. This caused
"Cache entry not found" errors when playlist tried to validate the pk.
Solution:
- If DB entry exists but file doesn't, wait up to 1 second for file creation
- This handles the race condition between prebuffer completion and
File::create() in the background task
- Deterministic and robust: either file exists or we timeout with error
The fix preserves the progressive caching design while ensuring
validation is deterministic.
Test: Verified no "Cache entry not found" errors with clean cache.
Changes:
1. pmocache/cache_trait.rs - Fixed is_valid_pk() logic:
- Accept files WITH completion markers (complete downloads)
- Accept files WITHOUT markers but recent (< 60s) (downloads in progress)
- Reject files WITHOUT markers and old (>= 60s) (failed downloads)
This preserves progressive caching: files are valid as soon as prebuffer
completes, without waiting for completion marker.
2. pmoupnp/cache_registry.rs - Added compatibility layer:
- Re-exports get_audio_cache/get_cover_cache from singletons
- Provides build_audio_url/build_cover_url for pmosource
- Uses PMO_SERVER_URL env var for base URL
3. pmoupnp/lib.rs - Added cache_registry module to public API
This fixes "Cache entry not found" errors while maintaining progressive
caching functionality for play_and_cache example.
Added heuristic to accept files modified within last 60 seconds,
which should catch files currently being downloaded.
Also added debug logging to diagnose why validation fails.
Still debugging - need to test with logs to see what's happening.