Index product paths once during restore planning
This commit is contained in:
@@ -163,6 +163,7 @@ func buildCommittedRestoreActions(
|
||||
return nil, fmt.Errorf("committed remote current state is required")
|
||||
}
|
||||
actions := make([]RestoreAction, 0, len(current.Commit.Artifacts))
|
||||
products := newRestoreProductPaths(current.Manifest)
|
||||
for _, artifact := range current.Commit.Artifacts {
|
||||
rel, include, err := restoreLocalRelativePathForCommittedArtifact(current.SessionPrefix, artifact, opts.IncludeAudio)
|
||||
if err != nil {
|
||||
@@ -171,7 +172,7 @@ func buildCommittedRestoreActions(
|
||||
if artifact.Type == artifacts.RemoteArtifactTypePublishedOutput && current.Manifest != nil {
|
||||
identity, _ := artifacts.ParsePublishedOutputObjectKey(current.SessionPrefix, artifact.DestinationKey)
|
||||
if _, sourceErr := artifactpolicy.ClassifySource(artifact.Source); sourceErr == nil {
|
||||
productPath, productErr := restoreProductRelativePath(cfg, current.Manifest, sessionPaths.Root, artifact.Source)
|
||||
productPath, productErr := products.relativePath(cfg, current.Manifest, sessionPaths.Root, artifact.Source)
|
||||
if productErr != nil && (!strings.HasPrefix(identity.Destination, config.PathAudioDirSegment+"/") || !errors.Is(productErr, errRestoreProductNotFound)) {
|
||||
return nil, fmt.Errorf("map committed source %q: %w", artifact.Source, productErr)
|
||||
}
|
||||
@@ -201,28 +202,41 @@ func buildCommittedRestoreActions(
|
||||
return actions, nil
|
||||
}
|
||||
|
||||
// restoreProductRelativePath takes local product identity from the committed
|
||||
// session evidence; the remote publication destination is only an object key.
|
||||
func restoreProductRelativePath(cfg *config.Config, m *manifest.Manifest, destinationRoot, source string) (string, error) {
|
||||
producerRoot, hasProducerRoot := restoredManifestSessionRoot(m)
|
||||
var paths []string
|
||||
// restoreProductPaths indexes evidence once, retaining duplicates for the
|
||||
// per-source agreement checks. Unselected paths are not validated here.
|
||||
type restoreProductPaths struct {
|
||||
bySource map[string][]string
|
||||
fallback *artifacts.ArtifactCatalog
|
||||
}
|
||||
|
||||
func newRestoreProductPaths(m *manifest.Manifest) *restoreProductPaths {
|
||||
index := &restoreProductPaths{bySource: make(map[string][]string)}
|
||||
if m == nil {
|
||||
return index
|
||||
}
|
||||
for _, record := range m.Stages {
|
||||
if record == nil {
|
||||
continue
|
||||
}
|
||||
for _, output := range record.Outputs {
|
||||
if output.SourceID == source {
|
||||
paths = append(paths, output.LocalPath)
|
||||
}
|
||||
index.bySource[output.SourceID] = append(index.bySource[output.SourceID], output.LocalPath)
|
||||
}
|
||||
for _, artifact := range record.AnalyzeArtifacts {
|
||||
if artifact.Output != nil && artifact.Output.SourceID == source {
|
||||
paths = append(paths, artifact.Output.LocalPath)
|
||||
if artifact.Output != nil {
|
||||
output := artifact.Output
|
||||
index.bySource[output.SourceID] = append(index.bySource[output.SourceID], output.LocalPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
return index
|
||||
}
|
||||
|
||||
// relativePath takes local product identity from the committed session
|
||||
// evidence; the remote publication destination is only an object key.
|
||||
func (index *restoreProductPaths) relativePath(cfg *config.Config, m *manifest.Manifest, destinationRoot, source string) (string, error) {
|
||||
producerRoot, hasProducerRoot := restoredManifestSessionRoot(m)
|
||||
var result string
|
||||
for _, value := range paths {
|
||||
for _, value := range index.bySource[source] {
|
||||
local, err := rebaseRestoredLocalReference("published output", value, producerRoot, hasProducerRoot, destinationRoot)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -242,17 +256,20 @@ func restoreProductRelativePath(cfg *config.Config, m *manifest.Manifest, destin
|
||||
result = rel
|
||||
}
|
||||
if result == "" {
|
||||
catalog := artifacts.NewArtifactCatalog()
|
||||
if err := catalog.RegisterBuiltIns(); err != nil {
|
||||
return "", err
|
||||
if index.fallback == nil {
|
||||
catalog := artifacts.NewArtifactCatalog()
|
||||
if err := catalog.RegisterBuiltIns(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := catalog.RegisterConfiguredArtifacts(artifacts.ConfiguredArtifactDefinitions(cfg.ConcreteArtifacts())); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := catalog.RegisterExtractionArtifacts(artifacts.ExtractionDefinitionsFromConfig(cfg.Pipeline.Notarius)); err != nil {
|
||||
return "", err
|
||||
}
|
||||
index.fallback = catalog
|
||||
}
|
||||
if err := catalog.RegisterConfiguredArtifacts(artifacts.ConfiguredArtifactDefinitions(cfg.ConcreteArtifacts())); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := catalog.RegisterExtractionArtifacts(artifacts.ExtractionDefinitionsFromConfig(cfg.Pipeline.Notarius)); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if entry, ok := catalog.Lookup(source); ok {
|
||||
if entry, ok := index.fallback.Lookup(source); ok {
|
||||
relative, err := artifacts.ProductRelativePath(destinationRoot, entry.CanonicalRelPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
Reference in New Issue
Block a user