From 4a60c8795803c145a48cf472f63306f36de874ca Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Fri, 21 Apr 2017 18:22:52 +0200 Subject: [PATCH] common: Add flatpak_build_file[_va] helper This makes it easy to construct GFiles from a base dir and an argument list of child elements. --- common/flatpak-utils.c | 29 +++++++++++++++++++++++++++++ common/flatpak-utils.h | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c index 4a8db0f98..23fe68836 100644 --- a/common/flatpak-utils.c +++ b/common/flatpak-utils.c @@ -2054,6 +2054,35 @@ flatpak_spawnv (GFile *dir, return TRUE; } +GFile * +flatpak_build_file_va (GFile *base, + va_list args) +{ + g_autoptr(GFile) res = g_object_ref (base); + const gchar *arg; + + while ((arg = va_arg (args, const gchar *))) + { + GFile *child = g_file_get_child (res, arg); + g_set_object (&res, child); + } + + return g_steal_pointer (&res); +} + +GFile * +flatpak_build_file (GFile *base, ...) +{ + GFile *res; + va_list args; + + va_start (args, base); + res = flatpak_build_file_va (base, args); + va_end (args); + + return res; +} + const char * flatpak_file_get_path_cached (GFile *file) { diff --git a/common/flatpak-utils.h b/common/flatpak-utils.h index 4f806f7db..40a2c1ba7 100644 --- a/common/flatpak-utils.h +++ b/common/flatpak-utils.h @@ -399,6 +399,10 @@ gboolean flatpak_spawnv (GFile *dir, const char *flatpak_file_get_path_cached (GFile *file); +GFile *flatpak_build_file_va (GFile *base, + va_list args); +GFile *flatpak_build_file (GFile *base, ...) G_GNUC_NULL_TERMINATED; + gboolean flatpak_openat_noatime (int dfd, const char *name, int *ret_fd,