跳到主要内容

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

浏览文件

rooted_darwin.go

60 行 · 1.7 KB历史下载
1package reversesshfs
2
3import (
4 "github.com/pkg/sftp"
5 "golang.org/x/sys/unix"
6)
7
8func statVFS(st *unix.Statfs_t) *sftp.StatVFS {
9 return &sftp.StatVFS{
10 Bsize: uint64(st.Bsize),
11 Frsize: uint64(st.Bsize),
12 Blocks: st.Blocks,
13 Bfree: st.Bfree,
14 Bavail: st.Bavail,
15 Files: st.Files,
16 Ffree: st.Ffree,
17 Favail: st.Ffree,
18 Flag: uint64(st.Flags),
19 Namemax: 255, // APFS and HFS+ names are at most 255 UTF-16 code units
20 }
21}
22
23// renameNoReplace renames, failing with EEXIST when the new path exists, atomically.
24func renameNoReplace(oldfd int, oldBase string, newfd int, newBase string) error {
25 return unix.RenameatxNp(oldfd, oldBase, newfd, newBase, unix.RENAME_EXCL)
26}
27
28// fchmodatNoFollow never follows a symlink at base, and fails on one, as on Linux.
29// If base is replaced by a symlink after the check, fchmodat changes the mode of the symlink itself.
30func fchmodatNoFollow(dirfd int, base string, mode uint32) error {
31 var st unix.Stat_t
32 if err := unix.Fstatat(dirfd, base, &st, unix.AT_SYMLINK_NOFOLLOW); err != nil {
33 return err
34 }
35 if st.Mode&unix.S_IFMT == unix.S_IFLNK {
36 return unix.ELOOP
37 }
38 return unix.Fchmodat(dirfd, base, mode, unix.AT_SYMLINK_NOFOLLOW)
39}
40
41// Open each component without following links and keep the client on the
42// selected volume. Truncation is deferred until the descriptor is checked.
43func cloudOpenat(fd int, name string, flags int, mode uint32) (int, error) {
44 next, err := unix.Openat(fd, name, flags, mode)
45 if err != nil {
46 return -1, err
47 }
48 var parent, child unix.Stat_t
49 if err = unix.Fstat(fd, &parent); err == nil {
50 err = unix.Fstat(next, &child)
51 }
52 if err == nil && parent.Dev != child.Dev {
53 err = unix.EXDEV
54 }
55 if err != nil {
56 unix.Close(next)
57 return -1, err
58 }
59 return next, nil
60}