[tracker/tracker-0.10] libtracker-common, tracker-extract: Use of path vs. uri is wrong here



commit 65fe93fba1c3e549fd3199027f1db239b2a77eaf
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Feb 23 18:10:59 2011 +0100

    libtracker-common, tracker-extract: Use of path vs. uri is wrong here

 src/libtracker-common/tracker-file-utils.c |   42 ++++++++++++++++++++++++---
 src/libtracker-common/tracker-file-utils.h |    6 ++-
 src/tracker-extract/tracker-albumart.c     |    5 ++-
 3 files changed, 44 insertions(+), 9 deletions(-)
---
diff --git a/src/libtracker-common/tracker-file-utils.c b/src/libtracker-common/tracker-file-utils.c
index 122142d..f6a6c1b 100644
--- a/src/libtracker-common/tracker-file-utils.c
+++ b/src/libtracker-common/tracker-file-utils.c
@@ -134,17 +134,14 @@ tracker_file_get_size (const gchar *path)
 	return size;
 }
 
+static
 guint64
-tracker_file_get_mtime (const gchar *path)
+file_get_mtime (GFile *file)
 {
 	GFileInfo *info;
-	GFile     *file;
 	GError    *error = NULL;
 	guint64    mtime;
 
-	g_return_val_if_fail (path != NULL, 0);
-
-	file = g_file_new_for_path (path);
 	info = g_file_query_info (file,
 	                          G_FILE_ATTRIBUTE_TIME_MODIFIED,
 	                          G_FILE_QUERY_INFO_NONE,
@@ -152,9 +149,11 @@ tracker_file_get_mtime (const gchar *path)
 	                          &error);
 
 	if (G_UNLIKELY (error)) {
+		gchar *path = g_file_get_path (file);
 		g_message ("Could not get mtime for '%s', %s",
 		           path,
 		           error->message);
+		g_free (path);
 		g_error_free (error);
 		mtime = 0;
 	} else {
@@ -162,6 +161,39 @@ tracker_file_get_mtime (const gchar *path)
 		g_object_unref (info);
 	}
 
+	return mtime;
+}
+
+guint64
+tracker_file_get_mtime (const gchar *path)
+{
+	GFile     *file;
+	guint64    mtime;
+
+	g_return_val_if_fail (path != NULL, 0);
+
+	file = g_file_new_for_path (path);
+
+	mtime = file_get_mtime (file);
+
+	g_object_unref (file);
+
+	return mtime;
+}
+
+
+guint64
+tracker_file_get_mtime_uri (const gchar *uri)
+{
+	GFile     *file;
+	guint64    mtime;
+
+	g_return_val_if_fail (uri != NULL, 0);
+
+	file = g_file_new_for_uri (uri);
+
+	mtime = file_get_mtime (file);
+
 	g_object_unref (file);
 
 	return mtime;
diff --git a/src/libtracker-common/tracker-file-utils.h b/src/libtracker-common/tracker-file-utils.h
index eebd360..4a308df 100644
--- a/src/libtracker-common/tracker-file-utils.h
+++ b/src/libtracker-common/tracker-file-utils.h
@@ -37,8 +37,10 @@ FILE*    tracker_file_open          (const gchar  *uri,
                                      gboolean      sequential);
 void     tracker_file_close         (FILE         *file,
                                      gboolean      need_again_soon);
-goffset  tracker_file_get_size      (const gchar  *uri);
-guint64  tracker_file_get_mtime     (const gchar  *uri);
+goffset  tracker_file_get_size      (const gchar  *path);
+guint64  tracker_file_get_mtime     (const gchar  *path);
+guint64  tracker_file_get_mtime_uri (const gchar  *uri);
+
 gchar *  tracker_file_get_mime_type (GFile        *file);
 gboolean tracker_file_lock          (GFile        *file);
 gboolean tracker_file_unlock        (GFile        *file);
diff --git a/src/tracker-extract/tracker-albumart.c b/src/tracker-extract/tracker-albumart.c
index cbf44ab..8d49292 100644
--- a/src/tracker-extract/tracker-albumart.c
+++ b/src/tracker-extract/tracker-albumart.c
@@ -781,6 +781,7 @@ tracker_albumart_process (const unsigned char *buffer,
 	gchar *local_uri = NULL;
 	gchar *filename_uri;
 	guint64 mtime, a_mtime = 0;
+	GFile *mfile;
 
 	g_debug ("Processing album art, buffer is %ld bytes, artist:'%s', album:'%s', filename:'%s', mime:'%s'",
 	         (long int) len,
@@ -791,12 +792,12 @@ tracker_albumart_process (const unsigned char *buffer,
 
 	if (strstr (filename, "://")) {
 		filename_uri = g_strdup (filename);
+		mtime = tracker_file_get_mtime_uri (filename);
 	} else {
 		filename_uri = g_filename_to_uri (filename, NULL, NULL);
+		mtime = tracker_file_get_mtime (filename);
 	}
 
-	mtime = tracker_file_get_mtime (filename);
-
 	albumart_get_path (artist,
 	                   album,
 	                   "album",



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]