Exemplo n.º 1
0
func (c *Context) SerializeIndex(index *Index) (err error) {
	var data []byte
	var db *bolt.DB

	if data, err = json.Marshal(index); err != nil {
		return
	}

	db, err = c.OpenDB()
	if err != nil {
		return err
	}
	defer db.Close()

	return db.Update(func(tx *bolt.Tx) error {
		bucket, err := tx.CreateBucketIfNotExists(byteify(IndicesKey))
		if err != nil {
			return err
		}
		if bucket == nil {
			return ErrNoSuchDbBucket
		}
		return bucket.Put(byteify(index.FileId), data)
	})
}
Exemplo n.º 2
0
// New creates a wait queue.
// The bucket will be created if it does not exist. Otherwise,
// the bucket will be deleted and created again.
func NewHeap(db *bolt.DB, bucket []byte, bufsize int) (h *Heap, err error) {
	if err = db.Update(func(tx *bolt.Tx) error {
		if tx.Bucket(bucket) != nil {
			if err := tx.DeleteBucket(bucket); err != nil {
				return err
			}
		}
		if _, err := tx.CreateBucketIfNotExists(bucket); err != nil {
			return err
		}
		return nil

	}); err != nil {
		db.Close()
		return
	}
	h = &Heap{
		db:       db,
		count:    0,
		min:      nil,
		writebuf: list.New(),
		bufsize:  bufsize,
		bucket:   bucket,
	}
	return
}
Exemplo n.º 3
0
// tearDownBoltDB closes and deletes boltdb
func tearDownBoltDB(db *bolt.DB) error {
	p := db.Path()
	err := db.Close()
	if err != nil {
		return err
	}

	return os.Remove(p)
}
Exemplo n.º 4
0
// closedb closes and deletes a ReportifyDB database.
func closedb(db *bolt.DB) {
	if db == nil {
		return
	}
	path := db.Path()
	db.Close()
	if path != "" {
		os.Remove(path)
	}
}
Exemplo n.º 5
0
func Run(cfg config.Config) (err error) {
	var db *bolt.DB
	db, err = bolt.Open(cfg.DatabasePath, 0600, &bolt.Options{Timeout: cfg.Timeout})
	if err != nil {
		return err
	}
	defer func() {
		if err == nil {
			err = db.Close()
		} else {
			db.Close()
		}
	}()
	return nil
}
Exemplo n.º 6
0
		db, err = GetDB(pth)
		Expect(err).To(BeNil())

		u = NewUser(
			"inspector",
			UserPassword("abc123bs"),
			UserPermission("write"),
			UserDB(db),
		)
		_, err = u.Save()
		Expect(err).To(BeNil())
	})

	AfterEach(func() {
		db.Close()
		os.RemoveAll(dir)
	})

	It("can save", func() {
		u2 := NewUser("inspector", UserDB(db))
		Expect(u2.Fetch()).To(BeNil())
		Expect(u2.Password).To(Equal(""))
		Expect(len(u2.HashedPassword)).ToNot(Equal(0))
		Expect(u2.Permission).To(Equal("write"))
	})

	It("can delete", func() {
		err := u.Delete()
		Expect(err).To(BeNil())
		u2 := NewUser("inspector", UserDB(db))
Exemplo n.º 7
0
func closeAndRemove(db *bolt.DB, filename string) {
	db.Close()
	removeFile(filename)
}
Exemplo n.º 8
0
func closePageDatabase(db *bolt.DB) {
	if db != nil {
		db.Close()
		db = nil
	}
}
Exemplo n.º 9
0
func clean_bolt(db *bolt.DB) {
	db.Close()
	os.Remove(db.Path())
}
Exemplo n.º 10
0
func closeDB(db *bolt.DB) {
	db.Close()
	if err := os.Remove(getDBPath()); err != nil {
		panic(err)
	}
}