X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=events.go;h=0921069d2cf21748e6bcd34fae076dff206cc44e;hb=def74ddc09249de9ab72001bb00550863d7f27e6;hp=6fdf1e79b3318052d319878457459d9ca22ccc55;hpb=b2f90fb412218973608b24a32eebadc60de9878a;p=goircd.git diff --git a/events.go b/events.go index 6fdf1e7..0921069 100644 --- a/events.go +++ b/events.go @@ -19,6 +19,7 @@ package main import ( "fmt" + "io/ioutil" "log" "os" "path" @@ -60,7 +61,7 @@ type LogEvent struct { // Logging events logger itself // Each room's events are written to separate file in logdir // Events include messages, topic and keys changes, joining and leaving -func Logger(logdir string, events chan LogEvent) { +func Logger(logdir string, events <-chan LogEvent) { mode := os.O_CREATE | os.O_WRONLY | os.O_APPEND perm := os.FileMode(0660) var format string @@ -93,17 +94,13 @@ type StateEvent struct { // Room state events saver // 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) +func StateKeeper(statedir string, events <-chan StateEvent) { 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() } }