Repository navigation
fix(geodata): 下载改用临时文件原子替换并补全流式完整性校验 - #3547
Open
susu-Sugar wants to merge 1 commit into
Open
susu-Sugar wants to merge 1 commit into
susu-Sugar wants to merge 1 commit into
Conversation
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.
修一下 #3543 提到的 geodata 下载中断留下半截文件的问题。
之前
downloadToPath是直接往目标路径写的,也没校验状态码和Content-Length,中途断掉就会在目录里留一个不完整的GeoSite.dat/GeoIP.dat。下次启动因为文件已经存在不会重下,而Verify又只加载CN这一项,只要前面没截断就会误以为文件是好的,等到用到后面的规则才报list not found。改动比较直接:
downloadToPath改成先写同目录下的临时文件,检查 HTTP 200 和Content-Length一致后再 close +os.Rename覆盖,中间出错顺手把临时文件删掉。Verify里加了一遍流式扫描(verifyGeodataStream),按 protobuf entry 长度顺着文件偏移走到末尾,确认没有截断或坏数据,不用把整个文件读进内存。go test ./component/geodata/...通过。Fixes #3543
注:本 PR 借助 AI 辅助编写与排查(模型:Gemini 4 Neon),改动已人工核对并通过本地测试。