Esempio n. 1
0
//CheckData makes a record from res and checks its records meets condisions of args.
//adds the rec to cache if meets conditions.
//if spam or big data, remove the rec from disk.
//returns spam/getting error.
func (c *Cache) CheckData(tx *bolt.Tx, res string, stamp int64,
	id string, begin, end int64) error {
	r := record.New(c.Datfile, "", 0)
	if errr := r.Parse(res); errr != nil {
		return cfg.ErrGet
	}
	exist, err := db.HasKey(tx, "record", r.Head.ToKey())
	if err != nil {
		log.Println(err)
	}
	if exist {
		return nil
	}
	if !r.Meets(begin, end) {
		return cfg.ErrGet
	}
	deleted := false
	if len(r.Recstr()) > cfg.RecordLimit<<10 || r.IsSpam() {
		log.Printf("warning:%s/%s:too large or spam record", r.Datfile, r.Idstr())
		deleted = true
	}
	err = r.SyncTX(tx, deleted)
	if err != nil {
		return err
	}
	if deleted {
		return cfg.ErrSpam
	}
	return nil
}
Esempio n. 2
0
//Exists return true is datapath exists.
func (c *Cache) Exists() bool {
	var cnt bool
	err := db.DB.View(func(tx *bolt.Tx) error {
		var err error
		cnt, err = db.HasKey(tx, "thread", []byte(c.Datfile))
		return err
	})
	if err != nil {
		log.Println(err)
	}
	return cnt
}
Esempio n. 3
0
//Exists return true if record file exists.
func (u *Head) Exists() bool {
	var r bool
	err := db.DB.View(func(tx *bolt.Tx) error {
		var err error
		r, err = db.HasKey(tx, "record", u.ToKey())
		return err
	})
	if err != nil {
		log.Print(err)
		return false
	}
	return r
}
Esempio n. 4
0
//SyncTX saves Recstr to the file. if attached file exists, saves it to attached path.
//if signed, also saves body part.
func (r *Record) SyncTX(tx *bolt.Tx, deleted bool) error {
	has, err := db.HasKey(tx, "record", r.Head.ToKey())
	if err != nil {
		log.Println(err)
	}
	if has {
		return nil
	}
	d := DB{
		Head:    r.Head,
		Body:    r.bodystr(),
		Deleted: deleted,
	}
	return d.Put(tx)
}