tracker r3177 - in trunk: . src/libtracker-data



Author: mr
Date: Mon Apr  6 10:40:42 2009
New Revision: 3177
URL: http://svn.gnome.org/viewvc/tracker?rev=3177&view=rev

Log:


Modified:
   trunk/ChangeLog
   trunk/src/libtracker-data/tracker-turtle.c
   trunk/src/libtracker-data/tracker-turtle.h

Modified: trunk/src/libtracker-data/tracker-turtle.c
==============================================================================
--- trunk/src/libtracker-data/tracker-turtle.c	(original)
+++ trunk/src/libtracker-data/tracker-turtle.c	Mon Apr  6 10:40:42 2009
@@ -71,12 +71,12 @@
 	}
 }
 
-
 #ifdef HAVE_RAPTOR
 
-
 static void
-foreach_in_hash (gpointer key, gpointer value, gpointer user_data)
+foreach_in_hash (gpointer key,
+		 gpointer value, 
+		 gpointer user_data)
 {
 	raptor_statement    *statement;
 	TurtleOptimizerInfo *item = user_data;
@@ -104,12 +104,10 @@
 	g_free (statement);
 }
 
-
 static void
 commit_turtle_parse_info_optimizer (TurtleOptimizerInfo *info)
 {
 	if (info->last_subject) {
-
 		g_hash_table_foreach (info->hash, 
 				      foreach_in_hash,
 				      info);
@@ -121,9 +119,9 @@
 	}
 }
 
-
 static void
-consume_triple_optimizer (void* user_data, const raptor_statement* triple) 
+consume_triple_optimizer (void                   *user_data, 
+			  const raptor_statement *triple) 
 {
 	TurtleOptimizerInfo *info = user_data;
 	gchar               *subject;
@@ -142,10 +140,8 @@
 	}
 
 	if (triple->object_type == RAPTOR_IDENTIFIER_TYPE_RESOURCE) {
-
 		/* TODO: these checks for removals of resources and predicates 
 		 * are incorrect atm */
-
 		if (g_str_has_suffix (predicate, ":")) {
 			/* <URI> <> <> */
 			g_hash_table_destroy (info->hash);
@@ -157,18 +153,17 @@
 			g_hash_table_remove (info->hash, predicate);
 		}
 	} else {
-
 		/* TODO: Add conflict resolution here (if any is needed) */
-
 		g_hash_table_replace (info->hash,
 				      g_strdup (predicate),
 				      g_strdup (triple->object));
 	}
-
 }
 
 static void
-foreach_in_metadata (TrackerField *field, gpointer value, gpointer user_data)
+foreach_in_metadata (TrackerField *field, 
+		     gpointer      value, 
+		     gpointer      user_data)
 {
 	raptor_statement          *statement;
 	TrackerTurtleMetadataItem *item = user_data;
@@ -207,9 +202,6 @@
 }
 #endif /* HAVE_RAPTOR */
 
-
-
-
 TurtleFile *
 tracker_turtle_open (const gchar *turtle_file)
 {
@@ -220,15 +212,16 @@
 
 	turtle = g_new0 (TurtleFile, 1);
 
-	turtle->file = g_fopen (turtle_file, "a");
-	/* Similar to a+ */
-	if (!turtle->file) 
-		turtle->file = g_fopen (turtle_file, "w");
+	turtle->file = tracker_file_open (turtle_file, "a+",  TRUE);
+	if (!turtle->file) {
+		return NULL;
+	}
 
 	turtle->serializer = raptor_new_serializer ("turtle");
 	turtle->uri = raptor_new_uri ((unsigned char *) "/");
 	raptor_serialize_start_to_file_handle (turtle->serializer, 
-					       turtle->uri, turtle->file);
+					       turtle->uri, 
+					       turtle->file);
 
 	return turtle;
 #else 
@@ -259,8 +252,8 @@
 }
 
 void 
-tracker_turtle_add_metadatas (TurtleFile          *turtle,
-			      GPtrArray           *metadata_items)
+tracker_turtle_add_metadatas (TurtleFile *turtle,
+			      GPtrArray  *metadata_items)
 {
 #ifdef HAVE_RAPTOR
 	guint count;
@@ -277,7 +270,6 @@
 #endif /* HAVE_RAPTOR */
 }
 
