1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

util: file: Use more obvious logic in virFindFileInPath

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>
This commit is contained in:
Peter Krempa 2019-11-14 10:16:54 +01:00
parent 6eac0c5436
commit 4bb2c51a9c

View File

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