Commit 99c9bc7d authored by Paolo Borelli's avatar Paolo Borelli Committed by Paolo Borelli

add some execution tracing annotations.

2006-04-08  Paolo Borelli  <pborelli@katamail.com>

	* gedit/debug.[ch]:
	* gedit/gedit-document-loader.c:
	* gedit/gedit-document-saver.c:

	add some execution tracing annotations.
parent 1a1e27ce
2006-04-08 Paolo Borelli <pborelli@katamail.com>
* gedit/debug.[ch]:
* gedit/gedit-document-loader.c:
* gedit/gedit-document-saver.c:
add some execution tracing annotations.
2006-04-06 Steve Frécinaux <steve@istique.net>
* plugins/snippets/data/c++.xml:
......
......@@ -72,22 +72,17 @@ gedit_cmd_help_about (GtkAction *action,
static const gchar copyright[] = \
"Copyright \xc2\xa9 1998-2000 Evan Lawrence, Alex Robert\n"
"Copyright \xc2\xa9 2000-2002 Chema Celorio, Paolo Maggi\n"
"Copyright \xc2\xa9 2003-2005 Paolo Maggi";
"Copyright \xc2\xa9 2003-2006 Paolo Maggi";
static const gchar comments[] = \
N_("gedit is a small and lightweight text editor for the "
"GNOME Desktop");
static GdkPixbuf *logo = NULL;
GdkPixbuf *logo;
gedit_debug (DEBUG_COMMANDS);
if(!logo)
{
logo = gdk_pixbuf_new_from_file (
GNOME_ICONDIR "/gedit-logo.png",
NULL);
}
logo = gdk_pixbuf_new_from_file (GNOME_ICONDIR "/gedit-logo.png", NULL);
gtk_show_about_dialog (GTK_WINDOW (window),
"authors", authors,
......@@ -100,4 +95,7 @@ gedit_cmd_help_about (GtkAction *action,
"website", "http://www.gedit.org",
"name", _("gedit"),
NULL);
if (logo)
g_object_unref (logo);
}
......@@ -82,6 +82,10 @@ gedit_debug_init ()
debug = debug | GEDIT_DEBUG_METADATA;
if (g_getenv ("GEDIT_DEBUG_WINDOW") != NULL)
debug = debug | GEDIT_DEBUG_WINDOW;
if (g_getenv ("GEDIT_DEBUG_LOADER") != NULL)
debug = debug | GEDIT_DEBUG_LOADER;
if (g_getenv ("GEDIT_DEBUG_SAVER") != NULL)
debug = debug | GEDIT_DEBUG_SAVER;
out:
......
......@@ -55,7 +55,8 @@ typedef enum {
GEDIT_DEBUG_UTILS = 1 << 10,
GEDIT_DEBUG_METADATA = 1 << 11,
GEDIT_DEBUG_WINDOW = 1 << 12,
GEDIT_DEBUG_LOADER = 1 << 13,
GEDIT_DEBUG_SAVER = 1 << 14
} GeditDebugSection;
......@@ -72,6 +73,8 @@ typedef enum {
#define DEBUG_UTILS GEDIT_DEBUG_UTILS, __FILE__, __LINE__, G_STRFUNC
#define DEBUG_METADATA GEDIT_DEBUG_METADATA,__FILE__, __LINE__, G_STRFUNC
#define DEBUG_WINDOW GEDIT_DEBUG_WINDOW, __FILE__, __LINE__, G_STRFUNC
#define DEBUG_LOADER GEDIT_DEBUG_LOADER, __FILE__, __LINE__, G_STRFUNC
#define DEBUG_SAVER GEDIT_DEBUG_SAVER, __FILE__, __LINE__, G_STRFUNC
void gedit_debug_init (void);
......
......@@ -275,6 +275,8 @@ update_document_contents (GeditDocumentLoader *loader,
gint file_size,
GError **error)
{
gedit_debug (DEBUG_SAVER);
g_return_val_if_fail (file_size > 0, FALSE);
g_return_val_if_fail (file_contents != NULL, FALSE);
......@@ -470,8 +472,6 @@ stat_to_file_info (GnomeVFSFileInfo *file_info,
static void
load_completed_or_failed (GeditDocumentLoader *loader)
{
gedit_debug (DEBUG_DOCUMENT);
/* the object will be unrefed in the callback of the loading
* signal, so we need to prevent finalization.
*/
......@@ -483,7 +483,10 @@ load_completed_or_failed (GeditDocumentLoader *loader)
TRUE, /* completed */
loader->priv->error);
gedit_debug_message (DEBUG_DOCUMENT, "unref");
if (loader->priv->error == NULL)
gedit_debug_message (DEBUG_LOADER, "load completed");
else
gedit_debug_message (DEBUG_LOADER, "load failed");
g_object_unref (loader);
}
......@@ -540,6 +543,8 @@ load_local_file_real (GeditDocumentLoader *loader)
if (mapped_file == MAP_FAILED)
{
gedit_debug_message (DEBUG_SAVER, "mmap failed");
result = gnome_vfs_result_from_errno ();
g_set_error (&loader->priv->error,
......@@ -613,6 +618,8 @@ static void
load_local_file (GeditDocumentLoader *loader,
const gchar *fname)
{
gedit_debug (DEBUG_SAVER);
g_signal_emit (loader,
signals[LOADING],
0,
......@@ -661,8 +668,6 @@ async_close_cb (GnomeVFSAsyncHandle *handle,
static void
remote_load_completed_or_failed (GeditDocumentLoader *loader)
{
gedit_debug (DEBUG_DOCUMENT);
/* free the buffer and close the handle */
gnome_vfs_async_close (loader->priv->handle,
async_close_cb,
......@@ -689,6 +694,8 @@ async_read_cb (GnomeVFSAsyncHandle *handle,
{
GeditDocumentLoader *loader = GEDIT_DOCUMENT_LOADER (data);
gedit_debug (DEBUG_LOADER);
/* reality checks. */
g_return_if_fail (bytes_requested == READ_CHUNK_SIZE);
g_return_if_fail (loader->priv->handle == handle);
......@@ -772,6 +779,8 @@ remote_get_info_cb (GnomeVFSAsyncHandle *handle,
GeditDocumentLoader *loader = GEDIT_DOCUMENT_LOADER (data);
GnomeVFSGetFileInfoResult *info_result;
gedit_debug (DEBUG_LOADER);
/* assert that the list has one and only one item */
g_return_if_fail (results != NULL && results->next == NULL);
......@@ -820,6 +829,8 @@ async_open_callback (GnomeVFSAsyncHandle *handle,
{
GList *uri_list = NULL;
gedit_debug (DEBUG_LOADER);
g_return_if_fail (loader->priv->handle == handle);
if (result != GNOME_VFS_OK)
......@@ -858,6 +869,8 @@ async_open_callback (GnomeVFSAsyncHandle *handle,
static void
load_remote_file (GeditDocumentLoader *loader)
{
gedit_debug (DEBUG_LOADER);
g_return_if_fail (loader->priv->handle == NULL);
/* loading start */
......@@ -894,6 +907,8 @@ gedit_document_loader_load (GeditDocumentLoader *loader,
{
gchar *local_path;
gedit_debug (DEBUG_LOADER);
g_return_if_fail (GEDIT_IS_DOCUMENT_LOADER (loader));
g_return_if_fail (uri != NULL);
......@@ -992,7 +1007,7 @@ gedit_document_loader_get_bytes_read (GeditDocumentLoader *loader)
gboolean
gedit_document_loader_cancel (GeditDocumentLoader *loader)
{
gedit_debug (DEBUG_DOCUMENT);
gedit_debug (DEBUG_LOADER);
g_return_val_if_fail (GEDIT_IS_DOCUMENT_LOADER (loader), FALSE);
......
......@@ -44,13 +44,16 @@
#include <libgnomevfs/gnome-vfs.h>
#include "gedit-document-saver.h"
#include "gedit-debug.h"
#include "gedit-convert.h"
#include "gedit-metadata-manager.h"
#include "gedit-prefs-manager.h"
#include "gedit-marshal.h"
#include "gedit-utils.h"
#define GEDIT_DOCUMENT_SAVER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_DOCUMENT_SAVER, GeditDocumentSaverPrivate))
#define GEDIT_DOCUMENT_SAVER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \
GEDIT_TYPE_DOCUMENT_SAVER, \
GeditDocumentSaverPrivate))
struct _GeditDocumentSaverPrivate
{
......@@ -187,6 +190,8 @@ write_document_contents (gint fd,
ssize_t written;
gboolean res;
gedit_debug (DEBUG_SAVER);
gtk_text_buffer_get_bounds (doc, &start_iter, &end_iter);
contents = gtk_text_buffer_get_slice (doc, &start_iter, &end_iter, TRUE);
......@@ -296,6 +301,11 @@ save_completed_or_failed (GeditDocumentSaver *saver)
TRUE, /* completed */
saver->priv->error);
if (saver->priv->error == NULL)
gedit_debug_message (DEBUG_SAVER, "save completed");
else
gedit_debug_message (DEBUG_SAVER, "save failed");
g_object_unref (saver);
}
......@@ -366,6 +376,8 @@ copy_file_data (gint sfd,
ssize_t bytes_to_write;
ssize_t bytes_written;
gedit_debug (DEBUG_SAVER);
buffer = g_malloc (BUFSIZE);
do
......@@ -455,6 +467,8 @@ save_existing_local_file (GeditDocumentSaver *saver)
gchar *backup_filename = NULL;
gboolean backup_created = FALSE;
gedit_debug (DEBUG_SAVER);
if (fstat (saver->priv->fd, &statbuf) != 0)
{
GnomeVFSResult result = gnome_vfs_result_from_errno ();
......@@ -550,6 +564,8 @@ save_existing_local_file (GeditDocumentSaver *saver)
gchar *tmp_filename;
gint tmpfd;
gedit_debug_message (DEBUG_SAVER, "tmp file moving strategy");
dirname = g_path_get_dirname (saver->priv->local_path);
tmp_filename = g_build_filename (dirname, ".gedit-save-XXXXXX", NULL);
g_free (dirname);
......@@ -563,6 +579,8 @@ save_existing_local_file (GeditDocumentSaver *saver)
if (tmpfd == -1)
{
gedit_debug_message (DEBUG_SAVER, "could not create tmp file");
g_free (tmp_filename);
goto fallback_strategy;
}
......@@ -571,9 +589,12 @@ save_existing_local_file (GeditDocumentSaver *saver)
if (fchown (tmpfd, statbuf.st_uid, statbuf.st_gid) == -1 ||
fchmod (tmpfd, statbuf.st_mode) == -1)
{
gedit_debug_message (DEBUG_SAVER, "could not set perms");
close (tmpfd);
unlink (tmp_filename);
g_free (tmp_filename);
goto fallback_strategy;
}
......@@ -582,9 +603,12 @@ save_existing_local_file (GeditDocumentSaver *saver)
saver->priv->encoding,
&saver->priv->error))
{
gedit_debug_message (DEBUG_SAVER, "could not write tmp file");
close (tmpfd);
unlink (tmp_filename);
g_free (tmp_filename);
goto out;
}
......@@ -593,6 +617,8 @@ save_existing_local_file (GeditDocumentSaver *saver)
{
GnomeVFSResult result = gnome_vfs_result_from_errno ();
gedit_debug_message (DEBUG_SAVER, "could not rename original -> backup");
g_set_error (&saver->priv->error,
GEDIT_DOCUMENT_ERROR,
result,
......@@ -601,6 +627,7 @@ save_existing_local_file (GeditDocumentSaver *saver)
close (tmpfd);
unlink (tmp_filename);
g_free (tmp_filename);
goto out;
}
......@@ -609,6 +636,8 @@ save_existing_local_file (GeditDocumentSaver *saver)
{
GnomeVFSResult result = gnome_vfs_result_from_errno ();
gedit_debug_message (DEBUG_SAVER, "could not rename tmp -> original");
g_set_error (&saver->priv->error,
GEDIT_DOCUMENT_ERROR,
result,
......@@ -620,6 +649,7 @@ save_existing_local_file (GeditDocumentSaver *saver)
close (tmpfd);
unlink (tmp_filename);
g_free (tmp_filename);
goto out;
}
......@@ -653,6 +683,8 @@ save_existing_local_file (GeditDocumentSaver *saver)
fallback_strategy:
gedit_debug_message (DEBUG_SAVER, "fallback strategy");
/* try to copy the old contents in a backup for safety
* unless we are explicetely told not to.
*/
......@@ -660,9 +692,13 @@ save_existing_local_file (GeditDocumentSaver *saver)
{
gint bfd;
gedit_debug_message (DEBUG_SAVER, "copying to backup");
/* move away old backups */
if (!remove_file (backup_filename))
{
gedit_debug_message (DEBUG_SAVER, "could not remove old backup");
/* we don't care about which was the problem, just
* that a backup was not possible.
*/
......@@ -680,6 +716,8 @@ save_existing_local_file (GeditDocumentSaver *saver)
if (bfd == -1)
{
gedit_debug_message (DEBUG_SAVER, "could not create backup");
g_set_error (&saver->priv->error,
GEDIT_DOCUMENT_ERROR,
GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
......@@ -694,10 +732,14 @@ save_existing_local_file (GeditDocumentSaver *saver)
* others. */
if (fchown (bfd, (uid_t) -1, statbuf.st_gid) != 0)
{
gedit_debug_message (DEBUG_SAVER, "could not restore group");
if (fchmod (bfd,
(statbuf.st_mode& 0707) |
((statbuf.st_mode & 07) << 3)) != 0)
{
gedit_debug_message (DEBUG_SAVER, "could not even clear group perms");
g_set_error (&saver->priv->error,
GEDIT_DOCUMENT_ERROR,
GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
......@@ -712,6 +754,8 @@ save_existing_local_file (GeditDocumentSaver *saver)
if (!copy_file_data (saver->priv->fd, bfd, NULL))
{
gedit_debug_message (DEBUG_SAVER, "could not copy data into the backup");
g_set_error (&saver->priv->error,
GEDIT_DOCUMENT_ERROR,
GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
......@@ -780,6 +824,8 @@ save_new_local_file (GeditDocumentSaver *saver)
{
struct stat statbuf;
gedit_debug (DEBUG_SAVER);
if (!write_document_contents (saver->priv->fd,
GTK_TEXT_BUFFER (saver->priv->document),
saver->priv->encoding,
......@@ -835,6 +881,8 @@ save_local_file (GeditDocumentSaver *saver)
GSourceFunc next_phase;
GnomeVFSResult result;
gedit_debug (DEBUG_SAVER);
/* saving start */
g_signal_emit (saver,
signals[SAVING],
......@@ -901,6 +949,8 @@ remote_get_info_cb (GnomeVFSAsyncHandle *handle,
GeditDocumentSaver *saver = GEDIT_DOCUMENT_SAVER (data);
GnomeVFSGetFileInfoResult *info_result;
gedit_debug (DEBUG_SAVER);
/* assert that the list has one and only one item */
g_return_if_fail (results != NULL && results->next == NULL);
......@@ -935,6 +985,8 @@ static gint
async_xfer_ok (GnomeVFSXferProgressInfo *progress_info,
GeditDocumentSaver *saver)
{
gedit_debug_message (DEBUG_SAVER, "xfer phase: %d", progress_info->phase);
switch (progress_info->phase)
{
case GNOME_VFS_XFER_PHASE_INITIAL:
......@@ -1075,6 +1127,8 @@ static gint
async_xfer_error (GnomeVFSXferProgressInfo *progress_info,
GeditDocumentSaver *saver)
{
gedit_debug (DEBUG_SAVER);
g_set_error (&saver->priv->error,
GEDIT_DOCUMENT_ERROR,
progress_info->vfs_status,
......@@ -1117,6 +1171,8 @@ save_remote_file_real (GeditDocumentSaver *saver)
GList *dest_uri_list = NULL;
GnomeVFSResult result;
gedit_debug (DEBUG_SAVER);
/* For remote files we use the following strategy:
* we save to a local temp file and then transfer it
* over to the requested location asyncronously.
......@@ -1171,6 +1227,8 @@ save_remote_file_real (GeditDocumentSaver *saver)
goto error;
}
gedit_debug_message (DEBUG_SAVER, "Saved local copy, starting xfer");
result = gnome_vfs_async_xfer (&saver->priv->handle,
source_uri_list,
dest_uri_list,
......@@ -1208,6 +1266,8 @@ save_remote_file_real (GeditDocumentSaver *saver)
static void
save_remote_file (GeditDocumentSaver *saver)
{
gedit_debug (DEBUG_SAVER);
/* saving start */
g_signal_emit (saver,
signals[SAVING],
......@@ -1236,6 +1296,8 @@ gedit_document_saver_save (GeditDocumentSaver *saver,
g_return_if_fail (GEDIT_IS_DOCUMENT_SAVER (saver));
g_return_if_fail ((uri != NULL) && (strlen (uri) > 0));
gedit_debug (DEBUG_SAVER);
// CHECK:
// - sanity check a max len for the uri?
// report async (in an idle handler) or sync (bool ret)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment