Skip to content

Commit 266026d

Browse files
committed
Bugfix: MTP watcher misses external files
`invalidate_listing_cache` was called with the raw `mtp://` URL from `LISTING_CACHE` (e.g., `mtp://mtp-device/65537/Documents`), but the MTP listing cache keys use `normalize_mtp_path` (e.g., `/Documents`). The key mismatch made every invalidation a no-op, so `list_directory` kept returning stale cached entries and `compute_diff` found no changes. On macOS this was masked because FSEvents fires with enough latency that the 5s cache TTL expires before diffs are computed. On Linux, inotify fires instantly, so all diff attempts hit the still-fresh cache.
1 parent 4380469 commit 266026d

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

apps/desktop/src-tauri/src/mtp/connection/event_loop.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use tauri::{AppHandle, Emitter};
1111
use tokio::sync::{Mutex, broadcast};
1212

1313
use super::cache::EVENT_DEBOUNCE_MS;
14-
use super::{MtpConnectionManager, connection_manager};
14+
use super::{MtpConnectionManager, connection_manager, normalize_mtp_path};
1515
use crate::file_system::listing::{get_listings_by_volume_prefix, update_listing_entries};
1616
use crate::file_system::{DirectoryDiff, FileEntry, compute_diff};
1717
use std::path::PathBuf;
@@ -243,10 +243,12 @@ impl MtpConnectionManager {
243243
mtp_path.strip_prefix('/').unwrap_or(&mtp_path).to_string()
244244
};
245245

246-
// Invalidate the MTP listing cache before re-reading so we get fresh data
247-
// (otherwise we'd compare stale cached data with itself and detect no changes)
246+
// Invalidate the MTP listing cache before re-reading so we get fresh data.
247+
// Must use the normalized MTP path (e.g., "/Documents") — not the raw LISTING_CACHE
248+
// path (e.g., "mtp://mtp-device/65537/Documents") — because that's what list_directory
249+
// uses as the cache key.
248250
connection_manager()
249-
.invalidate_listing_cache(device_id, storage_id, &path)
251+
.invalidate_listing_cache(device_id, storage_id, &normalize_mtp_path(&mtp_path))
250252
.await;
251253

252254
// Re-read the directory from the MTP device

0 commit comments

Comments
 (0)