跳到主要内容

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

浏览文件

storage_unix.go

54 行 · 1.1 KB历史下载
1//go:build !windows
2
3package cage
4
5import (
6 "errors"
7 "os"
8 "path/filepath"
9 "syscall"
10
11 "golang.org/x/sys/unix"
12)
13
14func lockStorageFile(f *os.File, exclusive bool) (bool, error) {
15 mode := unix.LOCK_SH
16 if exclusive {
17 mode = unix.LOCK_EX
18 }
19 err := unix.Flock(int(f.Fd()), mode|unix.LOCK_NB)
20 if errors.Is(err, unix.EWOULDBLOCK) {
21 return false, nil
22 }
23 return err == nil, err
24}
25func linkStorage(link, target string) error { return os.Symlink(target, link) }
26func sparseStorageFile(*os.File) error { return nil }
27
28func storageMountRoot(path string) (bool, error) {
29 fi, err := os.Stat(path)
30 if err != nil {
31 return false, err
32 }
33 parent, err := os.Stat(filepath.Dir(path))
34 if err != nil {
35 return false, err
36 }
37 return fi.Sys().(*syscall.Stat_t).Dev != parent.Sys().(*syscall.Stat_t).Dev, nil
38}
39
40func syncStorageDir(path string) error {
41 f, err := os.Open(path)
42 if err != nil {
43 return err
44 }
45 defer f.Close()
46 return f.Sync()
47}
48
49func renameStorage(from, to string) error {
50 if err := os.Rename(from, to); err != nil {
51 return err
52 }
53 return syncStorageDir(filepath.Dir(to))
54}