返回 DeepSeek-Reasonix
remote_hosts_file_unix.go
根目录 / desktop / remote_hosts_file_unix.go
1 //go:build !windows
2
3 package main
4
5 import (
6 "errors"
7 "fmt"
8 "os"
9
10 "golang.org/x/sys/unix"
11 )
12
13 func openRemoteHostStoreFile(path string) (*os.File, os.FileInfo, error) {
14 fd, err := unix.Open(path, unix.O_RDONLY|unix.O_CLOEXEC|unix.O_NOFOLLOW, 0)
15 if err != nil {
16 if errors.Is(err, unix.ELOOP) {
17 return nil, nil, ErrRemoteHostStoreUnsafe
18 }
19 return nil, nil, err
20 }
21 file := os.NewFile(uintptr(fd), path)
22 info, err := file.Stat()
23 if err != nil {
24 file.Close()
25 return nil, nil, err
26 }
27 return file, info, nil
28 }
29
30 func validateRemoteHostStorePermissions(info os.FileInfo) error {
31 if info.Mode().Perm() != 0o600 {
32 return fmt.Errorf("%w: permissions are %04o, want 0600", ErrRemoteHostStoreUnsafe, info.Mode().Perm())
33 }
34 return nil
35 }
36
36 lines GO