Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/common/loki/positions/write_positions_windows.go
4096 views
1
//go:build windows
2
3
package positions
4
5
// This code is copied from Promtail. The positions package allows logging
6
// components to keep track of read file offsets on disk and continue from the
7
// same place in case of a restart.
8
9
import (
10
"os"
11
"path/filepath"
12
13
yaml "gopkg.in/yaml.v2"
14
)
15
16
// writePositionFile is a fallback for Windows because renameio does not support Windows.
17
// See https://github.com/google/renameio#windows-support
18
func writePositionFile(filename string, positions map[Entry]string) error {
19
buf, err := yaml.Marshal(File{
20
Positions: positions,
21
})
22
if err != nil {
23
return err
24
}
25
26
target := filepath.Clean(filename)
27
temp := target + "-new"
28
29
err = os.WriteFile(temp, buf, os.FileMode(positionFileMode))
30
if err != nil {
31
return err
32
}
33
34
return os.Rename(temp, target)
35
}
36
37