[PATCH v2 3/5] util: file: Use more obvious logic in virFindFileInPath

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
v2:
- fixed logic to do the same as it did before
- rewrote commit message to accomodate change

 src/util/virfile.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index 072a299b39..c7620e49d5 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -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 */
-- 
2.23.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux