Skip to content

fix(tdesktop): prefer modern key_datas file over legacy 0/1#1754

Merged
ernado merged 1 commit into
mainfrom
fix/825-tdesktop-key-datas
Jun 11, 2026
Merged

fix(tdesktop): prefer modern key_datas file over legacy 0/1#1754
ernado merged 1 commit into
mainfrom
fix/825-tdesktop-key-datas

Conversation

@ernado

@ernado ernado commented Jun 11, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #825 — Telegram Desktop's modern storage layout names the key and account files with an s suffix (key_datas, <hash>s) and may not contain the legacy key_data/0/1 files at all.

session/tdesktop already tried the s suffix, but after 0 and 1. 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 modern s file first and only falls back to legacy 0/1:

const auto modern = base + 's';
if (QFileInfo::exists(modern)) {
    toTry[0] = modern;       // modern takes precedence
} else { /* legacy 0/1 */ }

Changes

  • session/tdesktop/file.go: try suffix order s, 0, 1 (modern first).
  • Added tdesktop_modern_test.go:
    • TestReadFS_Modern — builds a synthetic modern tdata (only key_datas, no key_data) and reads it end-to-end. This is the first end-to-end ReadFS coverage and directly reproduces feat(tdesktop): support key_datas #825's layout.
    • TestReadFS_ModernPrecedence — asserts the modern s file wins over a stale legacy 0 file (fails on the old ordering, passes with the fix).

Testing

go test -race ./session/tdesktop/... passes.

🤖 Generated with Claude Code

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>
@ernado ernado merged commit 4fdbf0b into main Jun 11, 2026
11 of 12 checks passed
@ernado ernado deleted the fix/825-tdesktop-key-datas branch June 11, 2026 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(tdesktop): support key_datas

1 participant