跳到主要内容

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

浏览文件

cloud_unix.go

52 行 · 1.3 KB历史下载
1//go:build linux || darwin
2
3package reversesshfs
4
5import (
6 "os"
7 "path/filepath"
8 "strings"
9
10 "golang.org/x/sys/unix"
11)
12
13// Start at the volume root, so replacing any component of the picker result
14// with a symlink while the grant is being opened cannot redirect it.
15func openCloudRoot(directory string) (rootedSys, error) {
16 const flags = unix.O_RDONLY | unix.O_DIRECTORY | unix.O_NOFOLLOW | unix.O_CLOEXEC | unix.O_NONBLOCK
17 fd, err := unix.Open("/", flags, 0)
18 if err != nil {
19 return rootedSys{}, err
20 }
21 for _, c := range strings.Split(strings.TrimPrefix(filepath.Clean(directory), "/"), "/") {
22 next, err := unix.Openat(fd, c, flags, 0)
23 unix.Close(fd)
24 if err != nil {
25 return rootedSys{}, err
26 }
27 fd = next
28 }
29 return rootedSys{rootFD: fd}, nil
30}
31
32func (h *rootedHandlers) cloudOpenRead(rel string) (*os.File, error) {
33 parent, base, err := h.openParent(rel)
34 if err != nil {
35 return nil, err
36 }
37 defer unix.Close(parent)
38 fd, err := cloudOpenat(parent, base, unix.O_NOFOLLOW|unix.O_CLOEXEC|unix.O_NONBLOCK|unix.O_RDONLY, 0)
39 if err != nil {
40 return nil, err
41 }
42 var st unix.Stat_t
43 err = unix.Fstat(fd, &st)
44 if err == nil && st.Mode&unix.S_IFMT != unix.S_IFDIR && (st.Mode&unix.S_IFMT != unix.S_IFREG || st.Nlink != 1) {
45 err = errDenied
46 }
47 if err != nil {
48 unix.Close(fd)
49 return nil, err
50 }
51 return os.NewFile(uintptr(fd), rel), nil
52}