From: Michal Privoznik Date: Wed, 11 Jun 2025 11:19:32 +0000 (+0200) Subject: virpcimock: Strip fakerootdir prefix in virFileCanonicalizePath() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21e7bcc14fae7eca97cf738669ac73bed496ad2f;p=thirdparty%2Flibvirt.git virpcimock: Strip fakerootdir prefix in virFileCanonicalizePath() The mocked implementation of virFileCanonicalizePath() redirects accesses to few dirs into a temporary directory, where PCI related files live. See getrealpath() for more info on this. Anyway, in the end - real implementation of virFileCanonicalizePath() is called which then might contain the 'fakerootdir' prefix. Up until now this did not matter because none of our test really cared about actual value of resolved path. They usually cared about last component of the path or something. But this will soon change. TLDR - if the returned path has $fakerootdir prefix, strip it. Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 34128d5516..4eff6d70e3 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -1184,13 +1184,23 @@ char * virFileCanonicalizePath(const char *path) { g_autofree char *newpath = NULL; + char *ret = NULL; init_syms(); if (getrealpath(&newpath, path) < 0) return NULL; - return real_virFileCanonicalizePath(newpath); + ret = real_virFileCanonicalizePath(newpath); + + if (ret && fakerootdir && STRPREFIX(ret, fakerootdir)) { + size_t len = strlen(ret); + size_t preflen = strlen(fakerootdir); + + memmove(ret, ret + preflen, len - preflen + 1); + } + + return ret; } # include "virmockstathelpers.c"