pub fn resolve_reference(
from: &Utf8Path,
reference: &str,
) -> Option<Utf8PathBuf>Expand description
Resolve a recipe reference to a path relative to the collection root.
reference is the reference as the recipe writes it — ./Shared/Sauce,
../sauces/tomato. The parser only produces one from a name starting ./
or ../, so it always opens with a dot component and can never be an
absolute path of its own.
A reference that steps up does so from the directory of the file that
writes it; one that does not is read from the collection root. That is
not a new rule for the second half: ./ has always meant the root here,
and the shipped seed relies on it — Breakfast/Mexican Style Burrito.cook
writes @./Shared/Red Beans and means Shared/Red Beans.cook at the root,
not one beside itself. .. had no working meaning at all before this: it
was resolved from the root like everything else, so ../sauces/tomato
landed outside the collection whatever wrote it.
from is that writer’s directory, relative to the root and empty for a
recipe sitting at it. It is ours, not a request’s: an entry path with the
base directory stripped off.
Returns None for a reference that still climbs above the root, or that
normalises to something is_safe_relative_path refuses — a reference is
free to spell @./C:/Windows/win.ini{}, and joining that to the recipe
directory would drop the directory. Neither names a recipe in the
collection, so callers report them the way they report one that is missing.