74 lines
2.8 KiB
Go
74 lines
2.8 KiB
Go
package engine
|
|
|
|
import "go.maximumdirect.net/configkit/internal/document"
|
|
|
|
// capturedHostSource contains immutable, passive facts about one selected file.
|
|
type capturedHostSource struct {
|
|
document *document.Node
|
|
bytes int64
|
|
mainPath string
|
|
basePath string
|
|
rootPath string
|
|
}
|
|
|
|
// selectInputSource shares discovery and post-selection option checks with
|
|
// preparation and ordinary acquisition.
|
|
func selectInputSource(source Source, sourceID string, context *FilesystemContext) (Source, *SourceInfo, []Diagnostic) {
|
|
if source.kind != sourceSearch {
|
|
return source, nil, nil
|
|
}
|
|
selected, failed, diagnostics := resolveSearchInput(source, sourceID, defaultDiscoveryDirectoryHelpers(), defaultDiscoveryHostProbe())
|
|
if len(diagnostics) != 0 {
|
|
return selected, failed, diagnostics
|
|
}
|
|
if context != nil {
|
|
if diagnostics := filesystemOptionDiagnostics(selected, context); len(diagnostics) != 0 {
|
|
return selected, nil, diagnostics
|
|
}
|
|
}
|
|
return selected, nil, nil
|
|
}
|
|
|
|
// captureHostMain snapshots a selected host document and canonical context.
|
|
// Diagnostics retain the same source evidence as ordinary acquisition.
|
|
func captureHostMain(source Source, context *FilesystemContext) (Source, []SourceInfo, []Diagnostic) {
|
|
const sourceID = "source-1"
|
|
if source.kind != sourceFile && source.kind != sourceSearch && source.kind != sourceNone {
|
|
return Source{}, nil, []Diagnostic{optionDiagnostic(CodeOptionsInvalid, "main preparation requires a host file, search, or absent source")}
|
|
}
|
|
if context != nil {
|
|
if context.FS != nil {
|
|
return Source{}, nil, []Diagnostic{optionDiagnostic(CodeOptionsInvalid, "main preparation requires a host filesystem context")}
|
|
}
|
|
if diagnostics := filesystemOptionDiagnostics(source, context); len(diagnostics) != 0 {
|
|
return Source{}, nil, diagnostics
|
|
}
|
|
}
|
|
selected, failed, diagnostics := selectInputSource(source, sourceID, context)
|
|
if len(diagnostics) != 0 {
|
|
return Source{}, sourceInfos(failed), diagnostics
|
|
}
|
|
if selected.kind == sourceNone {
|
|
if context != nil {
|
|
_, diagnostic := validateFilesystemContext(selected, context, parsedSource{}, nil)
|
|
if diagnostic != nil {
|
|
return Source{}, nil, []Diagnostic{*diagnostic}
|
|
}
|
|
}
|
|
return selected, nil, nil
|
|
}
|
|
parsed, diagnostics := parseSource(selected, sourceID, defaultParseLimits())
|
|
if len(diagnostics) != 0 {
|
|
return Source{}, sourceInfos(parsed.source), diagnostics
|
|
}
|
|
resolved, diagnostic := validateFilesystemContext(selected, context, parsed, nil)
|
|
if diagnostic != nil {
|
|
return Source{}, sourceInfos(parsed.source), []Diagnostic{*diagnostic}
|
|
}
|
|
selected.captured = &capturedHostSource{
|
|
document: parsed.document, bytes: parsed.bytes, mainPath: resolved.mainPath,
|
|
basePath: resolved.basePath, rootPath: resolved.rootPath,
|
|
}
|
|
return selected, sourceInfos(parsed.source), nil
|
|
}
|