cpw.nader.asynclogging-3: 738865ce: Fixed total_size_async to properly grab ...

morshed.nader at gmail.com morshed.nader at gmail.com
Thu Jan 5 19:16:47 EST 2012


----------------------------------------------------------------------
Revision: 738865ce749562495b65abdcc8acdf28c707f0f5
Parent:   cf82f1a3c70f063a56c4d9797400126f88f30a0f
Author:   morshed.nader at gmail.com
Date:     01/05/12 10:59:33
Branch:   im.pidgin.cpw.nader.asynclogging-3
URL: http://d.pidgin.im/viewmtn/revision/info/738865ce749562495b65abdcc8acdf28c707f0f5

Changelog: 

Fixed total_size_async to properly grab the child file names and screen out by extension

Changes against parent cf82f1a3c70f063a56c4d9797400126f88f30a0f

  patched  libpurple/commonlog.c

-------------- next part --------------
============================================================
--- libpurple/commonlog.c	368445850bb030be3cc0b4d8d30a7a3a4802189e
+++ libpurple/commonlog.c	a43ac6e3d93cf668e6e8aa381e87e096cb080a5c
@@ -142,6 +142,7 @@ typedef struct {
 	GAsyncReadyCallback cb;
 	gpointer userdata;
 	guint64 total;
+	GFile *dir;
 } total_size_callback_data;
 
 
@@ -212,6 +213,7 @@ total_size_callback_data_free(gpointer u
 	g_free(data->name);
 	g_free(data->ext);
 	g_object_unref(data->cancel);
+	g_object_unref(data->dir);
 	g_free(data);
 }
 
@@ -1217,7 +1219,6 @@ purple_common_log_total_size_async(Purpl
 	gint io_priority, GCancellable *cancellable, GAsyncReadyCallback cb,
 	gpointer userdata)
 {
-	GFile *dir;
 	gchar *path;
 	total_size_callback_data *data;
 
@@ -1233,14 +1234,14 @@ purple_common_log_total_size_async(Purpl
 	data->total = 0;
 
 	path = purple_log_get_log_dir(chat_type, name, account);
-	dir = g_file_new_for_path(path);
+	data->dir = g_file_new_for_path(path);
 
-	g_file_enumerate_children_async(dir, G_FILE_ATTRIBUTE_STANDARD_SIZE,
+	g_file_enumerate_children_async(data->dir,
+		G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_SIZE,
 		G_FILE_QUERY_INFO_NONE, io_priority, cancellable,
 		purple_common_log_total_size_async_2, data);
 
 	g_free(path);
-	g_object_unref(dir);
 }
 
 static void
@@ -1271,12 +1272,12 @@ purple_common_log_total_size_async_3(GOb
 {
 	GError *err = NULL;
 	GFileEnumerator *enumerator = G_FILE_ENUMERATOR(object);
-	GList *files, *file;
+	GList *file_infos, *file;
 	total_size_callback_data *data = userdata;
 
-	files = g_file_enumerator_next_files_finish(enumerator, res, &err);
+	file_infos = g_file_enumerator_next_files_finish(enumerator, res, &err);
 
-	if (files == NULL) {
+	if (file_infos == NULL) {
 		if (err != NULL) {
 			SIMPLE_ASYNC_RESULT_FROM_ERROR(enumerator, data->cb, data->userdata,
 				err);
@@ -1292,24 +1293,30 @@ purple_common_log_total_size_async_3(GOb
 		return;
 	}
 
-	for (file = files; file != NULL; file = file->next) {
+	for (file = file_infos; file != NULL; file = file->next) {
+		GFile *child_file;
 		GFileInfo *info = file->data;
-		const gchar *path;
+		gchar *child_path;
 		goffset size;
 
-		path = g_file_info_get_name(info);
+		child_file = g_file_get_child(data->dir, g_file_info_get_name(info));
+		child_path = g_file_get_path(child_file);
+		g_object_unref(child_file);
+
 		size = g_file_info_get_size(info);
 		g_assert(size >= 0);
 
-		g_object_unref(info);
-
-		if (!purple_str_has_suffix(path, data->ext))
+		if (!purple_str_has_suffix(child_path, data->ext)) {
+			g_free(child_path);
 			continue;
+		}
 
+		g_free(child_path);
 		data->total += size;
 	}
 
-	g_list_free(files);
+	g_list_foreach(file_infos, (GFunc) g_object_unref, NULL);
+	g_list_free(file_infos);
 
 	g_file_enumerator_next_files_async(enumerator, 20, data->io_priority,
 		data->cancel, purple_common_log_total_size_async_3, data);


More information about the Commits mailing list