Commit f002606
committed
Read MTP files in bounded windows so the device session is free between reads
Reworks the MTP read path from one held-open `GetObject` (which holds the single PTP session for the whole file) into a sequence of bounded ~8 MiB `download_partial_64` transactions, each acquiring + releasing the per-device lock. Between windows nothing is in flight and the session is free — the foundation for letting a foreground listing interleave during a transfer (the yield wiring comes next).
- `MtpReadSession` (`mtp/connection/file_ops.rs`): `open_read_session` resolves the handle + `Storage` + total size ONCE; `read_window` does only `acquire_device_lock` + `download_partial_64(handle, offset, len)` per window. Neither takes a `foreground_guard` — a transfer is a background user of the device gate, so raising `foreground_pending` would make it yield to itself.
- `MtpReadStream` (`volume/backends/mtp.rs`) caches the session and reads bounded windows: `next_chunk` clamps each window to the bytes remaining (`mtp_window_len`), advances the offset by the bytes actually returned, ends cleanly at EOF, and treats a 0-byte read before EOF as a transient error (not a frozen-progress spin). `cancel_and_release` is now a near-noop (nothing held between windows; a dropped mid-window read self-heals via mtp-rs `TransactionScope`).
- Reworks the SHARED `MtpReadStream`, so native drag-out gets bounded windows for free; the single-file `download_mtp_file` command is routed through the same `read_window` and loses its whole-file `foreground_guard`. Retires `open_download_stream_at_offset` + the `FileDownload`-wrapping internals.
- Window size is the named `MTP_READ_WINDOW` (8 MiB, the throughput-vs-yield-latency knob; tuned on real hardware later).
- Proactively fixed the pre-existing `virtual-mtp` tests' device-id derivation (built `mtp-{location_id}`, which never matches the serial-derived id, so they couldn't connect in isolation).
Real red→green: byte-exact multi-window assembly, EOF short-final-window, empty-file/offset==total → None, zero-before-EOF → error, short-mid-file advance, cancel keeps-partials. `pnpm check rust` green.1 parent 7a1e57c commit f002606
9 files changed
Lines changed: 715 additions & 232 deletions
File tree
- apps/desktop/src-tauri/src
- file_system/volume
- backends
- mtp/connection
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
| 185 | + | |
186 | 186 | | |
187 | | - | |
| 187 | + | |
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
192 | 192 | | |
193 | | - | |
| 193 | + | |
| 194 | + | |
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
197 | | - | |
| 198 | + | |
198 | 199 | | |
199 | 200 | | |
200 | 201 | | |
| |||
Lines changed: 7 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
Lines changed: 3 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 102 | + | |
| 103 | + | |
108 | 104 | | |
109 | 105 | | |
110 | 106 | | |
| |||
0 commit comments