跳到主要内容

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

浏览文件

cacheutil.go

61 行 · 1.7 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package cacheutil
5
6import (
7 "context"
8 "fmt"
9 "path"
10
11 "github.com/lima-vm/lima/v2/pkg/downloader"
12 "github.com/lima-vm/lima/v2/pkg/fileutils"
13 "github.com/lima-vm/lima/v2/pkg/limatype"
14)
15
16// NerdctlArchive returns the basename of the archive.
17func NerdctlArchive(y *limatype.LimaYAML) string {
18 if *y.Containerd.System || *y.Containerd.User {
19 for _, f := range y.Containerd.Archives {
20 if f.Arch == *y.Arch {
21 return path.Base(f.Location)
22 }
23 }
24 }
25 return ""
26}
27
28// EnsureNerdctlArchiveCache prefetches the nerdctl-full-VERSION-GOOS-GOARCH.tar.gz archive
29// into the cache before launching the hostagent process, so that we can show the progress in tty.
30// https://github.com/lima-vm/lima/issues/326
31func EnsureNerdctlArchiveCache(ctx context.Context, y *limatype.LimaYAML, created bool) (string, error) {
32 if !*y.Containerd.System && !*y.Containerd.User {
33 // nerdctl archive is not needed
34 return "", nil
35 }
36
37 errs := make([]error, len(y.Containerd.Archives))
38 for i, f := range y.Containerd.Archives {
39 // Skip downloading again if the file is already in the cache
40 if created && f.Arch == *y.Arch && !downloader.IsLocal(f.Location) {
41 path, err := fileutils.CachedFile(f)
42 if err == nil {
43 return path, nil
44 }
45 }
46 path, err := fileutils.DownloadFile(ctx, "", f, false, "the nerdctl archive", *y.Arch, nil)
47 if err != nil {
48 errs[i] = err
49 continue
50 }
51 if path == "" {
52 if downloader.IsLocal(f.Location) {
53 return f.Location, nil
54 }
55 return "", fmt.Errorf("cache did not contain %#q", f.Location)
56 }
57 return path, nil
58 }
59
60 return "", fileutils.Errors(errs)
61}