cpw.nader.asynclogging-3: a2b193a6: Replaced all the g_stat stuff with GFile...

morshed.nader at gmail.com morshed.nader at gmail.com
Tue Jan 11 23:28:11 EST 2011


----------------------------------------------------------------------
Revision: a2b193a64b7890e064a8c48e37b0c2b0f753a329
Parent:   5dcc469a155e3384d5d6adf07cf4229633cc9dad
Author:   morshed.nader at gmail.com
Date:     01/11/11 22:42:06
Branch:   im.pidgin.cpw.nader.asynclogging-3
URL: http://d.pidgin.im/viewmtn/revision/info/a2b193a64b7890e064a8c48e37b0c2b0f753a329

Changelog: 

Replaced all the g_stat stuff with GFileInfo queries

Changes against parent 5dcc469a155e3384d5d6adf07cf4229633cc9dad

  patched  libpurple/log.c

-------------- next part --------------
============================================================
--- libpurple/log.c	224d1d377ac7d62ed2d31962910eac5d5cf4f4ba
+++ libpurple/log.c	424796426e3e320407321fa814e3a278daa110c1
@@ -2992,23 +2992,33 @@ purple_log_common_total_sizer(PurpleLogC
 		}
 
 		if (purple_str_has_suffix(filename, ext) &&
-		    strlen(filename) >= 17 + strlen(ext)) {
-			struct stat st;
+		    strlen(filename) >= 17 + strlen(ext))
+		{
+			GFile *file;
+			GFileInfo *info;
 			gchar *tmp = g_build_filename(path, filename, NULL);
+			guint64 file_size;
 
-			if (g_stat(tmp, &st)) {
-				g_free(tmp);
+			file = g_file_new_for_path(tmp);
+			info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
+				G_FILE_QUERY_INFO_NONE, cancellable, error);
 
-				g_set_error_literal(error,
-					G_FILE_ERROR,
-					g_file_error_from_errno(errno),
-					g_strerror(errno));
+			if (info == NULL) {
+				g_dir_close(dir);
+				g_object_unref(file);
+				g_free(path);
+				g_free(tmp);
 
 				return -1;
 			}
 
+			file_size = g_file_info_get_attribute_uint64(info,
+				G_FILE_ATTRIBUTE_STANDARD_SIZE);
+			size += file_size;
+
+			g_object_unref(info);
+			g_object_unref(file);
 			g_free(tmp);
-			size += st.st_size;
 		}
 	}
 
@@ -3099,9 +3109,11 @@ purple_log_common_sizer(PurpleLog *log, 
 purple_log_common_sizer(PurpleLog *log, GCancellable *cancellable, GError **error)
 {
 	PurpleLogCommonLoggerData *data;
-	struct stat st;
+	GFile *file;
+	GFileInfo *info;
+	guint64 file_size;
 
-	g_return_val_if_fail(PURPLE_IS_LOG(log), 0);
+	g_return_val_if_fail(PURPLE_IS_LOG(log), -1);
 
 	data = purple_log_get_logger_data(log);
 
@@ -3112,16 +3124,25 @@ purple_log_common_sizer(PurpleLog *log, 
 			_("Unable to get log path"));
 
 		return -1;
-	} else if (g_stat(data->path, &st)) {
-		g_set_error_literal(error,
-			G_FILE_ERROR,
-			g_file_error_from_errno(errno),
-			g_strerror(errno));
+	}
 
+	file = g_file_new_for_path(data->path);
+	info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
+		G_FILE_QUERY_INFO_NONE, cancellable, error);
+
+	if (info == NULL) {
+		g_object_unref(file);
+
 		return -1;
 	}
 
-	return st.st_size;
+	file_size = g_file_info_get_attribute_uint64(info,
+		G_FILE_ATTRIBUTE_STANDARD_SIZE);
+
+	g_object_unref(info);
+	g_object_unref(file);
+
+	return file_size;
 }
 
 static void


More information about the Commits mailing list