bcacheup: use nixstore.Open

This commit is contained in:
Luke Granger-Brown 2022-10-10 00:49:44 +01:00
parent d6118944fa
commit 75b39cfbf7
4 changed files with 32 additions and 4 deletions

View file

@ -31,7 +31,6 @@ import (
var (
blobURLFlag = flag.String("cache_url", "", "Cache URL")
storeDBFlag = flag.String("nix_store_db", nixstore.DefaultStoreDB, "Path to the nix store database")
stateSummaryIntervalFlag = flag.Duration("state_summary_interval", 10*time.Second, "Time between state summary outputs.")
)
@ -156,7 +155,7 @@ func (t *stateTracker) StateSummary() string {
type uploader struct {
bucket *blob.Bucket
store *nixstore.DB
store nixstore.Store
storePath string
st stateTracker
@ -421,7 +420,7 @@ func main() {
}
defer bucket.Close()
store, err := nixstore.Open(*storeDBFlag)
store, err := nixstore.Open()
if err != nil {
log.Fatalf("opening Nix store: %v", err)
}

View file

@ -7,10 +7,13 @@ depot.third_party.buildGo.package {
name = "nixstore";
path = "hg.lukegb.com/lukegb/depot/go/nix/nixstore";
srcs = [
./nixstore.go
./remotestore.go
./sqlitestore.go
];
deps = with depot; [
go.nix.nar.narinfo
go.nix.nixwire
third_party.gopkgs."github.com".mattn.go-sqlite3
];
}

View file

@ -0,0 +1,26 @@
package nixstore
import (
"fmt"
"hg.lukegb.com/lukegb/depot/go/nix/nar/narinfo"
)
type Store interface {
NARInfo(storePath string) (*narinfo.NarInfo, error)
Close() error
}
func Open() (Store, error) {
s, errDmn := OpenDaemon(DaemonSock)
if errDmn == nil {
return s, nil
}
s2, errDB := OpenDB(DefaultStoreDB)
if errDB == nil {
return s2, nil
}
return nil, fmt.Errorf("failed to open daemon or DB: %v / %v", errDmn, errDB)
}

View file

@ -119,7 +119,7 @@ func (d *DB) Close() error {
return d.db.Close()
}
func Open(dbPath string) (*DB, error) {
func OpenDB(dbPath string) (*DB, error) {
sqlDB, err := sql.Open("sqlite3", dbPath)
if err != nil {
return nil, err