mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 05:17:59 +03:00
util: Introduce virFileFindInPathFull()
Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
d92054c867
commit
ef91f9e52a
@ -2358,6 +2358,7 @@ virFileWrapperFdFree;
|
||||
virFileWrapperFdNew;
|
||||
virFileWriteStr;
|
||||
virFindFileInPath;
|
||||
virFindFileInPathFull;
|
||||
|
||||
|
||||
# util/virfilecache.h
|
||||
|
@ -1737,6 +1737,25 @@ virFileIsLink(const char *linkpath)
|
||||
*/
|
||||
char *
|
||||
virFindFileInPath(const char *file)
|
||||
{
|
||||
return virFindFileInPathFull(file, NULL);
|
||||
}
|
||||
|
||||
/* virFindFileInPathFull:
|
||||
* @file: name of the program
|
||||
* @extraDirs: NULL-terminated list of additional directories
|
||||
*
|
||||
* Like virFindFileInPath(), but in addition to searching $PATH also
|
||||
* looks into all directories listed in @extraDirs. This is useful to
|
||||
* locate helpers that are installed outside of $PATH.
|
||||
*
|
||||
* The returned path must be freed by the caller.
|
||||
*
|
||||
* Returns: absolute path of the program or NULL
|
||||
*/
|
||||
char *
|
||||
virFindFileInPathFull(const char *file,
|
||||
const char *const *extraDirs)
|
||||
{
|
||||
g_autofree char *path = NULL;
|
||||
if (file == NULL)
|
||||
@ -1751,6 +1770,20 @@ virFindFileInPath(const char *file)
|
||||
return g_canonicalize_filename(path, NULL);
|
||||
}
|
||||
|
||||
if (extraDirs) {
|
||||
while (*extraDirs) {
|
||||
g_autofree char *extraPath = NULL;
|
||||
|
||||
extraPath = g_strdup_printf("%s/%s", *extraDirs, file);
|
||||
|
||||
if (virFileIsExecutable(extraPath)) {
|
||||
return g_steal_pointer(&extraPath);
|
||||
}
|
||||
|
||||
extraDirs++;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -189,6 +189,9 @@ int virFileIsLink(const char *linkpath)
|
||||
|
||||
char *virFindFileInPath(const char *file)
|
||||
G_NO_INLINE;
|
||||
char *virFindFileInPathFull(const char *file,
|
||||
const char *const *extraDirs)
|
||||
G_NO_INLINE;
|
||||
|
||||
char *virFileFindResource(const char *filename,
|
||||
const char *builddir,
|
||||
|
Loading…
Reference in New Issue
Block a user