-
 void
 tracker_turtle_add_triple (TurtleFile   *turtle,
 			   const gchar  *uri,
@@ -301,14 +293,20 @@
 	raptor_free_uri (turtle->uri);
 	raptor_serialize_end (turtle->serializer);
 	raptor_free_serializer(turtle->serializer);
-	fclose (turtle->file);
+
+	if (turtle->file) {
+		tracker_file_close (turtle->file, FALSE);
+	}
+
 	g_free (turtle);
 #endif
 }
 
 #ifdef HAVE_RAPTOR
 static void 
-raptor_error (void *user_data, raptor_locator* locator, const char *message)
+raptor_error (void           *user_data, 
+	      raptor_locator *locator, 
+	      const gchar    *message)
 {
 	g_message ("RAPTOR parse error: %s for %s\n", 
 		   message, 
@@ -351,11 +349,9 @@
 	raptor_free_uri (buri);
 
 	raptor_free_parser (parser);
-
 #endif 	
 }
 
-
 void
 tracker_turtle_optimize (const gchar *turtle_file)
 {
@@ -414,6 +410,5 @@
 	g_rename (tmp_file, turtle_file);
 
 	g_free (tmp_file);
-
 #endif /* HAVE_RAPTOR */
 }

Modified: trunk/src/libtracker-data/tracker-turtle.h
==============================================================================
--- trunk/src/libtracker-data/tracker-turtle.h	(original)
+++ trunk/src/libtracker-data/tracker-turtle.h	Mon Apr  6 10:40:42 2009
@@ -52,12 +52,11 @@
 
 G_BEGIN_DECLS
 
-typedef void (* TurtleTripleCallback) (void *user_data, const TrackerRaptorStatement *triple);
+typedef void (* TurtleTripleCallback) (void                         *user_data, 
+				       const TrackerRaptorStatement *triple);
 
 typedef struct TurtleFile TurtleFile;
 
-
-
 typedef struct {
 	gchar                *about_uri;
 	TrackerDataMetadata  *metadata;
@@ -65,33 +64,32 @@
 } TrackerTurtleMetadataItem;
 
 /* Initialization (use in both cases) */
-void        tracker_turtle_init            (void);
-void        tracker_turtle_shutdown        (void);
+void        tracker_turtle_init          (void);
+void        tracker_turtle_shutdown      (void);
 
 /* Transactions style */
-TurtleFile *tracker_turtle_open            (const gchar         *turtle_file);
-void        tracker_turtle_add_triple      (TurtleFile          *turtle,
-					    const gchar         *uri,
-					    TrackerField        *property,
-					    const gchar         *value);
-void        tracker_turtle_add_metadata    (TurtleFile          *turtle,
-					    const gchar         *uri,
-					    TrackerDataMetadata *metadata);
+TurtleFile *tracker_turtle_open          (const gchar          *turtle_file);
+void        tracker_turtle_add_triple    (TurtleFile           *turtle,
+					  const gchar          *uri,
+					  TrackerField         *property,
+					  const gchar          *value);
+void        tracker_turtle_add_metadata  (TurtleFile           *turtle,
+					  const gchar          *uri,
+					  TrackerDataMetadata  *metadata);
 
 /* @metadata_items contains TrackerTurtleMetadataItem instances */
-void        tracker_turtle_add_metadatas   (TurtleFile          *turtle,
-					    GPtrArray           *metadata_items);
-void        tracker_turtle_close           (TurtleFile          *turtle);
+void        tracker_turtle_add_metadatas (TurtleFile           *turtle,
+					  GPtrArray            *metadata_items);
+void        tracker_turtle_close         (TurtleFile           *turtle);
 
 /* Reading functions */
-void        tracker_turtle_process         (const gchar          *turtle_file,
-					    const gchar          *base_uri,
-					    TurtleTripleCallback  callback,
-					    void                 *user_data);
-					    
+void        tracker_turtle_process       (const gchar          *turtle_file,
+					  const gchar          *base_uri,
+					  TurtleTripleCallback  callback,
+					  void                 *user_data);
 
 /* Optimizer, reparser */
-void        tracker_turtle_optimize        (const gchar          *turtle_file);
+void        tracker_turtle_optimize      (const gchar          *turtle_file);
 
 G_END_DECLS
 



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