[tracker/libtracker-common-cleanup: 5/11] libtracker-common: Removed all tracker_file_*lock*() APIs



commit 5eb87c81aa02b889eb495a1ff672310886458184
Author: Martyn Russell <martyn lanedo com>
Date:   Fri Oct 10 11:27:29 2014 +0100

    libtracker-common: Removed all tracker_file_*lock*() APIs
    
    Completely unused

 src/libtracker-common/tracker-file-utils.c        |  221 ---------------------
 src/libtracker-common/tracker-file-utils.h        |    2 -
 src/libtracker-miner/tracker-miner-fs.c           |   20 --
 tests/libtracker-common/tracker-file-utils-test.c |   43 ----
 4 files changed, 0 insertions(+), 286 deletions(-)
---
diff --git a/src/libtracker-common/tracker-file-utils.c b/src/libtracker-common/tracker-file-utils.c
index 277d44a..c4ad77e 100644
--- a/src/libtracker-common/tracker-file-utils.c
+++ b/src/libtracker-common/tracker-file-utils.c
@@ -44,53 +44,6 @@
 
 #define TEXT_SNIFF_SIZE 4096
 
-static GHashTable *file_locks = NULL;
-
-#ifndef LOCK_EX
-
-/* Required on Solaris */
-#define LOCK_EX 1
-#define LOCK_SH 2
-#define LOCK_UN 3
-#define LOCK_NB 4
-
-static int flock(int fd, int op)
-{
-    int rc = 0;
-
-#if defined(F_SETLK) && defined(F_SETLKW)
-    struct flock fl = {0};
-
-    switch (op & (LOCK_EX|LOCK_SH|LOCK_UN)) {
-    case LOCK_EX:
-        fl.l_type = F_WRLCK;
-        break;
-
-    case LOCK_SH:
-        fl.l_type = F_RDLCK;
-        break;
-
-    case LOCK_UN:
-        fl.l_type = F_UNLCK;
-        break;
-
-    default:
-        errno = EINVAL;
-        return -1;
-    }
-
-    fl.l_whence = SEEK_SET;
-    rc = fcntl (fd, op & LOCK_NB ? F_SETLK : F_SETLKW, &fl);
-
-    if (rc && (errno == EAGAIN))
-        errno = EWOULDBLOCK;
-#endif /* defined(F_SETLK) && defined(F_SETLKW)  */
-
-    return rc;
-}
-
-#endif /* LOCK_EX */
-
 int
 tracker_file_open_fd (const gchar *path)
 {
@@ -698,180 +651,6 @@ tracker_path_has_write_access_or_was_created (const gchar *path)
 }
 
 gboolean
-tracker_file_lock (GFile *file)
-{
-       gint fd, retval;
-       gchar *path;
-
-       g_return_val_if_fail (G_IS_FILE (file), FALSE);
-
-       if (G_UNLIKELY (!file_locks)) {
-               file_locks = g_hash_table_new_full ((GHashFunc) g_file_hash,
-                                                   (GEqualFunc) g_file_equal,
-                                                   (GDestroyNotify) g_object_unref,
-                                                   NULL);
-       }
-
-       /* Don't try to lock twice */
-       if (g_hash_table_lookup (file_locks, file) != NULL) {
-               return TRUE;
-       }
-
-       if (!g_file_is_native (file)) {
-               return FALSE;
-       }
-
-       path = g_file_get_path (file);
-
-       if (!path) {
-               return FALSE;
-       }
-
-       fd = open (path, O_RDONLY);
-
-       if (fd < 0) {
-//LCOV_EXCL_START
-               gchar *uri;
-
-               uri = g_file_get_uri (file);
-               g_warning ("Could not open '%s'", uri);
-               g_free (uri);
-               g_free (path);
-
-               return FALSE;
-//LCOV_EXCL_STOP
-       }
-
-       retval = flock (fd, LOCK_EX);
-
-       if (retval == 0) {
-               g_hash_table_insert (file_locks,
-                                    g_object_ref (file),
-                                    GINT_TO_POINTER (fd));
-       } else {
-//LCOV_EXCL_START
-               gchar *uri;
-
-               uri = g_file_get_uri (file);
-               g_warning ("Could not lock file '%s'", uri);
-               g_free (uri);
-               close (fd);
-//LCOV_EXCL_STOP
-       }
-
-       g_free (path);
-
-       return (retval == 0);
-}
-
-gboolean
-tracker_file_unlock (GFile *file)
-{
-       gint retval, fd;
-
-       g_return_val_if_fail (G_IS_FILE (file), TRUE);
-
-       if (!file_locks) {
-               return TRUE;
-       }
-
-       fd = GPOINTER_TO_INT (g_hash_table_lookup (file_locks, file));
-
-       if (fd == 0) {
-               /* File wasn't actually locked */
-               return TRUE;
-       }
-
-       retval = flock (fd, LOCK_UN);
-
-       if (retval < 0) {
-//LCOV_EXCL_START
-               gchar *uri;
-
-               uri = g_file_get_uri (file);
-               g_warning ("Could not unlock file '%s'", uri);
-               g_free (uri);
-
-               return FALSE;
-//LCOV_EXCL_STOP
-       }
-
-       g_hash_table_remove (file_locks, file);
-       close (fd);
-
-       return TRUE;
-}
-
-gboolean
-tracker_file_is_locked (GFile *file)
-{
-       GFileInfo *file_info;
-       gboolean retval = FALSE;
-       gchar *path;
-       gint fd;
-
-       g_return_val_if_fail (G_IS_FILE (file), FALSE);
-
-       if (!g_file_is_native (file)) {
-               return FALSE;
-       }
-
-       /* Handle regular files; skip pipes and alike */
-       file_info = g_file_query_info (file,
-                                      G_FILE_ATTRIBUTE_STANDARD_TYPE,
-                                      G_FILE_QUERY_INFO_NONE,
-                                      NULL,
-                                      NULL);
-
-       if (!file_info) {
-               return FALSE;
-       }
-
-       if (g_file_info_get_file_type (file_info) != G_FILE_TYPE_REGULAR) {
-               g_object_unref (file_info);
-               return FALSE;
-       }
-
-       g_object_unref (file_info);
-
-       path = g_file_get_path (file);
-
-       if (!path) {
-               return FALSE;
-       }
-
-       fd = open (path, O_RDONLY);
-
-       if (fd < 0) {
-               gchar *uri;
-
-               uri = g_file_get_uri (file);
-               g_warning ("Could not open '%s'", uri);
-               g_free (uri);
-               g_free (path);
-
-               return FALSE;
-       }
-
-       /* Check for locks */
-       retval = flock (fd, LOCK_SH | LOCK_NB);
-
-       if (retval < 0) {
-               if (errno == EWOULDBLOCK) {
-                       retval = TRUE;
-               }
-       } else {
-               /* Oops, call was successful, unlock again the file */
-               flock (fd, LOCK_UN);
-       }
-
-       close (fd);
-       g_free (path);
-
-       return retval;
-}
-
-gboolean
 tracker_file_is_hidden (GFile *file)
 {
        GFileInfo *file_info;
diff --git a/src/libtracker-common/tracker-file-utils.h b/src/libtracker-common/tracker-file-utils.h
index 9bcc88e..2b6beab 100644
--- a/src/libtracker-common/tracker-file-utils.h
+++ b/src/libtracker-common/tracker-file-utils.h
@@ -40,8 +40,6 @@ 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);
 gboolean tracker_file_is_locked                             (GFile       *file);
 gboolean tracker_file_is_hidden                             (GFile       *file);
 gint     tracker_file_cmp                                   (GFile       *file_a,
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 4a8167d..847a556 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -2422,26 +2422,6 @@ item_queue_handlers_cb (gpointer user_data)
                return FALSE;
        }
 
