SIGN IN SIGN UP

fix: match the root at a path component boundary when transforming paths

The root transformer used a plain string prefix comparison to determine
whether a path is contained in the (from) root. A path that shares a
textual prefix with the root but lies outside it was therefore treated as
being under the root and rewritten, corrupting the path.

For a root of /run/nvidia/driver and a target root of /host:

	/run/nvidia/driver-backup/lib.so -> /host/-backup/lib.so
	/run/nvidia/driverfoo            -> /host/foo

Both paths are outside the root and must be left unchanged.

The prefix match is now required to end at a path component boundary. A
path equal to the root, and a root with a trailing separator (including a
root of /), are handled as before.

This applies to both the host and container root transformers since they
share transformPath, and is reachable from
'nvidia-ctk cdi transform root --from/--to' as well as from the driver
root transform applied during CDI spec generation.

Signed-off-by: Vyncint Ng <115854244+vyncint@users.noreply.github.com>
V
Vyncint Ng committed
60691e995bd2d9bbc1bc671a4bd235f98543b1a5
Parent: 5eee4c5