gchar *buf;
GFileInfo *finfo;
+ gssize size;
+
+ GError *error;
SolipaLog *solipa_log = (SolipaLog *)user_data;
NULL);
if (finfo != NULL)
{
- if (g_file_info_get_size (finfo) > priv->rotation_size)
+ size = g_file_info_get_size (finfo);
+ if (size > priv->rotation_size)
{
GFile *fold;
g_object_unref (fold);
g_output_stream_close (G_OUTPUT_STREAM (priv->stream), NULL, NULL);
- g_file_set_display_name (priv->file, "log.log.0", NULL, NULL);
+
+ fold = g_file_set_display_name (priv->file, "log.log.0", NULL, NULL);
+ g_object_unref (priv->file);
+ priv->file = g_object_ref (fold);
+ g_object_unref (fold);
if (priv->compress)
{
GZlibCompressor *compress;
+ GOutputStream *ostreamcomp;
+ GFile *fout;
+ GFileInputStream *istream;
+ GFileOutputStream *ostream;
+
+ error = NULL;
+ istream = g_file_read (priv->file, NULL, &error);
+ if (istream == NULL || error != NULL)
+ {
+ g_warning ("Impossibile leggere dal file %s: %s.",
+ "log.log.0",
+ error != NULL && error->message != NULL ? error->message : "nessun dettaglio");
+ }
+
+ buf = g_malloc0 (size);
+
+ error = NULL;
+ if (!g_input_stream_read_all (G_INPUT_STREAM (istream),
+ buf,
+ size,
+ NULL,
+ NULL,
+ &error))
+ {
+ g_warning ("Impossibile leggere dallo stream: %s.",
+ error != NULL && error->message != NULL ? error->message : "nessun dettaglio");
+ }
+
+ fout = g_file_new_for_path (g_build_filename (g_file_get_path (g_file_get_parent (priv->file)), "log.log.0.gz", NULL));
+ error = NULL;
+ ostream = g_file_replace (fout,
+ NULL,
+ FALSE,
+ G_FILE_CREATE_PRIVATE,
+ NULL,
+ &error);
+ if (ostream == NULL || error != NULL)
+ {
+ g_warning ("Impossibile creare il file: %s.",
+ error != NULL && error->message != NULL ? error->message : "nessun dettaglio");
+ }
compress = g_zlib_compressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP,
-1);
+ ostreamcomp = g_converter_output_stream_new (G_OUTPUT_STREAM (ostream),
+ G_CONVERTER (compress));
+
+ error = NULL;
+ if (!g_output_stream_write_all (ostreamcomp,
+ buf,
+ size,
+ NULL,
+ NULL,
+ &error))
+ {
+ g_warning ("Impossibile creare il file: %s.",
+ error != NULL && error->message != NULL ? error->message : "nessun dettaglio");
+ }
+
+ if (istream != NULL)
+ {
+ g_input_stream_close (G_INPUT_STREAM (istream), NULL, NULL);
+ g_object_unref (istream);
+ }
+ if (ostreamcomp != NULL)
+ {
+ g_output_stream_close (ostreamcomp, NULL, NULL);
+ g_object_unref (ostreamcomp);
+ }
+ if (ostream != NULL)
+ {
+ g_output_stream_close (G_OUTPUT_STREAM (ostream), NULL, NULL);
+ g_object_unref (ostream);
+ }
+
+ g_free (buf);
+
+ g_object_unref (fout);
+
+ g_file_delete (priv->file, NULL, NULL);
}
g_object_unref (priv->file);