Commit ab98ee8
committed
Bugfix: upsert in
After the previous commit, the SMB watcher and `write_from_stream`'s `notify_mutation` both stat the file and call `notify_directory_changed(Added(entry))`. The watcher's stat fires mid-write and catches a partial size; `write_from_stream`'s fires post-close and gets the final size. `notify_added` used `insert_entry_sorted`, which silently early-returns on duplicate path — so whichever Added landed in the cache first stuck, and the second observation was dropped. Result on MTP→SMB: 3 of 9 files copied with the correct bytes on disk but a cached size frozen at the partial mid-write value, visible in the FE until the user navigated away and back. Confirmed in the log: msg_id 266-269 stat returned `size=2359284` at T+213 ms (file still streaming); msg_id 313+ stat at T+330 ms returned 4989168 (post-Close) but was silently dropped because the path already had an entry.
Fix: `notify_added` now upserts. If `has_entry(listing_id, path)` is true, it routes to `notify_modified` (which updates the entry and emits the right diff type to the FE). Otherwise the existing insert path runs. The semantic — "this entry exists with this state at this point in time" — is the same; the cache now reflects the latest observation rather than the first.
Pinned by `notify_added_upserts_when_entry_already_present` in `caching_test.rs`: two Added calls with the same path and different sizes — final cache must hold the second size. TDD-verified red before the upsert: assertion failed with exactly the partial-size left-over (`Some(2359284)` vs expected `Some(4989168)`).
`notify_added` exposed as `pub(super)` so the test can drive it directly.notify_added so post-write size wins the watcher race1 parent 1dea24e commit ab98ee8
2 files changed
Lines changed: 57 additions & 3 deletions
Lines changed: 18 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
340 | | - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
341 | 352 | | |
342 | 353 | | |
343 | 354 | | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
344 | 360 | | |
345 | | - | |
| 361 | + | |
346 | 362 | | |
347 | 363 | | |
348 | 364 | | |
| |||
Lines changed: 39 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
231 | 269 | | |
232 | 270 | | |
233 | 271 | | |
| |||
0 commit comments