Source file src/crypto/internal/upki/index_open_windows.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     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  // windows.Openat shares delete access so a cache producer can replace the
    25  // index or remove an obsolete filter while a check is reading it.
    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