跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

legacy.go

61 行 · 1.4 KB历史下载
1package diagnostics
2
3import (
4 "io"
5 "os"
6 "path/filepath"
7)
8
9// ImportLegacy consumes only the old Cage-owned logs. Limit reads so an old
10// unbounded file cannot exhaust memory; omit a partial first line at the tail.
11func (s *Store) ImportLegacy(profile string) error {
12 paths := []string{"control.log", filepath.Join("proxy", "runtime.log"), filepath.Join("proxy", "validation.log"), filepath.Join("state", "setup.log")}
13 for _, relative := range paths {
14 path := filepath.Join(profile, relative)
15 st, err := os.Lstat(path)
16 if os.IsNotExist(err) {
17 continue
18 }
19 if err != nil {
20 return err
21 }
22 if !st.Mode().IsRegular() {
23 continue
24 }
25 if s.now().Sub(st.ModTime()) > s.retention {
26 if err := os.Remove(path); err != nil {
27 return err
28 }
29 continue
30 }
31 f, err := os.Open(path)
32 if err != nil {
33 return err
34 }
35 const limit = 256 << 10
36 if st.Size() > limit {
37 _, _ = f.Seek(st.Size()-limit, io.SeekStart)
38 }
39 r := io.LimitReader(f, limit)
40 if st.Size() > limit { // Discard the cut line before framing secret values.
41 var one [1]byte
42 for {
43 n, e := r.Read(one[:])
44 if n == 0 || e != nil || one[0] == '\n' {
45 break
46 }
47 }
48 }
49 stream := s.Stream("legacy", "warn")
50 _, err = io.Copy(stream, r)
51 _ = stream.Close()
52 f.Close()
53 if err != nil {
54 return err
55 }
56 if err = os.Remove(path); err != nil {
57 return err
58 }
59 }
60 return nil
61}