bcacheup: use nixstore.Open
This commit is contained in:
parent
d6118944fa
commit
75b39cfbf7
4 changed files with 32 additions and 4 deletions
|
@ -31,7 +31,6 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
blobURLFlag = flag.String("cache_url", "", "Cache URL")
|
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.")
|
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 {
|
type uploader struct {
|
||||||
bucket *blob.Bucket
|
bucket *blob.Bucket
|
||||||
store *nixstore.DB
|
store nixstore.Store
|
||||||
storePath string
|
storePath string
|
||||||
st stateTracker
|
st stateTracker
|
||||||
|
|
||||||
|
@ -421,7 +420,7 @@ func main() {
|
||||||
}
|
}
|
||||||
defer bucket.Close()
|
defer bucket.Close()
|
||||||
|
|
||||||
store, err := nixstore.Open(*storeDBFlag)
|
store, err := nixstore.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("opening Nix store: %v", err)
|
log.Fatalf("opening Nix store: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,13 @@ depot.third_party.buildGo.package {
|
||||||
name = "nixstore";
|
name = "nixstore";
|
||||||
path = "hg.lukegb.com/lukegb/depot/go/nix/nixstore";
|
path = "hg.lukegb.com/lukegb/depot/go/nix/nixstore";
|
||||||
srcs = [
|
srcs = [
|
||||||
|
./nixstore.go
|
||||||
|
./remotestore.go
|
||||||
./sqlitestore.go
|
./sqlitestore.go
|
||||||
];
|
];
|
||||||
deps = with depot; [
|
deps = with depot; [
|
||||||
go.nix.nar.narinfo
|
go.nix.nar.narinfo
|
||||||
|
go.nix.nixwire
|
||||||
third_party.gopkgs."github.com".mattn.go-sqlite3
|
third_party.gopkgs."github.com".mattn.go-sqlite3
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
26
go/nix/nixstore/nixstore.go
Normal file
26
go/nix/nixstore/nixstore.go
Normal 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)
|
||||||
|
}
|
|
@ -119,7 +119,7 @@ func (d *DB) Close() error {
|
||||||
return d.db.Close()
|
return d.db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Open(dbPath string) (*DB, error) {
|
func OpenDB(dbPath string) (*DB, error) {
|
||||||
sqlDB, err := sql.Open("sqlite3", dbPath)
|
sqlDB, err := sql.Open("sqlite3", dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in a new issue