core: Extract stage_and_checksum() internal API

This will be used for staging both metadata and data consistently
before actually importing it.
This commit is contained in:
Colin Walters committed 2011-11-30 21:20:15 -05:00
1 parent 99bf19314e
commit 556662b24c
4 files changed
+150 -89

No files matched your search

+46
View File
@@ -138,6 +138,52 @@ ot_gfile_get_basename_cached (GFile *file)
return name;
}
gboolean
ot_gio_splice_and_checksum (GOutputStream *out,
GInputStream *in,
GChecksum **out_checksum,
GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
GChecksum *ret_checksum = NULL;
if (out_checksum)
ret_checksum = g_checksum_new (G_CHECKSUM_SHA256);
if (ret_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 (ret_checksum)
g_checksum_update (ret_checksum, (guint8*)buf, bytes_read);
if (!g_output_stream_write_all (out, buf, bytes_read, &bytes_written, cancellable, error))
goto out;
}
while (bytes_read > 0);
}
else
{
if (g_output_stream_splice (out, in, 0, cancellable, error) < 0)
goto out;
}
ret = TRUE;
if (out_checksum)
{
*out_checksum = ret_checksum;
ret_checksum = NULL;
}
out:
ot_clear_checksum (&ret_checksum);
return ret;
}
gboolean
ot_gfile_create_tmp (GFile *dir,
const char *prefix,