Skip to content
File

Blob: cmd/server/storage_identity_windows.go

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