feat: Add basic STFS.ReplacesContent PAX record support in indexer
This commit is contained in:
@@ -270,6 +270,22 @@ func indexHeader(record, block int64, hdr *tar.Header, metadataPersister *persis
|
||||
if _, err := metadataPersister.DeleteHeader(context.Background(), hdr.Name, true); err != nil {
|
||||
return err
|
||||
}
|
||||
case pax.STFSReplacesContent:
|
||||
if hdr.PAXRecords[pax.STFSReplacesContent] == pax.STFSReplacesContentTrue {
|
||||
// Metadata & content update
|
||||
// TODO: Add implementation
|
||||
return pax.ErrUnsupportedAction
|
||||
} else {
|
||||
// Metadata-only update
|
||||
dbhdr, err := converters.TarHeaderToDBHeader(record, block, hdr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := metadataPersister.UpdateHeaderMetadata(context.Background(), dbhdr); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
default:
|
||||
return pax.ErrUnsupportedAction
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@ const (
|
||||
STFSRecordAction = "STFS.Action"
|
||||
STFSRecordActionCreate = "CREATE"
|
||||
STFSRecordActionDelete = "DELETE"
|
||||
|
||||
STFSReplacesContent = "STFS.ReplacesContent"
|
||||
STFSReplacesContentTrue = "true"
|
||||
STFSReplacesContentFalse = "false"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -54,6 +54,23 @@ func (p *MetadataPersister) UpsertHeader(ctx context.Context, dbhdr *models.Head
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MetadataPersister) UpdateHeaderMetadata(ctx context.Context, dbhdr *models.Header) error {
|
||||
currentHdr, err := models.FindHeader(ctx, p.db, dbhdr.Name, models.HeaderColumns.Name, models.HeaderColumns.Record, models.HeaderColumns.Block)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Update everything but the record & block
|
||||
dbhdr.Record = currentHdr.Record
|
||||
dbhdr.Block = currentHdr.Block
|
||||
|
||||
if _, err := dbhdr.Update(ctx, p.db, boil.Infer()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MetadataPersister) GetHeaders(ctx context.Context) (models.HeaderSlice, error) {
|
||||
return models.Headers().All(ctx, p.db)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user