summaryrefslogtreecommitdiff
path: root/src/libtracker-common/tracker-file-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libtracker-common/tracker-file-utils.c')
-rw-r--r--src/libtracker-common/tracker-file-utils.c221
1 files changed, 0 insertions, 221 deletions
diff --git a/src/libtracker-common/tracker-file-utils.c b/src/libtracker-common/tracker-file-utils.c
index 277d44ae9..c4ad77e63 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;