<commit_before>package store

import (
	"encoding/hex"
	"encoding/json"
	"fmt"

	"code.google.com/p/go-sqlite/go1/sqlite3"
	"github.com/endophage/go-tuf/data"
)

const (
	tufLoc      string = "/tmp/tuf"
	objectTable string = "objects"
	repoTable   string = "repositories"
	keysTable   string = "keys"
)

// implements LocalStore
type dbStore struct {
	db    *sqlite3.Conn
	meta  map[string]json.RawMessage
	files map[string]data.FileMeta
	keys  map[string][]*data.Key
}

func DBStore(db *sqlite3.Conn, meta map[string]json.RawMessage) *dbStore {
	if meta == nil {
		meta = make(map[string]json.RawMessage)
	}
	store := dbStore{
		db:    db,
		meta:  meta,
		files: make(map[string]data.FileMeta),
		keys:  make(map[string][]*data.Key),
	}

	return &store
}

// GetMeta loads existing TUF metadata files
func (dbs *dbStore) GetMeta() (map[string]json.RawMessage, error) {
	return dbs.meta, nil
}

// SetMeta writes individual TUF metadata files
func (dbs *dbStore) SetMeta(name string, meta json.RawMessage) error {
	dbs.meta[name] = meta
	return nil
}

// WalkStagedTargets walks all targets in scope
func (dbs *dbStore) WalkStagedTargets(paths []string, targetsFn targetsWalkFunc) error {
	if len(paths) == 0 {
		files := dbs.loadFiles("")
		for path, meta := range files {
			if err := targetsFn(path, meta); err != nil {
				return err
			}
		}
		return nil
	}<commit_msg>dbStore shouldn't store files, it should read them from the db when required<commit_after>package store

import (
	"encoding/hex"
	"encoding/json"
	"fmt"

	"code.google.com/p/go-sqlite/go1/sqlite3"
	"github.com/endophage/go-tuf/data"
)

const (
	tufLoc      string = "/tmp/tuf"
	objectTable string = "objects"
	repoTable   string = "repositories"
	keysTable   string = "keys"
)

// implements LocalStore
type dbStore struct {
	db    *sqlite3.Conn
	meta  map[string]json.RawMessage
	files map[string]data.FileMeta
	keys  map[string][]*data.Key
}

func DBStore(db *sqlite3.Conn, meta map[string]json.RawMessage, keys map[string][]*data.Key) *dbStore {
	if meta == nil {
		meta = make(map[string]json.RawMessage)
	}
	store := dbStore{
		db:   db,
		meta: meta,
		keys: keys,
	}

	return &store
}

// GetMeta loads existing TUF metadata files
func (dbs *dbStore) GetMeta() (map[string]json.RawMessage, error) {
	return dbs.meta, nil
}

// SetMeta writes individual TUF metadata files
func (dbs *dbStore) SetMeta(name string, meta json.RawMessage) error {
	dbs.meta[name] = meta
	return nil
}

// WalkStagedTargets walks all targets in scope
func (dbs *dbStore) WalkStagedTargets(paths []string, targetsFn targetsWalkFunc) error {
	if len(paths) == 0 {
		files := dbs.loadFiles("")
		for path, meta := range files {
			if err := targetsFn(path, meta); err != nil {
				return err
			}
		}
		return nil
	}
{'fraction_non_alphanumeric': 0.12833453496755587, 'fraction_numerical': 0.003604902667627974, 'mean_word_length': 3.911504424778761, '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': '6912675', 'n_tokens_mistral': 1052, 'n_tokens_neox': 1008, 'n_words': 260}