gnome-utils r8306 - in trunk: . logview logview/tests
- From: cosimoc svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-utils r8306 - in trunk: . logview logview/tests
- Date: Tue, 23 Dec 2008 13:27:57 +0000 (UTC)
Author: cosimoc
Date: Tue Dec 23 13:27:57 2008
New Revision: 8306
URL: http://svn.gnome.org/viewvc/gnome-utils?rev=8306&view=rev
Log:
Support for GZipped logs.
Modified:
trunk/configure.ac
trunk/logview/Makefile.am
trunk/logview/logview-log.c
trunk/logview/logview-log.h
trunk/logview/tests/test-reader.c
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Tue Dec 23 13:27:57 2008
@@ -410,15 +410,21 @@
dnl logview checks
dnl ********************
-dnl This is where the binary actually resides,
-dnl not the console helper link
-if test "x$enable_console_helper" = "xyes"; then
- LOGVIEWDIR_TMP="$sbindir"
-else
- LOGVIEWDIR_TMP="$bindir"
+AC_ARG_ENABLE(zlib, AC_HELP_STRING([--disable-zlib], [disable zlib support]))
+msg_zlib=no
+Z_LIBS=
+
+if test "x$enable_zlib" != "xno"; then
+ AC_CHECK_HEADER(zlib.h,
+ [AC_CHECK_LIB(z, gzopen, msg_zlib=yes]))
+ if test "x$msg_zlib" = "xyes"; then
+ Z_LIBS="-lz"
+ AC_DEFINE(HAVE_ZLIB,, [Define to 1 if it's build with zlib support])
+ fi
fi
-EXPANDED_LOGVIEWDIR=`eval echo $LOGVIEWDIR_TMP`
-AC_SUBST(EXPANDED_LOGVIEWDIR)
+
+AC_SUBST(Z_LIBS)
+AM_CONDITIONAL(HAVE_ZLIB, [test "$msg_zlib" = "yes"])
dnl ********************
@@ -511,12 +517,6 @@
echo "The following will be built -"
echo "============================="
echo ""
-dnl <= Console Helper =>
-if test "x$enable_console_helper" = "xyes"; then
- echo "Console helper (logview) : YES"
-else
- echo "Console helper (logview) : NO"
-fi
dnl <= Debug messages =>
if test "x$enable_debug" = "xyes"; then
@@ -525,9 +525,6 @@
echo "Debug messages (libgdict) : NO"
fi
-dnl <= message file =>
-echo "Logview default message file : $messages_file"
-
dnl <= gfloppy =>
if test "x$build_gfloppy" = "xtrue"; then
echo "Build gfloppy : YES"
Modified: trunk/logview/Makefile.am
==============================================================================
--- trunk/logview/Makefile.am (original)
+++ trunk/logview/Makefile.am Tue Dec 23 13:27:57 2008
@@ -40,9 +40,9 @@
logview-prefs.h \
$(BUILT_SOURCES)
-gnome_system_log_LDADD = \
+gnome_system_log_LDADD = \
$(GNOME_UTILS_LIBS) \
- $(LIBGNOME_LIBS)
+ $(Z_LIBS)
logview-marshal.h: logview-marshal.list $(GLIB_GENMARSHAL)
$(GLIB_GENMARSHAL) $< --header --prefix=logview_marshal >> $@
Modified: trunk/logview/logview-log.c
==============================================================================
--- trunk/logview/logview-log.c (original)
+++ trunk/logview/logview-log.c Tue Dec 23 13:27:57 2008
@@ -22,8 +22,16 @@
#include "config.h"
#include <glib.h>
+#include <glib/gi18n.h>
#include <gio/gio.h>
+#ifdef HAVE_ZLIB
+#include <zlib.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+
#include "logview-log.h"
#include "logview-utils.h"
@@ -322,6 +330,17 @@
return FALSE;
}
+static GError *
+create_zlib_error (void)
+{
+ GError *err;
+
+ err = g_error_new_literal (LOGVIEW_ERROR_QUARK, LOGVIEW_ERROR_ZLIB,
+ _("Error while uncompressing the GZipped log. The file "
+ "might be corrupt."));
+ return err;
+}
+
static gboolean
log_load (GIOSchedulerJob *io_job,
GCancellable *cancellable,
@@ -332,11 +351,12 @@
LogviewLog *log = job->log;
GFile *f = log->priv->file;
GFileInfo *info;
- GFileInputStream *is;
+ GInputStream *is;
const char *content_type;
char *buffer;
GFileType type;
GError *err = NULL;
+ gboolean is_archive;
info = g_file_query_info (f,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
@@ -349,19 +369,19 @@
if (err->code == G_IO_ERROR_PERMISSION_DENIED) {
/* TODO: PolicyKit integration */
}
- job->err = err;
goto out;
}
type = g_file_info_get_file_type (info);
content_type = g_file_info_get_content_type (info);
+ is_archive = g_content_type_equals (content_type, "application/x-gzip");
+
if (type != (G_FILE_TYPE_REGULAR || G_FILE_TYPE_SYMBOLIC_LINK) ||
- !g_content_type_is_a (content_type, "text/plain")) /* TODO: zipped logs */
+ (!g_content_type_is_a (content_type, "text/plain") && !is_archive))
{
err = g_error_new_literal (LOGVIEW_ERROR_QUARK, LOGVIEW_ERROR_NOT_A_LOG,
- "The file is not a regular file or is not a text file");
- job->err = err;
+ _("The file is not a regular file or is not a text file."));
g_object_unref (info);
goto out;
@@ -372,21 +392,68 @@
log->priv->display_name = g_strdup (g_file_info_get_display_name (info));
g_object_unref (info);
+
+ if (!is_archive) {
+ /* initialize the stream */
+ is = G_INPUT_STREAM (g_file_read (f, NULL, &err));
+
+ if (err) {
+ if (err->code == G_IO_ERROR_PERMISSION_DENIED) {
+ /* TODO: PolicyKit integration */
+ }
- /* initialize the stream */
- is = g_file_read (f, NULL, &err);
+ goto out;
+ }
+ } else {
+#ifdef HAVE_ZLIB
+ gzFile gz;
+ char *path;
+ char *actual_data;
+ int res;
+ guint len;
+
+ path = g_file_get_path (f);
+ gz = gzopen (path, "rb");
+
+ g_free (path);
+
+ if (!gz) {
+ err = create_zlib_error ();
+ goto out;
+ }
- if (err) {
- if (err->code == G_IO_ERROR_PERMISSION_DENIED) {
- /* TODO: PolicyKit integration */
+ is = g_memory_input_stream_new ();
+
+ do {
+ actual_data = g_malloc0 (256);
+ res = gzread (gz, actual_data, 256);
+ if (res > 0) {
+ g_memory_input_stream_add_data (G_MEMORY_INPUT_STREAM (is),
+ actual_data, res, (GDestroyNotify) g_free);
+ }
+ } while (res > 0);
+
+ gzclose (gz);
+
+ if (res < 0) {
+ err = create_zlib_error ();
+ goto out;
}
- job->err = err;
+#elif
+ err = g_error_new_literal (LOGVIEW_ERROR_QUARK, LOGVIEW_ERROR_NOT_SUPPORTED,
+ _("This version of System Log does not support GZipped logs."));
goto out;
+#endif
}
- log->priv->stream = g_data_input_stream_new (G_INPUT_STREAM (is));
+ log->priv->stream = g_data_input_stream_new (is);
+ g_object_unref (is);
out:
+ if (err) {
+ job->err = err;
+ }
+
g_io_scheduler_job_send_to_mainloop_async (io_job,
log_load_done,
job, NULL);
Modified: trunk/logview/logview-log.h
==============================================================================
--- trunk/logview/logview-log.h (original)
+++ trunk/logview/logview-log.h Tue Dec 23 13:27:57 2008
@@ -60,6 +60,8 @@
typedef enum {
LOGVIEW_ERROR_FAILED,
+ LOGVIEW_ERROR_ZLIB,
+ LOGVIEW_ERROR_NOT_SUPPORTED,
LOGVIEW_ERROR_NOT_A_LOG
} LogviewErrorEnum;
Modified: trunk/logview/tests/test-reader.c
==============================================================================
--- trunk/logview/tests/test-reader.c (original)
+++ trunk/logview/tests/test-reader.c Tue Dec 23 13:27:57 2008
@@ -9,6 +9,7 @@
static void
new_lines_cb (LogviewLog *log,
const char **lines,
+ GSList *new_days,
GError *error,
gpointer user_data)
{
@@ -50,7 +51,7 @@
g_type_init ();
loop = g_main_loop_new (NULL, FALSE);
- logview_log_create ("/var/log/messages", callback, NULL);
+ logview_log_create ("/var/log/dpkg.log.2.gz", callback, NULL);
g_main_loop_run (loop);
return 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]