registrar_windows.go 435 Bytes
Newer Older
1 2 3 4 5
package main

import (
  "encoding/json"
  "log"
6
  "os"
7 8 9 10 11 12
)

func WriteRegistry(state map[string]*FileState, path string) {
  tmp := path + ".new"
  file, err := os.Create(tmp)
  if err != nil {
13
    log.Printf("Failed to open .logstash-forwarder.new for writing: %s\n", err)
14 15 16 17 18 19 20 21 22 23 24
    return
  }

  encoder := json.NewEncoder(file)
  encoder.Encode(state)
  file.Close()

  old := path + ".old"
  os.Rename(path, old)
  os.Rename(tmp, path)
}