Esempio n. 1
0
// NewChatLog instantiates chat logs...
func NewChatLog(path string) (*ChatLog, error) {
	dir := filepath.Dir(path)
	if _, err := os.Stat(dir); err != nil {
		err := os.MkdirAll(dir, 0755)
		if err != nil {
			return nil, err
		}
	}

	if _, err := common.UncompressFile(path); !os.IsNotExist(err) && err != nil {
		log.Printf("error reading log %s %s", path, err)
	}
	f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
	if err != nil {
		return nil, err
	}

	nicks := common.NickList{}
	common.ReadNickList(nicks, nickPath(path))

	return &ChatLog{
		f:        f,
		nicks:    nicks,
		modified: time.Now(),
	}, nil
}
Esempio n. 2
0
func uncompress() error {
	if len(os.Args) < 3 {
		return errors.New("not enough args")
	}
	path := os.Args[2]
	if _, err := common.UncompressFile(path); err != nil {
		return err
	}
	return nil
}