Carry resolved filesystem facts through loads
This commit is contained in:
@@ -7,62 +7,18 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func contextsForAcquiredSources(source Source, context *FilesystemContext, baseSource *SourceInfo, sources []SourceInfo) (map[string]ResourceContext, *Diagnostic) {
|
||||
func contextsForResolvedSources(resolved *resolvedFilesystemContext, sources []SourceInfo) (map[string]ResourceContext, *Diagnostic) {
|
||||
if len(sources) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
var rootPath, basePath string
|
||||
var filesystem fs.FS
|
||||
if source.kind == sourceFilesystem {
|
||||
filesystem = source.namespace.filesystem
|
||||
rootPath, basePath = ".", path.Dir(source.path)
|
||||
if context != nil && context.Root != "" {
|
||||
rootPath = context.Root
|
||||
}
|
||||
} else if context != nil && context.FS != nil {
|
||||
filesystem = context.FS.namespace.filesystem
|
||||
rootPath, basePath = context.Root, context.BaseDir
|
||||
} else if source.kind == sourceFile {
|
||||
filePath := source.path
|
||||
if baseSource != nil {
|
||||
filePath = baseSource.Path
|
||||
} else {
|
||||
canonical, err := canonicalExistingPath(filePath)
|
||||
if err != nil {
|
||||
value := importDiagnostic(CodeImportInvalid, "selected source could not be canonicalized", nil)
|
||||
return nil, &value
|
||||
}
|
||||
filePath = canonical
|
||||
}
|
||||
basePath = filepath.Dir(filePath)
|
||||
rootPath = basePath
|
||||
if context != nil && context.Root != "" {
|
||||
canonical, err := canonicalExistingPath(context.Root)
|
||||
if err != nil {
|
||||
value := importDiagnostic(CodeImportInvalid, "configuration root could not be canonicalized", nil)
|
||||
return nil, &value
|
||||
}
|
||||
rootPath = canonical
|
||||
}
|
||||
} else if context != nil {
|
||||
var err error
|
||||
rootPath, err = canonicalExistingPath(context.Root)
|
||||
if err != nil {
|
||||
value := importDiagnostic(CodeImportInvalid, "configuration root could not be canonicalized", nil)
|
||||
return nil, &value
|
||||
}
|
||||
if source.kind == sourceNone && context.BaseDir == "" {
|
||||
basePath = rootPath
|
||||
} else {
|
||||
basePath, err = canonicalExistingPath(context.BaseDir)
|
||||
if err != nil {
|
||||
value := importDiagnostic(CodeImportInvalid, "import base directory could not be canonicalized", nil)
|
||||
return nil, &value
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if resolved == nil {
|
||||
return nil, nil
|
||||
}
|
||||
rootPath, basePath := resolved.rootPath, resolved.basePath
|
||||
var filesystem fs.FS
|
||||
if resolved.native != nil {
|
||||
filesystem = resolved.native.filesystem
|
||||
}
|
||||
var rooted fs.FS
|
||||
if filesystem != nil {
|
||||
rooted = rootedNativeFS{filesystem: filesystem, root: rootPath}
|
||||
@@ -81,7 +37,7 @@ func contextsForAcquiredSources(source Source, context *FilesystemContext, baseS
|
||||
}
|
||||
var relative string
|
||||
if filesystem != nil {
|
||||
if !fs.ValidPath(rootPath) || !fs.ValidPath(base) || rootPath != "." && base != rootPath && !strings.HasPrefix(base, rootPath+"/") {
|
||||
if !containsNativePath(rootPath, base) {
|
||||
value := importDiagnostic(CodeImportOutsideRoot, "source base is outside the configuration root", nil)
|
||||
return nil, &value
|
||||
}
|
||||
@@ -110,6 +66,30 @@ func contextsForAcquiredSources(source Source, context *FilesystemContext, baseS
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// contextsForAcquiredSources is retained for selected-overlay callers until
|
||||
// their request migration. Input acquisition resolves the facts at its own
|
||||
// lifecycle boundary and uses contextsForResolvedSources directly.
|
||||
func contextsForAcquiredSources(source Source, context *FilesystemContext, baseSource *SourceInfo, sources []SourceInfo) (map[string]ResourceContext, *Diagnostic) {
|
||||
if len(sources) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
if source.kind == sourceNone {
|
||||
if context == nil {
|
||||
return nil, nil
|
||||
}
|
||||
resolved, diagnostic := resolveAbsentFilesystemContext(context)
|
||||
if diagnostic != nil {
|
||||
return nil, diagnostic
|
||||
}
|
||||
return contextsForResolvedSources(&resolved, sources)
|
||||
}
|
||||
resolved, diagnostic := resolveFilesystemContext(source, context, parsedSource{source: baseSource}, nil)
|
||||
if diagnostic != nil {
|
||||
return nil, diagnostic
|
||||
}
|
||||
return contextsForResolvedSources(&resolved, sources)
|
||||
}
|
||||
|
||||
func mergeResourceContexts(target *map[string]ResourceContext, incoming map[string]ResourceContext) {
|
||||
if len(incoming) == 0 {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user