(ctx context.Context, name ResourceName, inputProps map[string]any)
| 364 | } |
| 365 | |
| 366 | func (p *Parser) trackResourceNamesForDataPaths(ctx context.Context, name ResourceName, inputProps map[string]any) error { |
| 367 | c, ok := inputProps["invalidate_on_change"].(bool) |
| 368 | if ok && !c { |
| 369 | return nil |
| 370 | } |
| 371 | path, ok := inputProps["path"].(string) |
| 372 | if !ok { |
| 373 | return nil |
| 374 | } |
| 375 | |
| 376 | var localPaths []string |
| 377 | if fileutil.IsGlob(path) { |
| 378 | entries, err := p.Repo.ListGlob(ctx, path, true) |
| 379 | if err != nil || len(entries) == 0 { |
| 380 | // The actual error will be returned by the model reconciler |
| 381 | return nil |
| 382 | } |
| 383 | |
| 384 | for _, entry := range entries { |
| 385 | localPaths = append(localPaths, entry.Path) |
| 386 | } |
| 387 | } else { |
| 388 | localPaths = []string{normalizePath(path)} |
| 389 | } |
| 390 | |
| 391 | // Update parser's resourceNamesForDataPaths map to track which resources depend on the local file |
| 392 | for _, path := range localPaths { |
| 393 | resources := p.resourceNamesForDataPaths[path] |
| 394 | if !slices.Contains(resources, name) { |
| 395 | resources = append(resources, name) |
| 396 | p.resourceNamesForDataPaths[path] = resources |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | // Calculate hash of local files |
| 401 | hash, err := p.Repo.Hash(ctx, localPaths) |
| 402 | if err != nil { |
| 403 | return err |
| 404 | } |
| 405 | // Add hash to input properties so that the model spec is considered updated when the local file changes |
| 406 | inputProps["local_files_hash"] = hash |
| 407 | return nil |
| 408 | } |
| 409 | |
| 410 | // findLineNumber returns the line number of the pos in the given text. |
| 411 | // Lines are counted starting from 1, and positions start from 0. |
no test coverage detected