registrar_other.go 452 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
// +build !windows

package main
import (
  "encoding/json"
  "os"
  "log"
)

func WriteRegistry(state map[string]*FileState, path string) {
  // Open tmp file, write, flush, rename
  file, err := os.Create(".lumberjack.new")
  if err != nil {
    log.Printf("Failed to open .lumberjack.new for writing: %s\n", err)
    return
  }
  defer file.Close()

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

  os.Rename(".lumberjack.new", path)
}