[ostree] otutil: Move checksum related bits into checksum-utils.[ch]
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] otutil: Move checksum related bits into checksum-utils.[ch]
- Date: Thu, 29 Nov 2012 22:14:22 +0000 (UTC)
commit 6d81120455c1cd99c11879c9e7885d294a289dd3
Author: Colin Walters <walters verbum org>
Date: Thu Nov 29 16:28:24 2012 -0500
otutil: Move checksum related bits into checksum-utils.[ch]
This paves the way for slimming ot-gio-utils.[ch] into libgsystem.
src/libotutil/ot-checksum-utils.c | 146 +++++++++++++++++++++++++++++++++++++
src/libotutil/ot-checksum-utils.h | 35 +++++++++
src/libotutil/ot-gio-utils.c | 145 ------------------------------------
src/libotutil/ot-gio-utils.h | 34 ---------
4 files changed, 181 insertions(+), 179 deletions(-)
---
diff --git a/src/libotutil/ot-checksum-utils.c b/src/libotutil/ot-checksum-utils.c
index 7405abf..bc4deae 100644
--- a/src/libotutil/ot-checksum-utils.c
+++ b/src/libotutil/ot-checksum-utils.c
@@ -36,3 +36,149 @@ ot_csum_from_gchecksum (GChecksum *checksum)
g_assert (len == 32);
return ret;
}
+
+gboolean
+ot_gio_write_update_checksum (GOutputStream *out,
+ gconstpointer data,
+ gsize len,
+ gsize *out_bytes_written,
+ GChecksum *checksum,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+
+ if (out)
+ {
+ if (!g_output_stream_write_all (out, data, len, out_bytes_written,
+ cancellable, error))
+ goto out;
+ }
+ else if (out_bytes_written)
+ {
+ *out_bytes_written = len;
+ }
+
+ if (checksum)
+ g_checksum_update (checksum, data, len);
+
+ ret = TRUE;
+ out:
+ return ret;
+}
+
+gboolean
+ot_gio_splice_update_checksum (GOutputStream *out,
+ GInputStream *in,
+ GChecksum *checksum,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+
+ g_return_val_if_fail (out != NULL || checksum != NULL, FALSE);
+
+ if (checksum != NULL)
+ {
+ gsize bytes_read, bytes_written;
+ char buf[4096];
+ do
+ {
+ if (!g_input_stream_read_all (in, buf, sizeof(buf), &bytes_read, cancellable, error))
+ goto out;
+ if (!ot_gio_write_update_checksum (out, buf, bytes_read, &bytes_written, checksum,
+ cancellable, error))
+ goto out;
+ }
+ while (bytes_read > 0);
+ }
+ else
+ {
+ if (g_output_stream_splice (out, in, 0, cancellable, error) < 0)
+ goto out;
+ }
+
+ ret = TRUE;
+ out:
+ return ret;
+}
+
+gboolean
+ot_gio_splice_get_checksum (GOutputStream *out,
+ GInputStream *in,
+ guchar **out_csum,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ GChecksum *checksum = NULL;
+ ot_lfree guchar *ret_csum = NULL;
+
+ checksum = g_checksum_new (G_CHECKSUM_SHA256);
+
+ if (!ot_gio_splice_update_checksum (out, in, checksum, cancellable, error))
+ goto out;
+
+ ret_csum = ot_csum_from_gchecksum (checksum);
+
+ ret = TRUE;
+ ot_transfer_out_value (out_csum, &ret_csum);
+ out:
+ g_clear_pointer (&checksum, (GDestroyNotify) g_checksum_free);
+ return ret;
+}
+
+gboolean
+ot_gio_checksum_stream (GInputStream *in,
+ guchar **out_csum,
+ GCancellable *cancellable,
+ GError **error)
+{
+ if (!out_csum)
+ return TRUE;
+ return ot_gio_splice_get_checksum (NULL, in, out_csum, cancellable, error);
+}
+
+static void
+checksum_stream_thread (GSimpleAsyncResult *result,
+ GObject *object,
+ GCancellable *cancellable)
+{
+ GError *error = NULL;
+ guchar *csum;
+
+ if (!ot_gio_checksum_stream ((GInputStream*)object, &csum,
+ cancellable, &error))
+ g_simple_async_result_take_error (result, error);
+ else
+ g_simple_async_result_set_op_res_gpointer (result, csum, g_free);
+}
+
+void
+ot_gio_checksum_stream_async (GInputStream *in,
+ int io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new ((GObject*) in,
+ callback, user_data,
+ ot_gio_checksum_stream_async);
+
+ g_simple_async_result_run_in_thread (result, checksum_stream_thread, io_priority, cancellable);
+ g_object_unref (result);
+}
+
+guchar *
+ot_gio_checksum_stream_finish (GInputStream *in,
+ GAsyncResult *result,
+ GError **error)
+{
+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
+
+ g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == ot_gio_checksum_stream_async);
+ return g_memdup (g_simple_async_result_get_op_res_gpointer (simple), 32);
+}
+
diff --git a/src/libotutil/ot-checksum-utils.h b/src/libotutil/ot-checksum-utils.h
index e9de638..67ff9db 100644
--- a/src/libotutil/ot-checksum-utils.h
+++ b/src/libotutil/ot-checksum-utils.h
@@ -29,6 +29,41 @@ G_BEGIN_DECLS
guchar *ot_csum_from_gchecksum (GChecksum *checksum);
+gboolean ot_gio_write_update_checksum (GOutputStream *out,
+ gconstpointer data,
+ gsize len,
+ gsize *out_bytes_written,
+ GChecksum *checksum,
+ GCancellable *cancellable,
+ GError **error);
+
+gboolean ot_gio_splice_get_checksum (GOutputStream *out,
+ GInputStream *in,
+ guchar **out_csum,
+ GCancellable *cancellable,
+ GError **error);
+
+gboolean ot_gio_splice_update_checksum (GOutputStream *out,
+ GInputStream *in,
+ GChecksum *checksum,
+ GCancellable *cancellable,
+ GError **error);
+
+gboolean ot_gio_checksum_stream (GInputStream *in,
+ guchar **out_csum,
+ GCancellable *cancellable,
+ GError **error);
+
+void ot_gio_checksum_stream_async (GInputStream *in,
+ int io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+guchar * ot_gio_checksum_stream_finish (GInputStream *in,
+ GAsyncResult *result,
+ GError **error);
+
G_END_DECLS
#endif
diff --git a/src/libotutil/ot-gio-utils.c b/src/libotutil/ot-gio-utils.c
index f28693d..14af2ce 100644
--- a/src/libotutil/ot-gio-utils.c
+++ b/src/libotutil/ot-gio-utils.c
@@ -202,151 +202,6 @@ ot_gfile_load_contents_utf8 (GFile *file,
return ret;
}
-gboolean
-ot_gio_write_update_checksum (GOutputStream *out,
- gconstpointer data,
- gsize len,
- gsize *out_bytes_written,
- GChecksum *checksum,
- GCancellable *cancellable,
- GError **error)
-{
- gboolean ret = FALSE;
-
- if (out)
- {
- if (!g_output_stream_write_all (out, data, len, out_bytes_written,
- cancellable, error))
- goto out;
- }
- else if (out_bytes_written)
- {
- *out_bytes_written = len;
- }
-
- if (checksum)
- g_checksum_update (checksum, data, len);
-
- ret = TRUE;
- out:
- return ret;
-}
-
-gboolean
-ot_gio_splice_update_checksum (GOutputStream *out,
- GInputStream *in,
- GChecksum *checksum,
- GCancellable *cancellable,
- GError **error)
-{
- gboolean ret = FALSE;
-
- g_return_val_if_fail (out != NULL || checksum != NULL, FALSE);
-
- if (checksum != NULL)
- {
- gsize bytes_read, bytes_written;
- char buf[4096];
- do
- {
- if (!g_input_stream_read_all (in, buf, sizeof(buf), &bytes_read, cancellable, error))
- goto out;
- if (!ot_gio_write_update_checksum (out, buf, bytes_read, &bytes_written, checksum,
- cancellable, error))
- goto out;
- }
- while (bytes_read > 0);
- }
- else
- {
- if (g_output_stream_splice (out, in, 0, cancellable, error) < 0)
- goto out;
- }
-
- ret = TRUE;
- out:
- return ret;
-}
-
-gboolean
-ot_gio_splice_get_checksum (GOutputStream *out,
- GInputStream *in,
- guchar **out_csum,
- GCancellable *cancellable,
- GError **error)
-{
- gboolean ret = FALSE;
- GChecksum *checksum = NULL;
- ot_lfree guchar *ret_csum = NULL;
-
- checksum = g_checksum_new (G_CHECKSUM_SHA256);
-
- if (!ot_gio_splice_update_checksum (out, in, checksum, cancellable, error))
- goto out;
-
- ret_csum = ot_csum_from_gchecksum (checksum);
-
- ret = TRUE;
- ot_transfer_out_value (out_csum, &ret_csum);
- out:
- g_clear_pointer (&checksum, (GDestroyNotify) g_checksum_free);
- return ret;
-}
-
-gboolean
-ot_gio_checksum_stream (GInputStream *in,
- guchar **out_csum,
- GCancellable *cancellable,
- GError **error)
-{
- if (!out_csum)
- return TRUE;
- return ot_gio_splice_get_checksum (NULL, in, out_csum, cancellable, error);
-}
-
-static void
-checksum_stream_thread (GSimpleAsyncResult *result,
- GObject *object,
- GCancellable *cancellable)
-{
- GError *error = NULL;
- guchar *csum;
-
- if (!ot_gio_checksum_stream ((GInputStream*)object, &csum,
- cancellable, &error))
- g_simple_async_result_take_error (result, error);
- else
- g_simple_async_result_set_op_res_gpointer (result, csum, g_free);
-}
-
-void
-ot_gio_checksum_stream_async (GInputStream *in,
- int io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- GSimpleAsyncResult *result;
-
- result = g_simple_async_result_new ((GObject*) in,
- callback, user_data,
- ot_gio_checksum_stream_async);
-
- g_simple_async_result_run_in_thread (result, checksum_stream_thread, io_priority, cancellable);
- g_object_unref (result);
-}
-
-guchar *
-ot_gio_checksum_stream_finish (GInputStream *in,
- GAsyncResult *result,
- GError **error)
-{
- GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
-
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == ot_gio_checksum_stream_async);
- return g_memdup (g_simple_async_result_get_op_res_gpointer (simple), 32);
-}
-
static gboolean
cp_internal (GFile *src,
GFile *dest,
diff --git a/src/libotutil/ot-gio-utils.h b/src/libotutil/ot-gio-utils.h
index a7c3b40..b96f1ca 100644
--- a/src/libotutil/ot-gio-utils.h
+++ b/src/libotutil/ot-gio-utils.h
@@ -50,40 +50,6 @@ gboolean ot_gfile_load_contents_utf8 (GFile *file,
GCancellable *cancellable,
GError **error);
-gboolean ot_gio_write_update_checksum (GOutputStream *out,
- gconstpointer data,
- gsize len,
- gsize *out_bytes_written,
- GChecksum *checksum,
- GCancellable *cancellable,
- GError **error);
-
-gboolean ot_gio_splice_get_checksum (GOutputStream *out,
- GInputStream *in,
- guchar **out_csum,
- GCancellable *cancellable,
- GError **error);
-
-gboolean ot_gio_splice_update_checksum (GOutputStream *out,
- GInputStream *in,
- GChecksum *checksum,
- GCancellable *cancellable,
- GError **error);
-
-gboolean ot_gio_checksum_stream (GInputStream *in,
- guchar **out_csum,
- GCancellable *cancellable,
- GError **error);
-
-void ot_gio_checksum_stream_async (GInputStream *in,
- int io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-guchar * ot_gio_checksum_stream_finish (GInputStream *in,
- GAsyncResult *result,
- GError **error);
gboolean ot_gio_shutil_cp_a (GFile *src,
GFile *dest,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]