Sync quality: files downloaded in the old format are not re-fetched when the setting is the default #1

Open
opened 2026-11-20 15:52:12 +00:00 by mai · 0 comments
Owner

Summary

The documented contract for setSyncQuality (lib/data/repositories/playlist/song_downloader.dart:651) states: "files already stored in the old format are re-fetched in the new one, so the offline library ends up in the format the user asked for." On Android this does not hold for the default value (compressed). Setting Compressed when it is already selected does nothing; only toggling Original → Compressed re-fetches.

Reproduction (Android, observed)

  1. A client downloaded songs as original files (under best, or before the setting existed).
  2. Open Settings → Local Synchronization. The toggle is on Compressed — the default (defaultSyncQuality, song_downloader.dart:112).
  3. Tap Compressed. The files stay original — no re-fetch.
  4. Tap Original, then Compressed. The files are deleted and re-fetched as mp3-320.

Root cause

The format comparison (_formatMatches, song_downloader.dart:1496) runs only inside _update(), which is reached only through update(). Two paths block it:

  1. init() (song_downloader.dart:289-370) marks every existing library file as downloaded (lines 324-346) with no format check, and does not run a sync pass. On startup, files in the old format are accepted as-is.
  2. setSyncQuality (song_downloader.dart:655) returns early when the value is unchanged: if (_syncQuality == quality) return ok. Since the default is compressed, tapping Compressed when it is already selected is a no-op — update(true) is never called, so _update() never compares the stored task URLs against the wanted format.

The stored format key is read from the task record's URL (downloadFormatKeyOfUri, download_format.dart:75), so the comparison itself is the real, safe gate: it leaves files already in the wanted format untouched and refetches only the ones that do not match. The early-return is what defeats it.

Fix

  1. setSyncQuality: drop the same-value early-return. Store the value, set _syncQuality, and run update(true) unconditionally. The format comparison is idempotent, so setting the same value is safe (matching files are left alone) and it refetches the old-format files.
  2. init(): after the library is marked and the in-flight tasks are tracked (the end of init, before notifyListeners), run update(true) so a default-compressed client refetches files downloaded in the old format on startup. This closes the upgrade case.

Tests to add

In test/data/repositories/playlist/song_downloader_test.dart, mirroring the existing harness (makeSong, keyValue, repo, the downloadUriFor assertions at lines 741-775):

  • setSyncQuality(compressed) when the in-memory value is already compressed runs update(true) and re-fetches a task whose stored URL is /rest/download as /rest/stream?format=mp3&maxBitRate=320.
  • init() on a tree whose task records are original and whose stored quality is absent (default compressed) re-fetches them as the transcode.

Device proof (Android emulator)

Build a fork-signed APK from the worktree (copy android/key.properties from the shared clone; apksigner verify --print-certs must show CN=Crossonic Fork), install over the existing install on the emulator, and prove:

  • With the toggle set to Compressed, a FLAC favorite downloads as an mp3, not the original.
  • Switching to Compressed from a tree of original-format files deletes them and refetches as mp3.
  • The app's own log (log_message in crossonic_database.sqlite, read via adb exec-out tar) shows the delete + re-enqueue lines for the old-format files.

Acceptance criteria

  • Gate green: flutter analyze 0 errors, flutter test all pass, the two new tests present.
  • On the emulator, setting Compressed on a tree of original-format files refetches them as mp3-320.
  • The fix lands on dev and the next beta publishes.
## Summary The documented contract for `setSyncQuality` (`lib/data/repositories/playlist/song_downloader.dart:651`) states: *"files already stored in the old format are re-fetched in the new one, so the offline library ends up in the format the user asked for."* On Android this does **not** hold for the default value (`compressed`). Setting **Compressed** when it is already selected does nothing; only toggling **Original → Compressed** re-fetches. ## Reproduction (Android, observed) 1. A client downloaded songs as **original** files (under `best`, or before the setting existed). 2. Open Settings → Local Synchronization. The toggle is on **Compressed** — the default (`defaultSyncQuality`, `song_downloader.dart:112`). 3. Tap **Compressed**. The files stay original — no re-fetch. 4. Tap **Original**, then **Compressed**. The files are deleted and re-fetched as mp3-320. ## Root cause The format comparison (`_formatMatches`, `song_downloader.dart:1496`) runs only inside `_update()`, which is reached only through `update()`. Two paths block it: 1. **`init()` (`song_downloader.dart:289-370`)** marks every existing library file as `downloaded` (lines 324-346) **with no format check**, and does **not** run a sync pass. On startup, files in the old format are accepted as-is. 2. **`setSyncQuality` (`song_downloader.dart:655`)** returns early when the value is unchanged: `if (_syncQuality == quality) return ok`. Since the default is `compressed`, tapping Compressed when it is already selected is a no-op — `update(true)` is never called, so `_update()` never compares the stored task URLs against the wanted format. The stored format key is read from the task record's URL (`downloadFormatKeyOfUri`, `download_format.dart:75`), so the comparison itself is the real, safe gate: it leaves files already in the wanted format untouched and refetches only the ones that do not match. The early-return is what defeats it. ## Fix 1. **`setSyncQuality`**: drop the same-value early-return. Store the value, set `_syncQuality`, and run `update(true)` unconditionally. The format comparison is idempotent, so setting the same value is safe (matching files are left alone) and it refetches the old-format files. 2. **`init()`**: after the library is marked and the in-flight tasks are tracked (the end of `init`, before `notifyListeners`), run `update(true)` so a default-`compressed` client refetches files downloaded in the old format on startup. This closes the upgrade case. ## Tests to add In `test/data/repositories/playlist/song_downloader_test.dart`, mirroring the existing harness (`makeSong`, `keyValue`, `repo`, the `downloadUriFor` assertions at lines 741-775): - `setSyncQuality(compressed)` when the in-memory value is already `compressed` runs `update(true)` and re-fetches a task whose stored URL is `/rest/download` as `/rest/stream?format=mp3&maxBitRate=320`. - `init()` on a tree whose task records are `original` and whose stored quality is absent (default `compressed`) re-fetches them as the transcode. ## Device proof (Android emulator) Build a fork-signed APK from the worktree (copy `android/key.properties` from the shared clone; `apksigner verify --print-certs` must show `CN=Crossonic Fork`), install over the existing install on the emulator, and prove: - With the toggle set to **Compressed**, a FLAC favorite downloads as an mp3, not the original. - Switching to **Compressed** from a tree of original-format files deletes them and refetches as mp3. - The app's own log (`log_message` in `crossonic_database.sqlite`, read via `adb exec-out tar`) shows the delete + re-enqueue lines for the old-format files. ## Acceptance criteria - Gate green: `flutter analyze` 0 errors, `flutter test` all pass, the two new tests present. - On the emulator, setting Compressed on a tree of original-format files refetches them as mp3-320. - The fix lands on `dev` and the next beta publishes.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
mai/crossonic#1
No description provided.