]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virpcimock: Strip fakerootdir prefix in virFileCanonicalizePath()
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 11 Jun 2025 11:19:32 +0000 (13:19 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 2 Jul 2025 11:54:00 +0000 (13:54 +0200)
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 <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/virpcimock.c

index 34128d5516bcf5e3cb8e4d077ed9645b4f01ea28..4eff6d70e32f60a7ead9b210bd1ec6002b9b2da6 100644 (file)
@@ -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"