From fadd68e4e23af2e3bd28c0d0ec71b21c3e66f44f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 16 Jan 2015 10:01:15 -0500 Subject: [PATCH] Use gs_shutil_cp_a for collecting exports This saves some code - the downside is that we can only run build-finish once, since cp_a errors out on existing directories. --- xdg-app-builtins-build-finish.c | 114 +++++++++++++------------------- 1 file changed, 47 insertions(+), 67 deletions(-) diff --git a/xdg-app-builtins-build-finish.c b/xdg-app-builtins-build-finish.c index 0fbdd746..2e6f4d66 100644 --- a/xdg-app-builtins-build-finish.c +++ b/xdg-app-builtins-build-finish.c @@ -4,64 +4,29 @@ #include #include #include +#include #include "libgsystem.h" #include "xdg-app-builtins.h" #include "xdg-app-utils.h" -static gboolean -copy_subdir (GFile *files, GFile *export, const char *path, GCancellable *cancellable, GError **error) +static GFile *show_export_base; + +static int +show_export (const char *fpath, const struct stat *sb, int typeflag) { - gboolean ret = FALSE; - gs_unref_object GFile *source_dir = NULL; - gs_unref_object GFile *dest_dir = NULL; - gs_unref_object GFileEnumerator *source_enum = NULL; - gs_unref_object GFileInfo *child_info = NULL; - GError *temp_error = NULL; - - source_dir = g_file_resolve_relative_path (files, path); - if (!g_file_query_exists (source_dir, cancellable)) + if (typeflag == FTW_F) { - ret = TRUE; - goto out; - } + gs_unref_object GFile *file; + gs_free char *relpath; - dest_dir = g_file_resolve_relative_path (export, path); - if (!gs_file_ensure_directory (dest_dir, TRUE, cancellable, error)) - goto out; - - source_enum = g_file_enumerate_children (source_dir, G_FILE_ATTRIBUTE_STANDARD_NAME, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, error); - if (!source_enum) - goto out; - - while ((child_info = g_file_enumerator_next_file (source_enum, cancellable, &temp_error))) - { - gs_unref_object GFile *source = NULL; - gs_unref_object GFile *destination = NULL; - gs_free char *relpath = NULL; - const char *name; - - name = g_file_info_get_name (child_info); - - source = g_file_get_child (source_dir, name); - destination = g_file_get_child (dest_dir, name); - if (!g_file_copy (source, destination, G_FILE_COPY_OVERWRITE, cancellable, NULL, NULL, error)) - goto out; - - relpath = g_file_get_relative_path (files, source); + file = g_file_new_for_path (fpath); + relpath = g_file_get_relative_path (show_export_base, file); g_print ("Exporting %s\n", relpath); } - ret = TRUE; - -out: - if (temp_error != NULL) - g_propagate_error (error, temp_error); - - return ret; + return 0; } static gboolean @@ -70,36 +35,43 @@ collect_exports (GFile *base, GCancellable *cancellable, GError **error) gboolean ret = FALSE; gs_unref_object GFile *files = NULL; gs_unref_object GFile *export = NULL; - const gchar *sizes[] = { - "16x16", "24x24", "32x32", "48x48", "64x64", "96x96", - "128x128", "256x256", "512x512", "scalable", - NULL + const char *paths[] = { + "share/applications", /* Copy desktop files */ + "share/icons/hicolor", /* Icons */ + "share/dbus-1/services", /* D-Bus service files */ + NULL, }; int i; + const char *path; files = g_file_get_child (base, "files"); export = g_file_get_child (base, "export"); - /* Copy desktop files */ - if (!copy_subdir (files, export, "share/applications", cancellable, error)) - goto out; - - /* Copy icons */ - for (i = 0; sizes[i]; i++) + for (i = 0; paths[i]; i++) { - gs_free char *path; - - path = g_strconcat ("share/icons/hicolor/", sizes[i], "/apps", NULL); - if (!copy_subdir (files, export, path, cancellable, error)) - goto out; + gs_unref_object GFile *src = NULL; + src = g_file_resolve_relative_path (files, paths[i]); + if (g_file_query_exists (src, cancellable)) + { + g_debug ("Exporting from %s", paths[i]); + gs_unref_object GFile *dest = NULL; + dest = g_file_resolve_relative_path (export, paths[i]); + g_debug ("Ensuring export/%s exists", paths[i]); + if (!gs_file_ensure_directory (dest, TRUE, cancellable, error)) + goto out; + g_debug ("Copying from files/%s", paths[i]); + if (!gs_shutil_cp_a (src, dest, cancellable, error)) + goto out; + } } - /* Copy D-Bus service files */ - if (!copy_subdir (files, export, "share/dbus-1/services", cancellable, error)) - goto out; + path = g_file_get_path (export); + show_export_base = export; + ftw (path, show_export, 10); ret = TRUE; + g_assert_no_error (*error); out: return ret; } @@ -196,6 +168,7 @@ xdg_app_builtin_build_finish (int argc, char **argv, GCancellable *cancellable, GOptionContext *context; gs_unref_object GFile *base = NULL; gs_unref_object GFile *files_dir = NULL; + gs_unref_object GFile *export_dir = NULL; gs_unref_object GFile *var_dir = NULL; gs_unref_object GFile *var_tmp_dir = NULL; gs_unref_object GFile *var_run_dir = NULL; @@ -219,10 +192,8 @@ xdg_app_builtin_build_finish (int argc, char **argv, GCancellable *cancellable, base = g_file_new_for_commandline_arg (directory); - if (!gs_file_ensure_directory (base, TRUE, cancellable, error)) - goto out; - files_dir = g_file_get_child (base, "files"); + export_dir = g_file_get_child (base, "export"); var_dir = g_file_get_child (base, "var"); var_tmp_dir = g_file_get_child (var_dir, "tmp"); var_run_dir = g_file_get_child (var_dir, "run"); @@ -235,12 +206,21 @@ xdg_app_builtin_build_finish (int argc, char **argv, GCancellable *cancellable, goto out; } + if (g_file_query_exists (export_dir, cancellable)) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Build directory %s already finalized", directory); + goto out; + } + + g_debug ("Collecting exports"); if (!collect_exports (base, cancellable, error)) goto out; + g_debug ("Updating metadata"); if (!update_metadata (base, cancellable, error)) goto out; + g_debug ("Cleaning up var"); if (!clean_up_var (base, cancellable, error)) goto out;