feat: Implement stcache list command
This commit is contained in:
@@ -33,7 +33,7 @@ func NewMetadataPersister(dbPath string) *MetadataPersister {
|
||||
}
|
||||
|
||||
func (c *MetadataPersister) UpsertHeader(ctx context.Context, record, block int64, hdr *tar.Header) error {
|
||||
paxHeaders, err := json.Marshal(hdr.PAXRecords)
|
||||
paxRecords, err := json.Marshal(hdr.PAXRecords)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func (c *MetadataPersister) UpsertHeader(ctx context.Context, record, block int6
|
||||
Changetime: hdr.ChangeTime,
|
||||
Devmajor: hdr.Devmajor,
|
||||
Devminor: hdr.Devminor,
|
||||
Paxrecords: string(paxHeaders),
|
||||
Paxrecords: string(paxRecords),
|
||||
Format: int64(hdr.Format),
|
||||
}
|
||||
|
||||
@@ -77,3 +77,7 @@ func (c *MetadataPersister) UpsertHeader(ctx context.Context, record, block int6
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MetadataPersister) GetHeaders(ctx context.Context) (models.HeaderSlice, error) {
|
||||
return models.Headers().All(ctx, p.db)
|
||||
}
|
||||
|
||||
@@ -16,26 +16,26 @@ type SQLite struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func (d *SQLite) Open() error {
|
||||
func (s *SQLite) Open() error {
|
||||
// Create leading directories for database
|
||||
leadingDir, _ := filepath.Split(d.DBPath)
|
||||
leadingDir, _ := filepath.Split(s.DBPath)
|
||||
if err := os.MkdirAll(leadingDir, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Open the DB
|
||||
db, err := sql.Open("sqlite3", d.DBPath)
|
||||
db, err := sql.Open("sqlite3", s.DBPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Configure the db
|
||||
db.SetMaxOpenConns(1) // Prevent "database locked" errors
|
||||
d.db = db
|
||||
s.db = db
|
||||
|
||||
// Run migrations if set
|
||||
if d.Migrations != nil {
|
||||
if _, err := migrate.Exec(d.db, "sqlite3", d.Migrations, migrate.Up); err != nil {
|
||||
if s.Migrations != nil {
|
||||
if _, err := migrate.Exec(s.db, "sqlite3", s.Migrations, migrate.Up); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user