Repository navigation
1.3.1: the library loses no item (atomic index.json, restore from item.json) - #20
Merged
Merged
Conversation
index.json was rewritten in place and a failed write was ignored. When it could not be written, the running player still listed every item, but the file kept an older list; the next start loaded only that, and the first change after it made the loss permanent. A write cut short left a broken file and the next start loaded nothing. A bad entry threw out of the start. - index.json and item.json are written to a temporary file and renamed; a failed write is logged. - A bad entry or a broken index.json is logged and skipped, not the rest. - At start every item folder whose item.json is not in index.json is restored from it (logged), and index.json is written again. - A delete removes item.json first, so a half-removed folder stays gone. - deploy/k8s: strategy Recreate (one player per library). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For 1.3.1. Not merged, tagged or released.
Problem
After an upgrade to 1.3.0, a library listed 3 of its 7 items at the first start. Nobody deleted them, and their folders and
item.jsonfiles were still on disk. Nothing was logged.Cause
Library::save_indexrewroteindex.jsonin place withstd::ofstreamand ignored a failed write (src/media.cpp, 1.3.0 line 171).Library::load_indexloads only whatindex.jsonlists.index.jsoncannot be opened for writing (for example a file the player's user may not write), every later write fails without a word. The running player still lists every item in memory, but the file keeps an older list. The next start loads only that list. The first change after the start (a conversion, an upload) then writes the shorter list, so the loss is permanent.load_index, so the player did not start.index.jsondropped the items the other had added.Reproduced with the released images: 1.2.4 with 3 items,
index.jsonmade read-only, then 4 more uploads. 1.2.4 lists 7 andmxl_test_player_library_itemsis 7, butindex.jsonstill lists 3. After a restart on 1.3.0 the library has 3 items, with 7 folders on disk and nothing in the log. The two-pod case was also reproduced: 1.2.4 and 1.3.0 on one directory; after a re-upload to the new pod,index.jsonlists 4.Fix
index.jsonanditem.jsonare written to a unique temporary file and renamed over the old one. A reader or a restart sees the old file or the new one, never part of one. A read-onlyindex.jsonis still replaced. A failed write is logged (ERROR library: …). Invalid UTF-8 no longer throws indump. Allsave_indexcallers already holdmu_; that is now written in a comment.load_index: a bad entry, or anindex.jsonthat is not valid JSON, is logged and skipped, not the rest.item.jsonis not inindex.jsonis restored from thatitem.json. Each one is logged asWARN library: restored <id> (<name>) …, and thenindex.jsonis written again. The start also logsINFO library: N items (M restored from item.json). This brings back items lost this way before 1.3.1.item.jsonfirst, so a folder that cannot be removed completely does not come back.deploy/k8s/deployment.yaml:strategy: Recreate.Tests
New unit test "the library loses no item…" covers a bad entry, a stale index, a cut-off and an empty index, a deleted item that must stay deleted, and a read-only
index.json(the last one is skipped when running as root). On v1.3.0 the test fails (type_error.302thrown out of the constructor). With the fix the test passes, and so does the full suite (37/37). In the lab, the fixed binary on the stale 3-item library from the reproduction starts with 7 items and logs 4 restores.Docs: CHANGELOG
## 1.3.1 (unreleased), SPECIFICATION §6.3, README (PLAYER_LIBRARY_DIR).🤖 Generated with Claude Code
https://claude.ai/code/session_017ybuzgBaGxuB5UiaE8dRa4