From 21e7bcc14fae7eca97cf738669ac73bed496ad2f Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Wed, 11 Jun 2025 13:19:32 +0200 Subject: [PATCH] virpcimock: Strip fakerootdir prefix in virFileCanonicalizePath() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- tests/virpcimock.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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" -- 2.47.3