]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Move virFileGetExistingParent out of ifdef __linux__
authorJiri Denemark <jdenemar@redhat.com>
Tue, 3 Jun 2025 09:23:28 +0000 (11:23 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 3 Jun 2025 09:28:15 +0000 (11:28 +0200)
The function is called by virFileIsSharedFSOverride which is not Linux
specific and thus building on anything but Linux failes.

Fixes: 94fb348d670f612c0b58901c9829b4eec81faa50
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/util/virfile.c

index 795f0218b4820d3b56723c76372feacf936ecd78..3b7a795d459addfe2401f833ff0f409d3013f8bd 100644 (file)
@@ -3444,6 +3444,34 @@ virFileRemoveLastComponent(char *path)
         path[0] = '\0';
 }
 
+
+static char *
+virFileGetExistingParent(const char *path)
+{
+    g_autofree char *dirpath = g_strdup(path);
+    char *p = NULL;
+
+    /* Try less and less of the path until we get to a directory we can access.
+     * Even if we don't have 'x' permission on any directory in the path on the
+     * NFS server (assuming it's NFS), we will be able to stat the mount point.
+     */
+    while (!virFileExists(dirpath) && p != dirpath) {
+        if (!(p = strrchr(dirpath, '/'))) {
+            virReportSystemError(EINVAL,
+                                 _("Invalid relative path '%1$s'"), path);
+            return NULL;
+        }
+
+        if (p == dirpath)
+            *(p + 1) = '\0';
+        else
+            *p = '\0';
+    }
+
+    return g_steal_pointer(&dirpath);
+}
+
+
 #ifdef __linux__
 
 # ifndef NFS_SUPER_MAGIC
@@ -3557,33 +3585,6 @@ virFileIsSharedFsFUSE(const char *path,
 }
 
 
-static char *
-virFileGetExistingParent(const char *path)
-{
-    g_autofree char *dirpath = g_strdup(path);
-    char *p = NULL;
-
-    /* Try less and less of the path until we get to a directory we can access.
-     * Even if we don't have 'x' permission on any directory in the path on the
-     * NFS server (assuming it's NFS), we will be able to stat the mount point.
-     */
-    while (!virFileExists(dirpath) && p != dirpath) {
-        if (!(p = strrchr(dirpath, '/'))) {
-            virReportSystemError(EINVAL,
-                                 _("Invalid relative path '%1$s'"), path);
-            return NULL;
-        }
-
-        if (p == dirpath)
-            *(p + 1) = '\0';
-        else
-            *p = '\0';
-    }
-
-    return g_steal_pointer(&dirpath);
-}
-
-
 static const struct virFileSharedFsData virFileSharedFs[] = {
     { .fstype = VIR_FILE_SHFS_NFS, .magic = NFS_SUPER_MAGIC },
     { .fstype = VIR_FILE_SHFS_GFS2, .magic = GFS2_MAGIC },