github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/clients/pkg/promtail/positions/write_positions_windows.go (about)

     1  //go:build windows
     2  // +build windows
     3  
     4  package positions
     5  
     6  import (
     7  	"io/ioutil"
     8  	"os"
     9  	"path/filepath"
    10  
    11  	yaml "gopkg.in/yaml.v2"
    12  )
    13  
    14  // writePositionFile is a fall back for Windows because renameio does not support Windows.
    15  // See https://github.com/google/renameio#windows-support
    16  func writePositionFile(filename string, positions map[string]string) error {
    17  	buf, err := yaml.Marshal(File{
    18  		Positions: positions,
    19  	})
    20  	if err != nil {
    21  		return err
    22  	}
    23  
    24  	target := filepath.Clean(filename)
    25  	temp := target + "-new"
    26  
    27  	err = ioutil.WriteFile(temp, buf, os.FileMode(positionFileMode))
    28  	if err != nil {
    29  		return err
    30  	}
    31  
    32  	return os.Rename(temp, target)
    33  }