]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: file: Use more obvious logic in virFindFileInPath
authorPeter Krempa <pkrempa@redhat.com>
Thu, 14 Nov 2019 09:16:54 +0000 (10:16 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 14 Nov 2019 14:50:43 +0000 (15:50 +0100)
Make it more obvious that the function will return NULL if the file is
not executable and stop reusing variables.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virfile.c

index 072a299b3932b2c5ff6bb38e2fe25e14f466687b..c7620e49d56154dfccb891b069164f0a8c687764 100644 (file)
@@ -1645,19 +1645,23 @@ virFindFileInPath(const char *file)
      * copy of that path, after validating that it is executable
      */
     if (IS_ABSOLUTE_FILE_NAME(file)) {
-        char *ret = NULL;
-        if (virFileIsExecutable(file))
-            ret = g_strdup(file);
-        return ret;
+        if (!virFileIsExecutable(file))
+            return NULL;
+
+        return g_strdup(file);
     }
 
     /* If we are passed an anchored path (containing a /), then there
      * is no path search - it must exist in the current directory
      */
     if (strchr(file, '/')) {
-        if (virFileIsExecutable(file))
-            ignore_value(virFileAbsPath(file, &path));
-        return path;
+        char *abspath = NULL;
+
+        if (!virFileIsExecutable(file))
+            return NULL;
+
+        ignore_value(virFileAbsPath(file, &abspath));
+        return abspath;
     }
 
     /* copy PATH env so we can tweak it */