tracker r2943 - in trunk: . src/libtracker-common src/libtracker-db src/tracker-extract src/tracker-indexer
- From: mr svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2943 - in trunk: . src/libtracker-common src/libtracker-db src/tracker-extract src/tracker-indexer
- Date: Wed, 18 Feb 2009 18:56:23 +0000 (UTC)
Author: mr
Date: Wed Feb 18 18:56:22 2009
New Revision: 2943
URL: http://svn.gnome.org/viewvc/tracker?rev=2943&view=rev
Log:
* src/libtracker-db/tracker-db-file-info.c:
* src/tracker-extract/tracker-extract-gstreamer.c:
* src/tracker-extract/tracker-extract-jpeg.c:
* src/tracker-extract/tracker-extract-png.c:
* src/tracker-extract/tracker-extract-tiff.c:
* src/tracker-indexer/tracker-indexer.c: Use
tracker_file_get_mtime() instead of using g_lstat() everywhere.
Modified:
trunk/ChangeLog
trunk/src/libtracker-common/tracker-file-utils.c
trunk/src/libtracker-common/tracker-file-utils.h
trunk/src/libtracker-db/tracker-db-file-info.c
trunk/src/tracker-extract/tracker-extract-gstreamer.c
trunk/src/tracker-extract/tracker-extract-jpeg.c
trunk/src/tracker-extract/tracker-extract-png.c
trunk/src/tracker-extract/tracker-extract-tiff.c
trunk/src/tracker-indexer/tracker-indexer.c
Modified: trunk/src/libtracker-common/tracker-file-utils.c
==============================================================================
--- trunk/src/libtracker-common/tracker-file-utils.c (original)
+++ trunk/src/libtracker-common/tracker-file-utils.c Wed Feb 18 18:56:22 2009
@@ -70,20 +70,6 @@
return fd;
}
-void
-tracker_file_close (gint fd,
- gboolean no_longer_needed)
-{
-
-#ifdef HAVE_POSIX_FADVISE
- if (no_longer_needed) {
- posix_fadvise (fd, 0, 0, POSIX_FADV_DONTNEED);
- }
-#endif
-
- close (fd);
-}
-
gboolean
tracker_file_unlink (const gchar *uri)
{
@@ -97,166 +83,90 @@
return result;
}
-guint32
+goffset
tracker_file_get_size (const gchar *uri)
{
- struct stat finfo;
-
- if (g_lstat (uri, &finfo) == -1) {
- return 0;
- } else {
- return (guint32) finfo.st_size;
- }
-}
-
-static inline gboolean
-is_utf8 (const gchar *buffer,
- gint buffer_length)
-{
- gchar *end;
-
- /* Code in this function modified from gnome-vfs */
- if (g_utf8_validate ((gchar*) buffer,
- buffer_length,
- (const gchar**) &end)) {
- return TRUE;
- } else {
- /* Check whether the string was truncated in the middle of
- * a valid UTF8 char, or if we really have an invalid
- * UTF8 string.
- */
- gunichar validated;
- gint remaining_bytes;
-
- remaining_bytes = buffer_length;
- remaining_bytes -= end - ((gchar *) buffer);
-
- if (remaining_bytes > 4) {
- return FALSE;
- }
-
- validated = g_utf8_get_char_validated (end, (gsize) remaining_bytes);
-
- if (validated == (gunichar) - 2) {
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-gboolean
-tracker_file_is_valid (const gchar *uri)
-{
- gchar *str;
- gboolean is_valid = TRUE;
-
- str = g_filename_from_utf8 (uri, -1, NULL, NULL, NULL);
+ GFileInfo *info;
+ GFile *file;
+ GError *error = NULL;
+ goffset size;
- if (!str) {
- g_warning ("URI:'%s' could not be converted to locale format",
- uri);
- return FALSE;
- }
+ g_return_val_if_fail (uri != NULL, 0);
- /* g_file_test (file,G_FILE_TEST_EXISTS) uses the access ()
- * system call and so needs locale filenames.
+ /* NOTE: We will need to fix this in Jurg's branch and call
+ * the _for_uri() variant.
*/
- is_valid &= uri != NULL;
- is_valid &= g_file_test (str,
- G_FILE_TEST_IS_REGULAR |
- G_FILE_TEST_IS_DIR |
- G_FILE_TEST_IS_SYMLINK);
-
- g_free (str);
-
- return is_valid;
-}
-
-gboolean
-tracker_file_is_directory (const gchar *uri)
-{
- gchar *str;
- gboolean is_directory;
-
- str = g_filename_from_utf8 (uri, -1, NULL, NULL, NULL);
-
- if (!str) {
- g_warning ("URI:'%s' could not be converted to locale format",
- str);
- return FALSE;
- }
-
- is_directory = g_file_test (str, G_FILE_TEST_IS_DIR);
- g_free (str);
-
- return is_directory;
-}
-
-gboolean
-tracker_file_is_indexable (const gchar *uri)
-{
- gchar *str;
- struct stat finfo;
- gboolean is_indexable;
-
- g_return_val_if_fail (uri != NULL, FALSE);
-
- str = g_filename_from_utf8 (uri, -1, NULL, NULL, NULL);
+ file = g_file_new_for_path (uri);
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_SIZE,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ &error);
- if (!str) {
- g_warning ("URI:'%s' could not be converted to locale format",
- str);
- return FALSE;
+ if (G_UNLIKELY (error)) {
+ g_message ("Could not get size for '%s', %s",
+ uri,
+ error->message);
+ g_error_free (error);
+ size = 0;
+ } else {
+ size = g_file_info_get_size (info);
+ g_object_unref (info);
}
- g_lstat (str, &finfo);
- g_free (str);
-
- is_indexable = TRUE;
- is_indexable &= !S_ISDIR (finfo.st_mode);
- is_indexable &= S_ISREG (finfo.st_mode);
-
- g_debug ("URI:'%s' %s indexable",
- uri,
- is_indexable ? "is" : "is not");
+ g_object_unref (file);
- return is_indexable;
+ return size;
}
-gint32
+guint64
tracker_file_get_mtime (const gchar *uri)
{
- struct stat finfo;
- gchar *str;
+ GFileInfo *info;
+ GFile *file;
+ GError *error = NULL;
+ guint64 mtime;
- str = g_filename_from_utf8 (uri, -1, NULL, NULL, NULL);
+ g_return_val_if_fail (uri != NULL, 0);
- if (str) {
- if (g_lstat (str, &finfo) == -1) {
- g_free (str);
- return 0;
- }
+ /* NOTE: We will need to fix this in Jurg's branch and call
+ * the _for_uri() variant.
+ */
+ file = g_file_new_for_path (uri);
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ &error);
+
+ if (G_UNLIKELY (error)) {
+ g_message ("Could not get mtime for '%s', %s",
+ uri,
+ error->message);
+ g_error_free (error);
+ mtime = 0;
} else {
- g_warning ("URI:'%s' could not be converted to locale format",
- uri);
- return 0;
+ mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ g_object_unref (info);
}
- g_free (str);
+ g_object_unref (file);
- return (gint32) finfo.st_mtime;
+ return mtime;
}
gchar *
-tracker_file_get_mime_type (const gchar *path)
+tracker_file_get_mime_type (const gchar *uri)
{
GFileInfo *info;
GFile *file;
GError *error = NULL;
gchar *content_type;
- file = g_file_new_for_path (path);
+ /* NOTE: We will need to fix this in Jurg's branch and call
+ * the _for_uri() variant.
+ */
+ file = g_file_new_for_path (uri);
info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_QUERY_INFO_NONE,
@@ -264,7 +174,7 @@
&error);
if (G_UNLIKELY (error)) {
- g_message ("Could not guess mimetype, %s\n",
+ g_message ("Could not guess mimetype, %s",
error->message);
g_error_free (error);
content_type = NULL;
@@ -394,8 +304,6 @@
}
-
-
void
tracker_path_remove (const gchar *uri)
{
Modified: trunk/src/libtracker-common/tracker-file-utils.h
==============================================================================
--- trunk/src/libtracker-common/tracker-file-utils.h (original)
+++ trunk/src/libtracker-common/tracker-file-utils.h Wed Feb 18 18:56:22 2009
@@ -30,14 +30,9 @@
gint tracker_file_open (const gchar *uri,
gboolean readahead);
-void tracker_file_close (gint fd,
- gboolean no_longer_needed);
gboolean tracker_file_unlink (const gchar *uri);
-gboolean tracker_file_is_valid (const gchar *uri);
-gboolean tracker_file_is_directory (const gchar *uri);
-gboolean tracker_file_is_indexable (const gchar *uri);
-guint32 tracker_file_get_size (const gchar *uri);
-gint32 tracker_file_get_mtime (const gchar *uri);
+goffset tracker_file_get_size (const gchar *uri);
+guint64 tracker_file_get_mtime (const gchar *uri);
gchar * tracker_file_get_mime_type (const gchar *uri);
void tracker_file_get_path_and_name (const gchar *uri,
gchar **path,
Modified: trunk/src/libtracker-db/tracker-db-file-info.c
==============================================================================
--- trunk/src/libtracker-db/tracker-db-file-info.c (original)
+++ trunk/src/libtracker-db/tracker-db-file-info.c Wed Feb 18 18:56:22 2009
@@ -268,25 +268,32 @@
TrackerDBFileInfo *
tracker_db_file_info_get (TrackerDBFileInfo *info)
{
- struct stat finfo;
+ GError *error = NULL;
gchar *str, *uri_in_locale;
+ struct stat finfo;
if (!info || !info->uri) {
return info;
}
- uri_in_locale = g_filename_from_utf8 (info->uri, -1, NULL, NULL, NULL);
+ uri_in_locale = g_filename_from_utf8 (info->uri,
+ -1,
+ NULL,
+ NULL,
+ &error);
- if (uri_in_locale) {
+ if (G_LIKELY (!error)) {
if (g_lstat (uri_in_locale, &finfo) == -1) {
g_free (uri_in_locale);
return info;
}
-
} else {
- g_warning ("URI:'%s' could not be converted to locale format",
- info->uri);
+ g_message ("Could not convert URI:'%s' to locale format, %s",
+ info->uri,
+ error->message);
+ g_error_free (error);
+
return NULL;
}
@@ -297,7 +304,7 @@
str = g_file_read_link (uri_in_locale, NULL);
if (str) {
- char *link_uri;
+ gchar *link_uri;
link_uri = g_filename_to_utf8 (str, -1, NULL, NULL, NULL);
info->link_name = g_path_get_basename (link_uri);
@@ -320,8 +327,8 @@
g_free (info->permissions);
info->permissions = tracker_create_permission_string (finfo);
- info->mtime = finfo.st_mtime;
- info->atime = finfo.st_atime;
+ info->mtime = finfo.st_mtime;
+ info->atime = finfo.st_atime;
return info;
}
Modified: trunk/src/tracker-extract/tracker-extract-gstreamer.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-gstreamer.c (original)
+++ trunk/src/tracker-extract/tracker-extract-gstreamer.c Wed Feb 18 18:56:22 2009
@@ -986,18 +986,16 @@
}
} else if (type == EXTRACT_MIME_IMAGE) {
if (!g_hash_table_lookup (metadata, "Image:Date")) {
- struct stat st;
-
- if (g_lstat (uri, &st) >= 0) {
- gchar *date;
-
- date = tracker_date_to_string (st.st_mtime);
+ gchar *date;
+ guint64 mtime;
+
+ mtime = tracker_file_get_mtime (uri);
+ date = tracker_date_to_string ((time_t) mtime);
- g_hash_table_insert (metadata,
- g_strdup ("Image:Date"),
- tracker_escape_metadata (date));
- g_free (date);
- }
+ g_hash_table_insert (metadata,
+ g_strdup ("Image:Date"),
+ tracker_escape_metadata (date));
+ g_free (date);
}
}
Modified: trunk/src/tracker-extract/tracker-extract-jpeg.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-jpeg.c (original)
+++ trunk/src/tracker-extract/tracker-extract-jpeg.c Wed Feb 18 18:56:22 2009
@@ -39,6 +39,7 @@
#include <jpeglib.h>
#include <libtracker-common/tracker-type-utils.h>
+#include <libtracker-common/tracker-file-utils.h>
#include "tracker-main.h"
#include "tracker-xmp.h"
@@ -349,18 +350,16 @@
/* Check that we have the minimum data. FIXME We should not need to do this */
if (!g_hash_table_lookup (metadata, "Image:Date")) {
- struct stat st;
+ gchar *date;
+ guint64 mtime;
- if (g_lstat(filename, &st) >= 0) {
- gchar *date;
+ mtime = tracker_file_get_mtime (filename);
+ date = tracker_date_to_string ((time_t) mtime);
- date = tracker_date_to_string (st.st_mtime);
-
- g_hash_table_insert (metadata,
- g_strdup ("Image:Date"),
- tracker_escape_metadata (date));
- g_free (date);
- }
+ g_hash_table_insert (metadata,
+ g_strdup ("Image:Date"),
+ tracker_escape_metadata (date));
+ g_free (date);
}
jpeg_destroy_decompress (&cinfo);
Modified: trunk/src/tracker-extract/tracker-extract-png.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-png.c (original)
+++ trunk/src/tracker-extract/tracker-extract-png.c Wed Feb 18 18:56:22 2009
@@ -38,6 +38,7 @@
#include <glib/gstdio.h>
#include <libtracker-common/tracker-type-utils.h>
+#include <libtracker-common/tracker-file-utils.h>
#include "tracker-main.h"
#include "tracker-xmp.h"
@@ -263,18 +264,16 @@
/* Check that we have the minimum data. FIXME We should not need to do this */
if (!g_hash_table_lookup (metadata, "Image:Date")) {
- struct stat st;
+ gchar *date;
+ guint64 mtime;
- if (g_lstat(filename, &st) >= 0) {
- gchar *date;
-
- date = tracker_date_to_string (st.st_mtime);
-
- g_hash_table_insert (metadata,
- g_strdup ("Image:Date"),
- tracker_escape_metadata (date));
- g_free (date);
- }
+ mtime = tracker_file_get_mtime (filename);
+ date = tracker_date_to_string ((time_t) mtime);
+
+ g_hash_table_insert (metadata,
+ g_strdup ("Image:Date"),
+ tracker_escape_metadata (date));
+ g_free (date);
}
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
Modified: trunk/src/tracker-extract/tracker-extract-tiff.c
==============================================================================
--- trunk/src/tracker-extract/tracker-extract-tiff.c (original)
+++ trunk/src/tracker-extract/tracker-extract-tiff.c Wed Feb 18 18:56:22 2009
@@ -28,6 +28,7 @@
#include <tiffio.h>
#include <libtracker-common/tracker-type-utils.h>
+#include <libtracker-common/tracker-file-utils.h>
#include "tracker-main.h"
#include "tracker-xmp.h"
@@ -252,18 +253,16 @@
/* Check that we have the minimum data. FIXME We should not need to do this */
if (!g_hash_table_lookup (metadata, "Image:Date")) {
- struct stat st;
+ gchar *date;
+ guint64 mtime;
- if (g_lstat(filename, &st) >= 0) {
- gchar *date;
-
- date = tracker_date_to_string (st.st_mtime);
-
- g_hash_table_insert (metadata,
- g_strdup ("Image:Date"),
- tracker_escape_metadata (date));
- g_free (date);
- }
+ mtime = tracker_file_get_mtime (filename);
+ date = tracker_date_to_string ((time_t) mtime);
+
+ g_hash_table_insert (metadata,
+ g_strdup ("Image:Date"),
+ tracker_escape_metadata (date));
+ g_free (date);
}
TIFFClose (image);
Modified: trunk/src/tracker-indexer/tracker-indexer.c
==============================================================================
--- trunk/src/tracker-indexer/tracker-indexer.c (original)
+++ trunk/src/tracker-indexer/tracker-indexer.c Wed Feb 18 18:56:22 2009
@@ -2110,8 +2110,8 @@
{
TrackerService *service;
gchar *path;
- struct stat st;
- time_t mtime;
+ guint64 current_mtime;
+ time_t db_mtime;
service = get_service_for_file (info->module_file, info->module);
@@ -2123,10 +2123,10 @@
* definitely want to index it.
*/
if (!tracker_data_query_service_exists (service,
- dirname,
- basename,
- NULL,
- &mtime)) {
+ dirname,
+ basename,
+ NULL,
+ &db_mtime)) {
return TRUE;
}
@@ -2137,13 +2137,17 @@
* immediately in this parent directory.
*/
path = g_file_get_path (info->file);
+ current_mtime = tracker_file_get_mtime (path);
- if (g_lstat (path, &st) == -1) {
+ /* Don't attempt to index the file if we couldn't even get the
+ * current mtime for it.
+ */
+ if (current_mtime == 0) {
g_free (path);
- return TRUE;
+ return FALSE;
}
- if (st.st_mtime <= mtime) {
+ if (current_mtime <= db_mtime) {
g_debug ("'%s' has indifferent mtime and should not be indexed", path);
g_free (path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]