From b19589569e4b89b0b731c5439ba9d8ae5ec08922 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Tue, 21 Oct 2014 10:31:37 +0100 Subject: trivial: Make compression optional in as_store_to_file() --- libappstream-glib/as-store.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c index 2c1b499..6c547cf 100644 --- a/libappstream-glib/as-store.c +++ b/libappstream-glib/as-store.c @@ -897,7 +897,7 @@ as_store_convert_icons (AsStore *store, AsIconKind kind, GError **error) * @cancellable: A #GCancellable, or %NULL * @error: A #GError or %NULL * - * Outputs a compressed XML file of all the applications in the store. + * Outputs an optionally compressed XML file of all the applications in the store. * * Returns: A #GString * @@ -915,6 +915,28 @@ as_store_to_file (AsStore *store, _cleanup_object_unref_ GOutputStream *out = NULL; _cleanup_object_unref_ GZlibCompressor *compressor = NULL; _cleanup_string_free_ GString *xml = NULL; + _cleanup_free_ gchar *basename = NULL; + + /* check if compressed */ + basename = g_file_get_basename (file); + if (g_strstr_len (basename, -1, ".gz") == NULL) { + xml = as_store_to_xml (store, flags); + if (!g_file_replace_contents (file, xml->str, xml->len, + NULL, + FALSE, + G_FILE_CREATE_NONE, + NULL, + cancellable, + &error_local)) { + g_set_error (error, + AS_STORE_ERROR, + AS_STORE_ERROR_FAILED, + "Failed to write file: %s", + error_local->message); + return FALSE; + } + return TRUE; + } /* compress as a gzip file */ compressor = g_zlib_compressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP, -1); -- cgit v1.2.1