Skip to content
File

Blob: internal/server/storage_identity_unix.go

go38 lines
1//go:build !windows
2 
3package server
4 
5import (
6 "fmt"
7 "os"
8 "path/filepath"
9)
10 
11func publishKVProviderMarker(tempPath, dir string) error {
12 // A hard link publishes the complete, synced marker atomically and never
13 // overwrites an identity established by a concurrent startup.
14 if err := os.Link(tempPath, filepath.Join(dir, kvProviderMarker)); err != nil {
15 return err
16 }
17 if err := os.Remove(tempPath); err != nil {
18 return fmt.Errorf("removing temporary marker: %w", err)
19 }
20 return syncKVProviderIdentity(dir)
21}
22 
23func syncKVProviderIdentity(dir string) error {
24 d, err := os.Open(dir)
25 if err != nil {
26 return fmt.Errorf("opening directory to sync storage identity: %w", err)
27 }
28 syncErr := d.Sync()
29 closeErr := d.Close()
30 if syncErr != nil {
31 return fmt.Errorf("syncing directory for storage identity: %w", syncErr)
32 }
33 if closeErr != nil {
34 return fmt.Errorf("closing directory after syncing storage identity: %w", closeErr)
35 }
36 return nil
37}