<commit_before>package collaboration

import (
	"os"
	"os/user"
	"path/filepath"
	"time"

	"github.com/boltdb/bolt"
)

const (
	UserBucket = "users"
	// Canonical database path is `$HOME + DatabasePath`
	DatabasePath = "/.config/koding/klient.bolt"
)

// NewBoltStorage returns a new boltdb
func NewBoltStorage() (*boltdb, error) {
	d := &boltdb{}

	// Ensure data directory exists.
	u, err := user.Current()
	if err != nil {
		return nil, err
	}
	boltPath := u.HomeDir + DatabasePath
	if err := os.MkdirAll(filepath.Dir(boltPath), 0755); err != nil {
		return nil, err
	}

	if err := d.open(boltPath); err != nil {
		return nil, err
	}

	return d, nil
}

// boltdb satisfies Storage interface
type boltdb struct {
	*bolt.DB
}

func (b *boltdb) open(dbpath string) error {
	var err error
	b.DB, err = bolt.Open(dbpath, 0644, &bolt.Options{Timeout: 1 * time.Second})
	if err != nil {
		return err
	}

	return b.Update(func(tx *Tx) error {
		_, err := tx.CreateBucketIfNotExists([]byte(UserBucket))
		if err != nil {
			return err
		}
		return nil
	})
}

// Get returns the value of a given username
func (b *boltdb) Get(username string) (string, error) {
	var user string

	err := b.View(func(tx *Tx) error {
		value := tx.User(username)
		if len(value) == 0 {
			return ErrUserNotFound
		}
		user = value
		return nil
	})

	if err != nil {<commit_msg>klient: Increase bolt timeout to 5 secs.<commit_after>package collaboration

import (
	"os"
	"os/user"
	"path/filepath"
	"time"

	"github.com/boltdb/bolt"
)

const (
	UserBucket = "users"
	// Canonical database path is `$HOME + DatabasePath`
	DatabasePath = "/.config/koding/klient.bolt"
)

// NewBoltStorage returns a new boltdb
func NewBoltStorage() (*boltdb, error) {
	d := &boltdb{}

	// Ensure data directory exists.
	u, err := user.Current()
	if err != nil {
		return nil, err
	}
	boltPath := u.HomeDir + DatabasePath
	if err := os.MkdirAll(filepath.Dir(boltPath), 0755); err != nil {
		return nil, err
	}

	if err := d.open(boltPath); err != nil {
		return nil, err
	}

	return d, nil
}

// boltdb satisfies Storage interface
type boltdb struct {
	*bolt.DB
}

func (b *boltdb) open(dbpath string) error {
	var err error
	b.DB, err = bolt.Open(dbpath, 0644, &bolt.Options{Timeout: 5 * time.Second})
	if err != nil {
		return err
	}

	return b.Update(func(tx *Tx) error {
		_, err := tx.CreateBucketIfNotExists([]byte(UserBucket))
		if err != nil {
			return err
		}
		return nil
	})
}

// Get returns the value of a given username
func (b *boltdb) Get(username string) (string, error) {
	var user string

	err := b.View(func(tx *Tx) error {
		value := tx.User(username)
		if len(value) == 0 {
			return ErrUserNotFound
		}
		user = value
		return nil
	})

	if err != nil {
{'fraction_non_alphanumeric': 0.1392451447416636, 'fraction_numerical': 0.007695126419934042, 'mean_word_length': 3.3610223642172525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '971403', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1011, 'n_words': 294}