跳到主要内容

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

浏览文件

joliet.go

71 行 · 1.8 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package iso9660util
5
6import (
7 "context"
8 "fmt"
9 "io"
10 "os"
11 "os/exec"
12 "path/filepath"
13 "runtime"
14
15 "github.com/sirupsen/logrus"
16)
17
18func writeJoliet(isoPath, label string, layout []Entry) error {
19 if err := os.RemoveAll(isoPath); err != nil {
20 return err
21 }
22 tmpDir, err := os.MkdirTemp("", "joliet")
23 if err != nil {
24 return err
25 }
26 defer os.RemoveAll(tmpDir)
27 for _, entry := range layout {
28 path := filepath.Join(tmpDir, entry.Path)
29 if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
30 return err
31 }
32 f, err := os.Create(path)
33 if err != nil {
34 return err
35 }
36 if _, err := io.Copy(f, entry.Reader); err != nil {
37 f.Close()
38 return err
39 }
40 f.Close()
41 }
42
43 ctx := context.TODO()
44 cmdSlice, err := writeJolietCommand(isoPath, label, tmpDir)
45 if err != nil {
46 return err
47 }
48 cmd := exec.CommandContext(ctx, cmdSlice[0], cmdSlice[1:]...)
49 logrus.Debugf("Executing %v", cmd.Args)
50 b, err := cmd.CombinedOutput()
51 if err != nil {
52 return fmt.Errorf("failed to run %v: %w (output=%#q)", cmd.Args, err, string(b))
53 }
54 return nil
55}
56
57func writeJolietCommand(isoPath, label, workDir string) ([]string, error) {
58 if runtime.GOOS == "darwin" {
59 return []string{"hdiutil", "makehybrid", "-o", isoPath, "-iso", "-joliet", "-default-volume-name", label, workDir}, nil
60 }
61 candidates := []string{"xorrisofs", "genisoimage", "mkisofs"}
62 for _, cmd := range candidates {
63 if cmdAbs, err := exec.LookPath(cmd); err == nil {
64 if cmd == "xorrisofs" {
65 return []string{cmdAbs, "-o", isoPath, "--norock", "-J", "-V", label, workDir}, nil
66 }
67 return []string{cmdAbs, "-o", isoPath, "-J", "-V", label, workDir}, nil
68 }
69 }
70 return nil, fmt.Errorf("none of %v is available", candidates)
71}