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, each as a global string replacement over the result of the rules before it, so a later rule can rewrite what an earlier rule produced. Callers should keep rule source paths non-overlapping to avoid 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 DetectSourceFormat ¶ added in v0.2.0
DetectSourceFormat returns the OpenJD pathmapping source-path-format enum for path p: "WINDOWS" when p contains a backslash or starts with a drive-letter prefix (e.g. "C:"), "POSIX" otherwise.
The heuristic mirrors detectPathFormat in internal/scheduler/assign.go and is used by the staging package to populate SourcePathFormat on staging-produced PathMapRules so that the written path_mapping.json is valid against the OpenJD pathmapping-1.0 schema (which requires "POSIX" or "WINDOWS").
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 (including one this function wrote earlier in the session: see internal/worker/executor's buildEffectiveLookup, which rewrites this file once staging rules are known) is replaced via writeSecure rather than a plain os.WriteFile. The root daemon writes this file at a deterministic name, at points that can run after job code has executed as the target uid (the rewrite runs after the environment onEnter action), so an open-by-path could be redirected by a hardlink or symlink swap. writeSecure refuses to write through any pre-existing entry that was not put there by this call, on every platform; see its per-OS doc comment for the mechanism.
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 NewLookup ¶ added in v0.2.0
func NewLookup(rules []protocol.PathMapRule) (*Lookup, error)
NewLookup is an alias for Parse, named for call sites that build a Lookup from a combined (e.g. staging-prepended) rule slice.
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.
func (*Lookup) CommandFlags ¶ added in v0.2.0
CommandFlags renders pattern once per rule with a non-empty SourcePath, replacing {src} with SourcePath and {dest} with DestinationPath, and returns the rendered strings in rule order. Rules with an empty SourcePath are skipped.