save_data_close (struct archive *a,
		 void           *client_data)
{
	SaveData *save_data = client_data;
	LoadData *load_data = LOAD_DATA (save_data);

	if (save_data->ostream != NULL) {
		GError *error = NULL;

		g_output_stream_close (save_data->ostream, load_data->cancellable, &error);
		if (load_data->error == NULL && error != NULL)
			load_data->error = g_error_copy (error);

		_g_error_free (error);
	}

	if (load_data->error == NULL)
		g_file_move (save_data->tmp_file,
			     fr_archive_get_file (load_data->archive),
			     G_FILE_COPY_OVERWRITE | G_FILE_COPY_TARGET_DEFAULT_PERMS,
			     load_data->cancellable,
			     NULL,
			     NULL,
			     &load_data->error);
	else
		g_file_delete (save_data->tmp_file, NULL, NULL);

	return ARCHIVE_OK;
}
save_data_close (struct archive *a,
		 void           *client_data)
{
	SaveData *save_data = client_data;
	LoadData *load_data = LOAD_DATA (save_data);

	if (save_data->ostream != NULL) {
		GError *error = NULL;

		g_output_stream_close (save_data->ostream, load_data->cancellable, &error);
		if (load_data->error == NULL && error != NULL)
			load_data->error = g_error_copy (error);

		_g_error_free (error);
	}

	if (load_data->error == NULL)
		g_file_move (save_data->tmp_file,
			     fr_archive_get_file (load_data->archive),
			     G_FILE_COPY_OVERWRITE | G_FILE_COPY_TARGET_DEFAULT_PERMS,
			     load_data->cancellable,
			     NULL,
			     NULL,
			     &load_data->error);
	else
		g_file_delete (save_data->tmp_file, NULL, NULL);

	return ARCHIVE_OK;
}