diff --git a/libotutil/ot-gio-utils.c b/libotutil/ot-gio-utils.c index ad172de7..b13b24ed 100644 --- a/libotutil/ot-gio-utils.c +++ b/libotutil/ot-gio-utils.c @@ -146,3 +146,32 @@ ot_util_new_file_for_path (const char *path) { return g_vfs_get_file_for_path (g_vfs_get_local (), path); } + +const char * +ot_gfile_get_path_cached (GFile *file) +{ + const char *path; + + path = g_object_get_data ((GObject*)file, "ostree-file-path"); + if (!path) + { + path = g_file_get_path (file); + g_object_set_data_full ((GObject*)file, "ostree-file-path", (char*)path, (GDestroyNotify)g_free); + } + return path; +} + + +const char * +ot_gfile_get_basename_cached (GFile *file) +{ + const char *name; + + name = g_object_get_data ((GObject*)file, "ostree-file-name"); + if (!name) + { + name = g_file_get_basename (file); + g_object_set_data_full ((GObject*)file, "ostree-file-name", (char*)name, (GDestroyNotify)g_free); + } + return name; +} diff --git a/libotutil/ot-gio-utils.h b/libotutil/ot-gio-utils.h index 0acb4dc9..15c5960d 100644 --- a/libotutil/ot-gio-utils.h +++ b/libotutil/ot-gio-utils.h @@ -28,6 +28,10 @@ G_BEGIN_DECLS GFile *ot_util_new_file_for_path (const char *path); +const char *ot_gfile_get_path_cached (GFile *file); + +const char *ot_gfile_get_basename_cached (GFile *file); + gboolean ot_util_ensure_directory (const char *path, gboolean with_parents, GError **error); char * ot_util_get_file_contents_utf8 (const char *path, GError **error);