package state func FindCatalogOutputByPath(outputs []CatalogOutputFile, path string) (CatalogOutputFile, bool) { for _, output := range outputs { if output.Path == path { return output, true } } return CatalogOutputFile{}, false } func CatalogOutputsForOwner(outputs []CatalogOutputFile, scope OwnerScope) []CatalogOutputFile { selected := make([]CatalogOutputFile, 0, len(outputs)) for _, output := range outputs { if output.PipelineID == scope.PipelineID && output.DestinationID == scope.DestinationID { selected = append(selected, output) } } return selected } func CatalogManagedOutputPaths(s CatalogState) []string { paths := make([]string, 0, len(s.Outputs)) for _, output := range s.Outputs { paths = append(paths, output.Path) } return paths } func RemoveMissingCatalogOwnerOutputs(s CatalogState, scope OwnerScope, missingPaths []string) (CatalogState, bool) { if len(missingPaths) == 0 { return s, false } missing := pathSet(missingPaths) next := s next.Outputs = make([]CatalogOutputFile, 0, len(s.Outputs)) changed := false for _, output := range s.Outputs { if output.PipelineID == scope.PipelineID && output.DestinationID == scope.DestinationID { if _, remove := missing[output.Path]; remove { changed = true continue } } next.Outputs = append(next.Outputs, output) } return next, changed } func RemoveMissingCatalogOutputs(s CatalogState, missingPaths []string) (CatalogState, bool) { if len(missingPaths) == 0 { return s, false } missing := pathSet(missingPaths) next := s next.Outputs = make([]CatalogOutputFile, 0, len(s.Outputs)) changed := false for _, output := range s.Outputs { if _, remove := missing[output.Path]; remove { changed = true continue } next.Outputs = append(next.Outputs, output) } return next, changed } func pathSet(paths []string) map[string]struct{} { set := make(map[string]struct{}, len(paths)) for _, path := range paths { set[path] = struct{}{} } return set }