X-Git-Url: http://www.git.cypherpunks.ru/?p=goircd.git;a=blobdiff_plain;f=events.go;h=0921069d2cf21748e6bcd34fae076dff206cc44e;hp=95760e8a6ceeaf0efe139c5d3e8d295d685c7b13;hb=41f96494948d1f9f1e0c3066099e0bd9ad0ee8dd;hpb=c1d256aaa0af4e0cb3649552e5067a9ec3bc94d5 diff --git a/events.go b/events.go index 95760e8..0921069 100644 --- a/events.go +++ b/events.go @@ -19,6 +19,7 @@ package main import ( "fmt" + "io/ioutil" "log" "os" "path" @@ -94,16 +95,12 @@ type StateEvent struct { // Room states shows that either topic or key has been changed // Each room's state is written to separate file in statedir func StateKeeper(statedir string, events <-chan StateEvent) { - mode := os.O_CREATE | os.O_TRUNC | os.O_WRONLY - perm := os.FileMode(0660) for event := range events { - state_path := path.Join(statedir, event.where) - fd, err := os.OpenFile(state_path, mode, perm) + fn := path.Join(statedir, event.where) + data := event.topic + "\n" + event.key + "\n" + err := ioutil.WriteFile(fn, []byte(data), os.FileMode(0660)) if err != nil { - log.Println("Can not open statefile", state_path, err) - continue + log.Printf("Can not write statefile %s: %v", fn, err) } - fd.WriteString(event.topic + "\n" + event.key + "\n") - fd.Close() } }