-       if (file && queue != QUEUE_DELETED &&
-           tracker_file_is_locked (file)) {
-               gchar *uri;
-
-               /* File is locked, ignore any updates on it */
-
-               uri = g_file_get_uri (file);
-               g_debug ("File '%s' is currently locked, ignoring updates on it",
-                        uri);
-               g_free (uri);
-
-               g_object_unref (file);
-
-               if (source_file) {
-                       g_object_unref (source_file);
-               }
-
-               return TRUE;
-       }
-
        if (queue == QUEUE_NONE) {
                g_timer_stop (fs->priv->extraction_timer);
                fs->priv->extraction_timer_stopped = TRUE;
diff --git a/tests/libtracker-common/tracker-file-utils-test.c 
b/tests/libtracker-common/tracker-file-utils-test.c
index 48f2ade..d50cbb2 100644
--- a/tests/libtracker-common/tracker-file-utils-test.c
+++ b/tests/libtracker-common/tracker-file-utils-test.c
@@ -394,47 +394,6 @@ test_file_exists_and_writable ()
 }
 
 static void
-test_file_utils_lock ()
-{
-        GFile *f, *no_f, *no_native_f;
-
-        f = g_file_new_for_path (TEST_FILENAME);
-        no_f = g_file_new_for_path ("./file-does-NOT-exist");
-        no_native_f = g_file_new_for_uri ("http://cgit.gnome.org/projects.tracker";);
-
-        /* Nothing locked */
-        g_assert (tracker_file_unlock (f));
-
-        /* Locking a regular file */
-        g_assert (!tracker_file_is_locked (f));
-
-        g_assert (tracker_file_lock (f));
-        g_assert (tracker_file_is_locked (f));
-
-        /* Try to lock twice */
-        g_assert (tracker_file_lock (f));
-        g_assert (tracker_file_is_locked (f));
-
-        g_assert (tracker_file_unlock (f));
-        g_assert (!tracker_file_is_locked (f));
-
-        /* Unlock not-locked file */
-        g_assert (tracker_file_unlock (no_f));
-
-        /* Lock a non-existent file */
-        /* This causes a warning aborting the test */
-        //g_assert (!tracker_file_lock (no_f));
-
-        /* Lock a non-native file */
-        g_assert (!tracker_file_lock (no_native_f));
-        g_assert (!tracker_file_is_locked (no_native_f));
-
-        g_object_unref (f);
-        g_object_unref (no_f);
-        g_object_unref (no_native_f);
-}
-
-static void
 test_file_utils_is_hidden ()
 {
         GFile *f;
@@ -501,8 +460,6 @@ main (int argc, char **argv)
                          test_file_system_has_enough_space);
         g_test_add_func ("/libtracker-common/file-utils/has_write_access_or_was_created",
                          test_file_exists_and_writable);
-        g_test_add_func ("/libtracker-common/file-utils/lock",
-                         test_file_utils_lock);
         g_test_add_func ("/libtracker-common/file-utils/is_hidden",
                          test_file_utils_is_hidden);
         g_test_add_func ("/libtracker-common/file-utils/cmp",


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