[tracker/wip/index-mount-points: 3/6] libtracker-miner: Cleaned up tracker_miner_fs_mount_add() function



commit 1f2f9f0a41320b426baf102997722182e1c57034
Author: Martyn Russell <martyn lanedo com>
Date:   Thu Jan 31 17:58:36 2013 +0000

    libtracker-miner: Cleaned up tracker_miner_fs_mount_add() function
    
    - Fixed memory leaks
    - Used const types for const returns
    - Avoided duplicate messaging
    - Added checks for valid UUID returns
    - Avoided freeing const char*

 src/libtracker-miner/tracker-miner-fs.c |   29 +++++++++++++----------------
 1 files changed, 13 insertions(+), 16 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 7ca0f11..62d3a8d 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -3220,9 +3220,6 @@ set_up_mount_point_cb (GObject      *source,
                g_critical ("Could not set mount point in database '%s', %s",
                            device_urn,
                            error->message);
-               g_critical ("Could not set mount point in database '%s', %s",
-                           device_urn,
-                           error->message);
                g_error_free (error);
        }
 
@@ -3237,23 +3234,23 @@ set_up_mount_point_cb (GObject      *source,
  * Tells the filesystem miner to inspect a mount. It ignores the values
  * of the index-removable-devices and index-optical-discs gsettings keys.
  *
- * Since: 0.14
+ * Since: 0.16
  **/
 void
 tracker_miner_fs_mount_add (TrackerMinerFS *fs,
                             GMount         *mount)
 {
        GFile *mount_point;
-       gchar *uri;
+       gchar *mount_uri;
        GString *queries;
        TrackerStorage *storage;
        gchar *iri;
-       gchar *uuid;
+       const gchar *uuid;
        gchar *urn;
        TrackerStorageType type;
 
        mount_point = g_mount_get_root (mount);
-       uri = g_file_get_uri (mount_point);
+       mount_uri = g_file_get_uri (mount_point);
 
        queries = g_string_new (NULL);
 
@@ -3264,14 +3261,12 @@ tracker_miner_fs_mount_add (TrackerMinerFS *fs,
 
        if (iri) {
                /* if mount point exists in the store, nothing else to do */
-               g_message ("Mount point '%s' already exists in store: '%s'", uri, iri);
-
+               g_message ("Mount point '%s' already exists in store: '%s'", mount_uri, iri);
                g_free (iri);
        } else {
                /* If it doesn't exist, we need to create it */
-               g_message ("Mount point '%s' does not exist in store, need to create it",
-                          uri);
                /* Create a nfo:Folder for the mount point */
+               g_message ("Mount point '%s' does not exist in store, need to create it", mount_uri);
                g_string_append_printf (queries,
                                        "INSERT SILENT INTO <" TRACKER_MINER_FS_GRAPH_URN "> {"
                                        " _:file a nfo:FileDataObject, nie:InformationElement, nfo:Folder ; "
@@ -3280,13 +3275,15 @@ tracker_miner_fs_mount_add (TrackerMinerFS *fs,
                                        "        nie:mimeType \"inode/directory\" ; "
                                        "        nfo:fileLastModified \"1981-06-05T02:20:00Z\" . "
                                        "}",
-                                       uri);
+                                       mount_uri);
        }
 
        uuid = tracker_storage_get_uuid_for_file (storage, mount_point);
+       g_return_if_fail (uuid != NULL);
+
+       /* Freed in set_up_mount_point_cb() */
        urn = g_strconcat (TRACKER_DATASOURCE_URN_PREFIX, uuid, NULL);
        type = tracker_storage_get_type_for_uuid (storage, uuid);
-       g_free (uuid);
 
        g_string_append_printf (queries,
                                "DELETE { <%s> a rdfs:Resource }  "
@@ -3303,15 +3300,15 @@ tracker_miner_fs_mount_add (TrackerMinerFS *fs,
                                urn,
                                TRACKER_STORAGE_TYPE_IS_REMOVABLE (type) ? "true" : "false",
                                TRACKER_STORAGE_TYPE_IS_OPTICAL (type) ? "true" : "false",
-                               uri);
-       g_free (uri);
+                               mount_uri);
+       g_free (mount_uri);
 
        tracker_sparql_connection_update_async (tracker_miner_get_connection (TRACKER_MINER (fs)),
                                                queries->str,
                                                G_PRIORITY_HIGH,
                                                NULL,
                                                set_up_mount_point_cb,
-                                               g_strdup (urn));
+                                               urn);
 
        g_string_free (queries, TRUE);
 


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