[totem-pl-parser/wip/hadess/async-save: 5/8] plparser: Make totem_pl_parser_write_buffer() cancellable



commit 7ec8311442dabc4458adbdef50f7ec84e061ced1
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Feb 27 16:56:14 2020 +0100

    plparser: Make totem_pl_parser_write_buffer() cancellable

 plparse/totem-pl-parser-pla.c     | 4 ++--
 plparse/totem-pl-parser-private.h | 1 +
 plparse/totem-pl-parser.c         | 9 +++++++--
 3 files changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/plparse/totem-pl-parser-pla.c b/plparse/totem-pl-parser-pla.c
index 56b44b3..e78efae 100644
--- a/plparse/totem-pl-parser-pla.c
+++ b/plparse/totem-pl-parser-pla.c
@@ -72,7 +72,7 @@ totem_pl_parser_save_pla (TotemPlParser    *parser,
         * the 'quick list' name there.
         */
        strncpy (buffer + TITLE_OFFSET, title, TITLE_SIZE);
-       if (totem_pl_parser_write_buffer (G_OUTPUT_STREAM (stream), buffer, RECORD_SIZE, error) == FALSE)
+       if (totem_pl_parser_write_buffer (G_OUTPUT_STREAM (stream), buffer, RECORD_SIZE, cancellable, error) 
== FALSE)
        {
                DEBUG(output, g_print ("Couldn't write header block for '%s'", uri));
                g_free (buffer);
@@ -150,7 +150,7 @@ totem_pl_parser_save_pla (TotemPlParser    *parser,
                memcpy (buffer + PATH_OFFSET, converted, written);
                g_free (converted);
 
-               if (totem_pl_parser_write_buffer (G_OUTPUT_STREAM (stream), buffer, RECORD_SIZE, error) == 
FALSE)
+               if (totem_pl_parser_write_buffer (G_OUTPUT_STREAM (stream), buffer, RECORD_SIZE, cancellable, 
error) == FALSE)
                {
                        DEBUG1(g_print ("Couldn't write entry %d to the file\n", i));
                        ret = FALSE;
diff --git a/plparse/totem-pl-parser-private.h b/plparse/totem-pl-parser-private.h
index 8073ec7..d868e9b 100644
--- a/plparse/totem-pl-parser-private.h
+++ b/plparse/totem-pl-parser-private.h
@@ -135,6 +135,7 @@ gboolean totem_pl_parser_write_string               (GOutputStream *stream,
 gboolean totem_pl_parser_write_buffer          (GOutputStream *stream,
                                                 const char *buf,
                                                 guint size,
+                                                GCancellable *cancellable,
                                                 GError **error);
 char * totem_pl_parser_relative                        (GFile *output,
                                                 const char *filepath);
diff --git a/plparse/totem-pl-parser.c b/plparse/totem-pl-parser.c
index a5a9740..0d7f932 100644
--- a/plparse/totem-pl-parser.c
+++ b/plparse/totem-pl-parser.c
@@ -873,6 +873,7 @@ totem_pl_parser_write_string (GOutputStream *stream, const char *buf, GError **e
  * @stream: a #GFileOutputStream to an open file
  * @buf: the string buffer to write out
  * @len: the length of the string to write out
+ * @cancellable: (allow-none): a #GCancellable, or %NULL
  * @error: return location for a #GError, or %NULL
  *
  * Writes @len bytes of @buf to the file specified by @handle.
@@ -882,14 +883,18 @@ totem_pl_parser_write_string (GOutputStream *stream, const char *buf, GError **e
  * Return value: %TRUE on success
  **/
 gboolean
-totem_pl_parser_write_buffer (GOutputStream *stream, const char *buf, guint len, GError **error)
+totem_pl_parser_write_buffer (GOutputStream  *stream,
+                             const char     *buf,
+                             guint           len,
+                             GCancellable   *cancellable,
+                             GError        **error)
 {
        gsize bytes_written;
 
        if (g_output_stream_write_all (stream,
                                       buf, len,
                                       &bytes_written,
-                                      NULL, error) == FALSE) {
+                                      cancellable, error) == FALSE) {
                g_object_unref (stream);
                return FALSE;
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]