Пример #1
0
//Remove Remove all files and dirs of cache.
func (c *Cache) Remove() {
	err := db.DB.Update(func(tx *bolt.Tx) error {
		r, err := record.GetFromDBs(tx, c.Datfile)
		if err != nil {
			return err
		}
		for _, rr := range r {
			rr.Del(tx)
		}
		return db.Del(tx, "thread", []byte(c.Datfile))
	})
	if err != nil {
		log.Println(err)
	}
}
Пример #2
0
//Prune removes Sugtaglists which are not listed in recs,
//or truncates its size to tagsize if listed.
func Prune(recs []*record.Head) {
	tmp := keys()
	for _, r := range recs {
		if l := util.FindString(tmp, r.Datfile); l != -1 {
			tmp = append(tmp[:l], tmp[l+1:]...)
		}
	}
	err := db.DB.Update(func(tx *bolt.Tx) error {
		for _, datfile := range tmp {
			err := db.Del(tx, "sugtag", []byte(datfile))
			if err != nil {
				return err
			}
		}
		return nil
	})
	if err != nil {
		log.Println(err)
	}
}
Пример #3
0
//Set remove all tags and saves tag strings.
func Set(thread string, tag []string) {
	err := db.DB.Update(func(tx *bolt.Tx) error {
		ts, err := db.GetMap(tx, "usertag", []byte(thread))
		if err != nil {
			log.Println(err)
		}
		for t := range ts {
			err = db.DelMap(tx, "usertagTag", []byte(t), thread)
			if err != nil {
				return err
			}
		}
		if err := db.Del(tx, "usertag", []byte(thread)); err != nil {
			log.Println(err)
		}
		return AddTX(tx, thread, tag)
	})
	if err != nil {
		log.Print(err)
	}
}
Пример #4
0
//RemoveFromAllTable removes node n from all tables and return true if exists.
//or returns false if not exists.
func RemoveFromAllTable(n *node.Node) bool {
	err := db.DB.Update(func(tx *bolt.Tx) error {
		threads, err := db.GetMap(tx, "lookupA", []byte(n.Nodestr))
		if err != nil {
			return err
		}
		err = db.Del(tx, "lookupA", []byte(n.Nodestr))
		if err != nil {
			return err
		}
		for t := range threads {
			err := db.DelMap(tx, "lookupT", []byte(t), n.Nodestr)
			if err != nil {
				return err
			}
		}
		return nil
	})
	if err != nil {
		log.Println(err)
		return false
	}
	return true
}
Пример #5
0
//Del deletes data from db.
func (d *DB) Del(tx *bolt.Tx) {
	if err := db.Del(tx, "record", d.Head.ToKey()); err != nil {
		log.Println(err)
	}
}