Documentation
¶
Overview ¶
Package pathmap implements resolved-mode path substitution for sqi-worker.
In resolved mode the server sends an ordered list of source→destination path rules alongside a task assignment. The worker uses those rules to:
- Validate that every rule has a concrete destination path.
- Apply string substitution to the task command and argument strings, replacing every occurrence of a source path with its destination path before launching the OS process.
- Write the standard OpenJD path_mapping.json file into the session working directory so that applications with native OpenJD path-mapping support can translate internally referenced paths without additional integration.
Lookup ¶
A Lookup wraps the ordered slice of protocol.PathMapRule values and exposes Lookup.Apply for string substitution and Lookup.ApplyToAction for substituting across a full protocol.Action (command + args).
Ordering ¶
Rules are applied in declaration order. If a command string contains a source path that matches multiple rules the first matching rule wins for any given starting position — but because each rule is applied as a global string replacement in turn, the caller should ensure rule source paths are non-overlapping prefix/path pairs to avoid unexpected chained substitutions.
Empty path map ¶
An empty or nil PathMap is valid; Parse returns a non-nil, empty Lookup and nil error. Calling Lookup.Apply or Lookup.ApplyToAction on an empty Lookup is a no-op that returns the input unchanged.
Index ¶
Constants ¶
const PathMappingFileName = "path_mapping.json"
PathMappingFileName is the name of the OpenJD path mapping file written to each session working directory.
const PathMappingVersion = "pathmapping-1.0"
PathMappingVersion is the OpenJD path-mapping schema version emitted in the "version" field of the path_mapping.json envelope.
Variables ¶
This section is empty.
Functions ¶
func WritePathMappingFile ¶
func WritePathMappingFile(workDir string, rules []protocol.PathMapRule) error
WritePathMappingFile serializes rules as JSON and writes them to <workDir>/path_mapping.json.
The file is the OpenJD pathmapping-1.0 envelope: a top-level object with a "version" field set to PathMappingVersion and a "path_mapping_rules" array of objects carrying "source_path_format", "source_path", and "destination_path" keys. Applications with native OpenJD support read this file to translate internally referenced paths without additional integration.
If rules is empty, no file is written (an empty path map carries no mapping information and applications should treat a missing file as equivalent to an empty map).
The file is written with mode 0644 (world-readable). An existing file at the path is overwritten (open with O_TRUNC semantics via os.WriteFile).
Types ¶
type Lookup ¶
type Lookup struct {
// contains filtered or unexported fields
}
Lookup is an ordered list of source-path → destination-path pairs derived from an protocol.AssignMsg's PathMap field.
Create a Lookup via Parse. The zero value is safe to use and behaves as an empty lookup (no substitutions).
func Parse ¶
func Parse(rules []protocol.PathMapRule) (*Lookup, error)
Parse validates and converts rules into a Lookup.
It returns a non-nil error if any rule with a non-empty SourcePath has an empty DestinationPath, identifying the offending source path so operators can diagnose a misconfigured storage location.
Rules where both SourcePath and DestinationPath are empty are accepted silently — they carry no mapping information and Lookup.Apply skips them.
An empty or nil rules slice is valid; Parse returns a non-nil empty Lookup and nil error.
func (*Lookup) Apply ¶
Apply performs resolved-mode path substitution on s.
Each rule's SourcePath is replaced with its DestinationPath, globally, in declaration order. A source path that appears more than once in s is replaced every time. Rules with an empty SourcePath are skipped.
If the Lookup is nil or empty, s is returned unchanged.
func (*Lookup) ApplyToAction ¶
ApplyToAction returns a copy of action with [Apply] applied to action.Command and each element of action.Args.
The original action is not modified. If action is nil or the Lookup has no rules, action is returned unchanged.