Skip to content
File

Blob: internal/server/storage_identity_windows.go

go38 lines
1package server
2 
3import (
4 "fmt"
5 "os"
6 "path/filepath"
7 
8 "golang.org/x/sys/windows"
9)
10 
11func publishKVProviderMarker(tempPath, dir string) error {
12 from, err := windows.UTF16PtrFromString(tempPath)
13 if err != nil {
14 return err
15 }
16 to, err := windows.UTF16PtrFromString(filepath.Join(dir, kvProviderMarker))
17 if err != nil {
18 return err
19 }
20 // Windows does not support syncing a read-only directory handle. Publish
21 // the synced file with a write-through move, without replacing any marker
22 // established by a concurrent startup.
23 return windows.MoveFileEx(from, to, windows.MOVEFILE_WRITE_THROUGH)
24}
25 
26func syncKVProviderIdentity(dir string) error {
27 // FlushFileBuffers requires a writable file handle on Windows.
28 f, err := os.OpenFile(filepath.Join(dir, kvProviderMarker), os.O_RDWR, 0)
29 if err != nil {
30 return fmt.Errorf("opening storage identity to sync: %w", err)
31 }
32 defer f.Close()
33 if err := f.Sync(); err != nil {
34 return fmt.Errorf("syncing storage identity: %w", err)
35 }
36 return nil
37}