daemon: sysroot: Avoid double-/ when creating sysroot paths in OCaml

Previously calling 'sysroot_path "/dev"' for example would return the
string "/sysroot//dev".  While this is not wrong, it confuses some
external programs (hello, setfiles), and it's not very "clean".  Be a
bit more careful to avoid doubling the '/' character in the common case.
This commit is contained in:
Richard W.M. Jones
2025-08-12 13:04:45 +01:00
committed by rwmjones
parent 06db19c56c
commit 1e0099671a
2 changed files with 6 additions and 2 deletions

View File

@@ -20,4 +20,8 @@ open Std_utils
external sysroot : unit -> string = "guestfs_int_daemon_sysroot"
let sysroot_path path = sysroot () // path
let sysroot_path path =
let sysroot = sysroot () in
if path = "" then sysroot
else if path.[0] = '/' then sysroot ^ path
else sysroot // path

View File

@@ -22,4 +22,4 @@ val sysroot : unit -> string
in default. *)
val sysroot_path : string -> string
(** Equivalent to calling [sysroot () // path] *)
(** Prepend [path] parameter with the sysroot. *)