Beispiel #1
0
func (t *SinceDB) Open(dbdir string) (err error) {
	if err = t.Close(); err != nil {
		return
	}
	t.dbdir = dbdir
	if !futil.IsExist(t.dbdir) {
		if err = os.MkdirAll(t.dbdir, 0755); err != nil {
			return
		}
	}
	fis, err := ioutil.ReadDir(t.dbdir)
	if err != nil {
		return
	}
	for _, fi := range fis {
		if fi.IsDir() {
			continue
		}
		name := fi.Name()
		path := filepath.Join(dbdir, fi.Name())
		sincefile, err := NewSinceFile(path)
		if err != nil {
			return err
		}
		t.SinceMap[name] = sincefile
	}
	return
}
Beispiel #2
0
func (self *InputConfig) LoadSinceDBInfos() (err error) {
	var (
		raw []byte
	)
	log.Debug("LoadSinceDBInfos")
	self.SinceDBInfos = map[string]*SinceDBInfo{}

	if self.SinceDBPath == "" || self.SinceDBPath == "/dev/null" {
		log.Warnf("No valid sincedb path")
		return
	}

	if !futil.IsExist(self.SinceDBPath) {
		log.Debugf("sincedb not found: %q", self.SinceDBPath)
		return
	}

	if raw, err = ioutil.ReadFile(self.SinceDBPath); err != nil {
		log.Errorf("Read sincedb failed: %q\n%s", self.SinceDBPath, err)
		return
	}

	if err = json.Unmarshal(raw, &self.SinceDBInfos); err != nil {
		log.Errorf("Unmarshal sincedb failed: %q\n%s", self.SinceDBPath, err)
		return
	}

	return
}
Beispiel #3
0
func (t *SinceFile) Open(filepath string) (err error) {
	if err = t.Close(); err != nil {
		return
	}

	if !futil.IsExist(filepath) {
		if err = ioutil.WriteFile(filepath, make([]byte, 32), 0644); err != nil {
			return
		}
	}

	if t.mmfile, err = mmfile.Open(filepath); err != nil {
		return
	}

	t.Since = (*time.Time)(unsafe.Pointer(&t.mmfile.Data()[0]))

	return
}