mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:30:52 +01:00
[PR #2075] tools/hashdict: write --out atomically, use shared report_paths guard, and accept UTF-8 BOM in --lookup (HASHDICT-ATOMIC-JSON-AND-PATH-GUARD) #2081
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2081
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2075
Author: @KushGene
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/hashdict-atomic-json-path-guard📝 Commits (2)
1ca436ctools/hashdict: write --out atomically, use shared report_paths guard, and accept UTF-8 BOM in --lookup (HASHDICT-ATOMIC-JSON-AND-PATH-GUARD)48b2141tests/test_hashdict: check directory entries instead of alias existence on folding volumes📊 Changes
2 files changed (+144 additions, -17 deletions)
View changed files
📝
tests/test_hashdict.py(+87 -0)📝
tools/hashdict.py(+57 -17)📄 Description
Claimed in the coordination issue as: HASHDICT-ATOMIC-JSON-AND-PATH-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7172506299)
What and why
Hardens
tools/hashdict.pyoutput handling and--lookupinput decoding without changing output bytes:--outwrites: Writes JSON through a sibling temporary file (tempfile.mkstemp(..., prefix=".hashdict-", suffix=".json")), preserves permissions withfile_mode.published_mode, and swaps viareplace_retry.replace, cleaning up the temp file on failure so an interrupted or failing write no longer truncates an existing dictionary.--outvalidation & shared path guard: Refuses empty/whitespace-only and directory--outpaths before scanning inputs or creating parent directories, and checks--extraandindex.jsoninputs withreport_paths.same_report_path(catching case-only aliases on case-folding volumes even when--outdoes not exist yet).--lookup: Opens--lookupdictionaries withutf-8-sig(matching the existingindex.jsonreader inhashdict.py), so dictionaries saved with a BOM by Windows PowerShell 5.1 / Notepad are accepted cleanly.tests/test_hashdict.py(test_write_failure_preserves_existing_output_and_leaves_no_temp_file,test_out_rejects_empty_and_directory_paths,test_out_refuses_case_only_input_alias_on_folding_volume,test_lookup_accepts_utf8_bom_dictionary).Tested
tests/test_hashdict.pyfailed againstmain(e18b59a5b) before the fix (existingouttruncated tob''onjson.dumperror, whitespace--outaccepted, case-only alias written, UTF-8 BOM rejected).python3 -I tests/test_hashdict.py: 47/47 passed.python3 -I tests/test_text_write_line_endings.py: 3/3 passed.python3 -I tests/test_report_paths.py: 22/22 passed.python3 -I scripts/check_no_game_data.py tools/hashdict.py tests/test_hashdict.py: exit 0.python3 -m compileall -q make_game.py tools tests: exit 0.GPUs tested: n/a (CPU-only Python tool and unit tests on Fedora Linux 45)
AI-assisted: yes (Antigravity)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.