From: Michal Privoznik <mprivozn(a)redhat.com>
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(a)redhat.com>
---
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.49.0