【架构优化】从 RestoreWorkspaceCheckpointFrom 中拆出单条目落盘逻辑 restoreCheckpointEntry

Đang mở
#469 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@fx-kurumi đang làm issue này rồi.

Từ ngày 13/11/2026.

  • #470 của @fx-kurumi — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
25/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
go
Lĩnh vực
backend

Hướng nghiên cứu

The work is in RestoreWorkspaceCheckpointFrom in internal/runtime/workspace_checkpoint.go, where the tar loop mixes entry validation with per-type writes for directories, regular files and symlinks. Pull request #470 is already open against this issue, so check it and coordinate before starting any change. Done means the write logic sits in a helper with the signature the issue gives, the existing checkpoint tests still pass, and the new helper has unit tests for each case the issue lists.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

现状问题

internal/runtime/workspace_checkpoint.go 中 RestoreWorkspaceCheckpointFrom 约 90 行,在同一个 tar 读取循环里同时做:条目校验(路径、重复、数量、展开大小)和按类型落盘(目录 / 普通文件 / 软链接)。落盘部分用 var file *os.File + 嵌套 if err == nil 串联,阅读和单测都不方便。

重构方案

把循环内「创建父目录 + 按 header.Typeflag 写入目录/文件/软链接」这一段抽成包内函数
restoreCheckpointEntry(base *os.Root, path string, header *tar.Header, reader io.Reader) error,主循环只保留校验并调用它。

  • 文件模式、O_EXCL、io.CopyN、Sync、Close 错误优先级、软链接注释、unsupported checkpoint entry 报错全部原样保留。

影响范围

仅 internal/runtime/workspace_checkpoint.go 一个函数内部;对外 API、归档格式、报错文案均不变。与 #396/#397(排除路径判断)不重叠。

验证方式

  • 新增 restoreCheckpointEntry 单测(目录/文件/软链接落盘、不支持类型、重复文件不覆盖、文件体截断报错)
  • 现有 checkpoint 相关测试全部通过;gofmt、go vet ./internal/runtime/
Ngôn ngữ chính
Go
Star
141
Fork
28
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
113

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Tencent/LoopForge

Tất cả issue của Tencent/LoopForge

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.