1
2
3
4
5 package upki
6
7 import (
8 "internal/syscall/windows"
9 "io"
10 "os"
11 "path/filepath"
12 "syscall"
13 )
14
15 func readFilterFile(path string) ([]byte, error) {
16 f, err := openCacheFile(path)
17 if err != nil {
18 return nil, err
19 }
20 defer f.Close()
21 return io.ReadAll(f)
22 }
23
24
25
26 func openCacheFile(path string) (*os.File, error) {
27 parent, err := os.OpenFile(filepath.Dir(path), os.O_RDONLY|windows.O_DIRECTORY, 0)
28 if err != nil {
29 return nil, err
30 }
31 defer parent.Close()
32
33 handle, err := windows.Openat(
34 syscall.Handle(parent.Fd()),
35 filepath.Base(path),
36 syscall.O_RDONLY|syscall.O_CLOEXEC,
37 0,
38 )
39 if err != nil {
40 return nil, &os.PathError{Op: "open", Path: path, Err: err}
41 }
42
43 return os.NewFile(uintptr(handle), path), nil
44 }
45
View as plain text