fix(tdesktop): prefer modern key_datas file over legacy 0/1#1754
Merged
Conversation
Telegram Desktop's modern storage layout names the key and account files with an "s" suffix (e.g. key_datas, <hash>s) and may not have the legacy "key_data"/"0"/"1" files at all. session/tdesktop already tried the "s" suffix, but only after "0" and "1", so when both a stale legacy file and the current modern file were present (as happens right after the multi-account migration) it read the stale one. Match Telegram Desktop's ReadFile order by checking the modern "s" file first and only falling back to legacy "0"/"1". Add an end-to-end test that reads a synthetic modern tdata (only "key_datas", no "key_data") and a precedence test asserting the modern file wins over a stale legacy file. Closes #825 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
Fixes #825 — Telegram Desktop's modern storage layout names the key and account files with an
ssuffix (key_datas,<hash>s) and may not contain the legacykey_data/0/1files at all.session/tdesktopalready tried thessuffix, but after0and1. So when both a stale legacy file and the current modern file are present — which happens right after Telegram Desktop's multi-account migration — gotd read the stale legacy file instead of the current one.This matches Telegram Desktop's own
ReadFile, which checks the modernsfile first and only falls back to legacy0/1:Changes
session/tdesktop/file.go: try suffix orders,0,1(modern first).tdesktop_modern_test.go:TestReadFS_Modern— builds a synthetic modern tdata (onlykey_datas, nokey_data) and reads it end-to-end. This is the first end-to-endReadFScoverage and directly reproduces feat(tdesktop): support key_datas #825's layout.TestReadFS_ModernPrecedence— asserts the modernsfile wins over a stale legacy0file (fails on the old ordering, passes with the fix).Testing
go test -race ./session/tdesktop/...passes.🤖 Generated with Claude Code