mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-23 22:16:16 +01:00
kqueue backend: port to new GLocalFileMonitor API
This is the bare minimal effort. This seems not to crash immediately, but it definitely needs some better testing. The backend is not in good shape. It could use some serious work.
This commit is contained in:
parent
19522424b1
commit
641b98ce6b
@ -5,8 +5,6 @@ noinst_LTLIBRARIES += libkqueue.la
|
||||
libkqueue_la_SOURCES = \
|
||||
gkqueuefilemonitor.c \
|
||||
gkqueuefilemonitor.h \
|
||||
gkqueuedirectorymonitor.c \
|
||||
gkqueuedirectorymonitor.h \
|
||||
kqueue-helper.c \
|
||||
kqueue-helper.h \
|
||||
kqueue-thread.c \
|
||||
|
@ -1,205 +0,0 @@
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2011, 2012 Dmitry Matveev <me@dmitrymatveev.co.uk>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gkqueuedirectorymonitor.h"
|
||||
#include "kqueue-helper.h"
|
||||
#include "kqueue-exclusions.h"
|
||||
#include <gio/gpollfilemonitor.h>
|
||||
#include <gio/gfile.h>
|
||||
#include <gio/giomodule.h>
|
||||
|
||||
|
||||
struct _GKqueueDirectoryMonitor
|
||||
{
|
||||
GLocalDirectoryMonitor parent_instance;
|
||||
kqueue_sub *sub;
|
||||
|
||||
GFileMonitor *fallback;
|
||||
GFile *fbfile;
|
||||
|
||||
gboolean pair_moves;
|
||||
};
|
||||
|
||||
static gboolean g_kqueue_directory_monitor_cancel (GFileMonitor *monitor);
|
||||
|
||||
#define g_kqueue_directory_monitor_get_type _g_kqueue_directory_monitor_get_type
|
||||
G_DEFINE_TYPE_WITH_CODE (GKqueueDirectoryMonitor, g_kqueue_directory_monitor, G_TYPE_LOCAL_DIRECTORY_MONITOR,
|
||||
g_io_extension_point_implement (G_LOCAL_DIRECTORY_MONITOR_EXTENSION_POINT_NAME,
|
||||
g_define_type_id,
|
||||
"kqueue",
|
||||
20))
|
||||
|
||||
|
||||
static void
|
||||
_fallback_callback (GFileMonitor *unused,
|
||||
GFile *first,
|
||||
GFile *second,
|
||||
GFileMonitorEvent event,
|
||||
gpointer udata)
|
||||
{
|
||||
GKqueueDirectoryMonitor *kq_mon = G_KQUEUE_DIRECTORY_MONITOR (udata);
|
||||
GFileMonitor *mon = G_FILE_MONITOR (kq_mon);
|
||||
g_assert (kq_mon != NULL);
|
||||
g_assert (mon != NULL);
|
||||
(void) unused;
|
||||
|
||||
if (event == G_FILE_MONITOR_EVENT_CHANGED)
|
||||
{
|
||||
_kh_dir_diff (kq_mon->sub, mon);
|
||||
}
|
||||
else
|
||||
g_file_monitor_emit_event (mon, first, second, event);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
g_kqueue_directory_monitor_finalize (GObject *object)
|
||||
{
|
||||
GKqueueDirectoryMonitor *kqueue_monitor = G_KQUEUE_DIRECTORY_MONITOR (object);
|
||||
|
||||
if (kqueue_monitor->sub)
|
||||
{
|
||||
_kh_cancel_sub (kqueue_monitor->sub);
|
||||
_kh_sub_free (kqueue_monitor->sub);
|
||||
kqueue_monitor->sub = NULL;
|
||||
}
|
||||
|
||||
if (kqueue_monitor->fallback)
|
||||
g_object_unref (kqueue_monitor->fallback);
|
||||
|
||||
if (kqueue_monitor->fbfile)
|
||||
g_object_unref (kqueue_monitor->fbfile);
|
||||
|
||||
if (G_OBJECT_CLASS (g_kqueue_directory_monitor_parent_class)->finalize)
|
||||
(*G_OBJECT_CLASS (g_kqueue_directory_monitor_parent_class)->finalize) (object);
|
||||
}
|
||||
|
||||
static GObject*
|
||||
g_kqueue_directory_monitor_constructor (GType type,
|
||||
guint n_construct_properties,
|
||||
GObjectConstructParam *construct_properties)
|
||||
{
|
||||
GObject *obj;
|
||||
GKqueueDirectoryMonitorClass *klass;
|
||||
GObjectClass *parent_class;
|
||||
GKqueueDirectoryMonitor *kqueue_monitor;
|
||||
kqueue_sub *sub = NULL;
|
||||
gboolean ret_kh_startup;
|
||||
const gchar *path = NULL;
|
||||
|
||||
klass = G_KQUEUE_DIRECTORY_MONITOR_CLASS (g_type_class_peek (G_TYPE_KQUEUE_DIRECTORY_MONITOR));
|
||||
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
|
||||
obj = parent_class->constructor (type,
|
||||
n_construct_properties,
|
||||
construct_properties);
|
||||
|
||||
kqueue_monitor = G_KQUEUE_DIRECTORY_MONITOR (obj);
|
||||
|
||||
ret_kh_startup = _kh_startup ();
|
||||
g_assert (ret_kh_startup);
|
||||
|
||||
kqueue_monitor->pair_moves = (G_LOCAL_DIRECTORY_MONITOR (obj)->flags & G_FILE_MONITOR_SEND_MOVED)
|
||||
? TRUE : FALSE;
|
||||
|
||||
kqueue_monitor->sub = NULL;
|
||||
kqueue_monitor->fallback = NULL;
|
||||
kqueue_monitor->fbfile = NULL;
|
||||
|
||||
path = G_LOCAL_DIRECTORY_MONITOR (obj)->dirname;
|
||||
|
||||
/* For a directory monitor, create a subscription object anyway.
|
||||
* It will be used for directory diff calculation routines. */
|
||||
|
||||
sub = _kh_sub_new (path,
|
||||
kqueue_monitor->pair_moves,
|
||||
kqueue_monitor);
|
||||
|
||||
/* FIXME: what to do about errors here? we can't return NULL or another
|
||||
* kind of error and an assertion is probably too hard (same issue as in
|
||||
* the inotify backend) */
|
||||
g_assert (sub != NULL);
|
||||
kqueue_monitor->sub = sub;
|
||||
|
||||
if (!_ke_is_excluded (path))
|
||||
_kh_add_sub (sub);
|
||||
else
|
||||
{
|
||||
GFile *file = g_file_new_for_path (path);
|
||||
kqueue_monitor->fbfile = file;
|
||||
kqueue_monitor->fallback = _g_poll_file_monitor_new (file);
|
||||
g_signal_connect (kqueue_monitor->fallback,
|
||||
"changed",
|
||||
G_CALLBACK (_fallback_callback),
|
||||
kqueue_monitor);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
g_kqueue_directory_monitor_is_supported (void)
|
||||
{
|
||||
return _kh_startup ();
|
||||
}
|
||||
|
||||
static void
|
||||
g_kqueue_directory_monitor_class_init (GKqueueDirectoryMonitorClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GFileMonitorClass *directory_monitor_class = G_FILE_MONITOR_CLASS (klass);
|
||||
GLocalDirectoryMonitorClass *local_directory_monitor_class = G_LOCAL_DIRECTORY_MONITOR_CLASS (klass);
|
||||
|
||||
gobject_class->finalize = g_kqueue_directory_monitor_finalize;
|
||||
gobject_class->constructor = g_kqueue_directory_monitor_constructor;
|
||||
directory_monitor_class->cancel = g_kqueue_directory_monitor_cancel;
|
||||
|
||||
local_directory_monitor_class->mount_notify = TRUE; /* TODO: ??? */
|
||||
local_directory_monitor_class->is_supported = g_kqueue_directory_monitor_is_supported;
|
||||
}
|
||||
|
||||
static void
|
||||
g_kqueue_directory_monitor_init (GKqueueDirectoryMonitor *monitor)
|
||||
{
|
||||
}
|
||||
|
||||
static gboolean
|
||||
g_kqueue_directory_monitor_cancel (GFileMonitor *monitor)
|
||||
{
|
||||
GKqueueDirectoryMonitor *kqueue_monitor = G_KQUEUE_DIRECTORY_MONITOR (monitor);
|
||||
|
||||
if (kqueue_monitor->sub)
|
||||
{
|
||||
_kh_cancel_sub (kqueue_monitor->sub);
|
||||
_kh_sub_free (kqueue_monitor->sub);
|
||||
kqueue_monitor->sub = NULL;
|
||||
}
|
||||
else if (kqueue_monitor->fallback)
|
||||
g_file_monitor_cancel (kqueue_monitor->fallback);
|
||||
|
||||
|
||||
if (G_FILE_MONITOR_CLASS (g_kqueue_directory_monitor_parent_class)->cancel)
|
||||
(*G_FILE_MONITOR_CLASS (g_kqueue_directory_monitor_parent_class)->cancel) (monitor);
|
||||
|
||||
return TRUE;
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2011, 2012 Dmitry Matveev <me@dmitrymatveev.co.uk>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __G_KQUEUE_DIRECTORY_MONITOR_H__
|
||||
#define __G_KQUEUE_DIRECTORY_MONITOR_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <gio/glocaldirectorymonitor.h>
|
||||
#include <gio/giomodule.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define G_TYPE_KQUEUE_DIRECTORY_MONITOR (_g_kqueue_directory_monitor_get_type ())
|
||||
#define G_KQUEUE_DIRECTORY_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_KQUEUE_DIRECTORY_MONITOR, GKqueueDirectoryMonitor))
|
||||
#define G_KQUEUE_DIRECTORY_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), G_TYPE_KQUEUE_DIRECTORY_MONITOR, GKqueueDirectoryMonitorClass))
|
||||
#define G_IS_KQUEUE_DIRECTORY_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_KQUEUE_DIRECTORY_MONITOR))
|
||||
#define G_IS_KQUEUE_DIRECTORY_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_KQUEUE_DIRECTORY_MONITOR))
|
||||
|
||||
typedef struct _GKqueueDirectoryMonitor GKqueueDirectoryMonitor;
|
||||
typedef struct _GKqueueDirectoryMonitorClass GKqueueDirectoryMonitorClass;
|
||||
|
||||
struct _GKqueueDirectoryMonitorClass {
|
||||
GLocalDirectoryMonitorClass parent_class;
|
||||
};
|
||||
|
||||
GType _g_kqueue_directory_monitor_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_KQUEUE_DIRECTORY_MONITOR_H__ */
|
@ -35,16 +35,13 @@ struct _GKqueueFileMonitor
|
||||
GLocalFileMonitor parent_instance;
|
||||
|
||||
kqueue_sub *sub;
|
||||
|
||||
|
||||
GFileMonitor *fallback;
|
||||
GFile *fbfile;
|
||||
|
||||
gboolean pair_moves;
|
||||
};
|
||||
|
||||
static gboolean g_kqueue_file_monitor_cancel (GFileMonitor* monitor);
|
||||
|
||||
#define g_kqueue_file_monitor_get_type _g_kqueue_file_monitor_get_type
|
||||
G_DEFINE_TYPE_WITH_CODE (GKqueueFileMonitor, g_kqueue_file_monitor, G_TYPE_LOCAL_FILE_MONITOR,
|
||||
g_io_extension_point_implement (G_LOCAL_FILE_MONITOR_EXTENSION_POINT_NAME,
|
||||
g_define_type_id,
|
||||
@ -59,16 +56,18 @@ _fallback_callback (GFileMonitor *unused,
|
||||
GFileMonitorEvent event,
|
||||
gpointer udata)
|
||||
{
|
||||
GKqueueFileMonitor *kq_mon = G_KQUEUE_FILE_MONITOR (udata);
|
||||
GKqueueFileMonitor *kq_mon = G_KQUEUE_FILE_MONITOR (udata);
|
||||
GFileMonitor *mon = G_FILE_MONITOR (kq_mon);
|
||||
g_assert (kq_mon != NULL);
|
||||
g_assert (mon != NULL);
|
||||
(void) unused;
|
||||
|
||||
if (event == G_FILE_MONITOR_EVENT_CHANGED)
|
||||
{
|
||||
_kh_dir_diff (kq_mon->sub, mon);
|
||||
}
|
||||
{
|
||||
GLocalFileMonitor *local_monitor = G_LOCAL_FILE_MONITOR (kq_mon);
|
||||
|
||||
_kh_dir_diff (kq_mon->sub, local_monitor->source);
|
||||
}
|
||||
else
|
||||
g_file_monitor_emit_event (mon, first, second, event);
|
||||
}
|
||||
@ -96,38 +95,28 @@ g_kqueue_file_monitor_finalize (GObject *object)
|
||||
(*G_OBJECT_CLASS (g_kqueue_file_monitor_parent_class)->finalize) (object);
|
||||
}
|
||||
|
||||
static GObject*
|
||||
g_kqueue_file_monitor_constructor (GType type,
|
||||
guint n_construct_properties,
|
||||
GObjectConstructParam *construct_properties)
|
||||
static void
|
||||
g_kqueue_file_monitor_start (GLocalFileMonitor *local_monitor,
|
||||
const gchar *dirname,
|
||||
const gchar *basename,
|
||||
const gchar *filename,
|
||||
GFileMonitorSource *source)
|
||||
{
|
||||
GKqueueFileMonitor *kqueue_monitor = G_KQUEUE_FILE_MONITOR (local_monitor);
|
||||
GObject *obj;
|
||||
GKqueueFileMonitorClass *klass;
|
||||
GObjectClass *parent_class;
|
||||
GKqueueFileMonitor *kqueue_monitor;
|
||||
kqueue_sub *sub = NULL;
|
||||
gboolean ret_kh_startup = FALSE;
|
||||
const gchar *path = NULL;
|
||||
|
||||
klass = G_KQUEUE_FILE_MONITOR_CLASS (g_type_class_peek (G_TYPE_KQUEUE_FILE_MONITOR));
|
||||
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
|
||||
obj = parent_class->constructor (type,
|
||||
n_construct_properties,
|
||||
construct_properties);
|
||||
|
||||
kqueue_monitor = G_KQUEUE_FILE_MONITOR (obj);
|
||||
|
||||
ret_kh_startup = _kh_startup ();
|
||||
g_assert (ret_kh_startup);
|
||||
|
||||
kqueue_monitor->pair_moves = G_LOCAL_FILE_MONITOR (obj)->flags & G_FILE_MONITOR_SEND_MOVED
|
||||
? TRUE : FALSE;
|
||||
|
||||
kqueue_monitor->sub = NULL;
|
||||
kqueue_monitor->fallback = NULL;
|
||||
kqueue_monitor->fbfile = NULL;
|
||||
|
||||
path = G_LOCAL_FILE_MONITOR (obj)->filename;
|
||||
path = filename;
|
||||
if (!path)
|
||||
path = dirname;
|
||||
|
||||
/* For a directory monitor, create a subscription object anyway.
|
||||
* It will be used for directory diff calculation routines.
|
||||
@ -137,9 +126,7 @@ g_kqueue_file_monitor_constructor (GType type,
|
||||
* will be created under that path, GKqueueFileMonitor will have to
|
||||
* handle the directory notifications. */
|
||||
|
||||
sub = _kh_sub_new (path,
|
||||
kqueue_monitor->pair_moves,
|
||||
kqueue_monitor);
|
||||
sub = _kh_sub_new (path, TRUE, source);
|
||||
|
||||
/* FIXME: what to do about errors here? we can't return NULL or another
|
||||
* kind of error and an assertion is probably too hard (same issue as in
|
||||
@ -159,8 +146,6 @@ g_kqueue_file_monitor_constructor (GType type,
|
||||
G_CALLBACK (_fallback_callback),
|
||||
kqueue_monitor);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -177,10 +162,11 @@ g_kqueue_file_monitor_class_init (GKqueueFileMonitorClass *klass)
|
||||
GLocalFileMonitorClass *local_file_monitor_class = G_LOCAL_FILE_MONITOR_CLASS (klass);
|
||||
|
||||
gobject_class->finalize = g_kqueue_file_monitor_finalize;
|
||||
gobject_class->constructor = g_kqueue_file_monitor_constructor;
|
||||
file_monitor_class->cancel = g_kqueue_file_monitor_cancel;
|
||||
|
||||
local_file_monitor_class->is_supported = g_kqueue_file_monitor_is_supported;
|
||||
local_file_monitor_class->start = g_kqueue_file_monitor_start;
|
||||
local_file_monitor_class->mount_notify = TRUE; /* TODO: ??? */
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define G_TYPE_KQUEUE_FILE_MONITOR (_g_kqueue_file_monitor_get_type ())
|
||||
#define G_TYPE_KQUEUE_FILE_MONITOR (g_kqueue_file_monitor_get_type ())
|
||||
#define G_KQUEUE_FILE_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_KQUEUE_FILE_MONITOR, GKqueueFileMonitor))
|
||||
#define G_KQUEUE_FILE_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), G_TYPE_KQUEUE_FILE_MONITOR, GKqueueFileMonitorClass))
|
||||
#define G_IS_KQUEUE_FILE_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_KQUEUE_FILE_MONITOR))
|
||||
@ -44,7 +44,7 @@ struct _GKqueueFileMonitorClass {
|
||||
GLocalFileMonitorClass parent_class;
|
||||
};
|
||||
|
||||
GType _g_kqueue_file_monitor_get_type (void);
|
||||
GType g_kqueue_file_monitor_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <gio/glocalfile.h>
|
||||
#include <gio/glocalfilemonitor.h>
|
||||
#include <gio/gfile.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
@ -38,8 +39,6 @@
|
||||
#include "kqueue-missing.h"
|
||||
#include "kqueue-exclusions.h"
|
||||
|
||||
#include "gkqueuedirectorymonitor.h"
|
||||
|
||||
static gboolean kh_debug_enabled = FALSE;
|
||||
#define KH_W if (kh_debug_enabled) g_warning
|
||||
|
||||
@ -113,7 +112,7 @@ convert_kqueue_events_to_gio (uint32_t flags, gboolean *done)
|
||||
|
||||
typedef struct {
|
||||
kqueue_sub *sub;
|
||||
GFileMonitor *monitor;
|
||||
GFileMonitorSource *source;
|
||||
} handle_ctx;
|
||||
|
||||
/**
|
||||
@ -129,29 +128,15 @@ static void
|
||||
handle_created (void *udata, const char *path, ino_t inode)
|
||||
{
|
||||
handle_ctx *ctx = NULL;
|
||||
GFile *file = NULL;
|
||||
gchar *fpath = NULL;
|
||||
|
||||
(void) inode;
|
||||
ctx = (handle_ctx *) udata;
|
||||
g_assert (udata != NULL);
|
||||
g_assert (ctx->sub != NULL);
|
||||
g_assert (ctx->monitor != NULL);
|
||||
g_assert (ctx->source != NULL);
|
||||
|
||||
fpath = _ku_path_concat (ctx->sub->filename, path);
|
||||
if (fpath == NULL)
|
||||
{
|
||||
KH_W ("Failed to allocate a string for a new event");
|
||||
return;
|
||||
}
|
||||
|
||||
file = g_file_new_for_path (fpath);
|
||||
g_file_monitor_emit_event (ctx->monitor,
|
||||
file,
|
||||
NULL,
|
||||
G_FILE_MONITOR_EVENT_CREATED);
|
||||
g_free (fpath);
|
||||
g_object_unref (file);
|
||||
g_file_monitor_source_handle_event (ctx->source, G_FILE_MONITOR_EVENT_CREATED, path,
|
||||
NULL, NULL, g_get_monotonic_time ());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,29 +152,15 @@ static void
|
||||
handle_deleted (void *udata, const char *path, ino_t inode)
|
||||
{
|
||||
handle_ctx *ctx = NULL;
|
||||
GFile *file = NULL;
|
||||
gchar *fpath = NULL;
|
||||
|
||||
(void) inode;
|
||||
ctx = (handle_ctx *) udata;
|
||||
g_assert (udata != NULL);
|
||||
g_assert (ctx->sub != NULL);
|
||||
g_assert (ctx->monitor != NULL);
|
||||
g_assert (ctx->source != NULL);
|
||||
|
||||
fpath = _ku_path_concat (ctx->sub->filename, path);
|
||||
if (fpath == NULL)
|
||||
{
|
||||
KH_W ("Failed to allocate a string for a new event");
|
||||
return;
|
||||
}
|
||||
|
||||
file = g_file_new_for_path (fpath);
|
||||
g_file_monitor_emit_event (ctx->monitor,
|
||||
file,
|
||||
NULL,
|
||||
G_FILE_MONITOR_EVENT_DELETED);
|
||||
g_free (fpath);
|
||||
g_object_unref (file);
|
||||
g_file_monitor_source_handle_event (ctx->source, G_FILE_MONITOR_EVENT_DELETED, path,
|
||||
NULL, NULL, g_get_monotonic_time ());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -201,7 +172,7 @@ handle_deleted (void *udata, const char *path, ino_t inode)
|
||||
* @to_inode: inode number of the replaced file.
|
||||
*
|
||||
* A callback function for the directory diff calculation routine,
|
||||
* produces G_FILE_MONITOR_EVENT_MOVED event on a move.
|
||||
* produces G_FILE_MONITOR_EVENT_RENAMED event on a move.
|
||||
**/
|
||||
static void
|
||||
handle_moved (void *udata,
|
||||
@ -211,10 +182,6 @@ handle_moved (void *udata,
|
||||
ino_t to_inode)
|
||||
{
|
||||
handle_ctx *ctx = NULL;
|
||||
GFile *file = NULL;
|
||||
GFile *other = NULL;
|
||||
gchar *path = NULL;
|
||||
gchar *npath = NULL;
|
||||
|
||||
(void) from_inode;
|
||||
(void) to_inode;
|
||||
@ -222,47 +189,12 @@ handle_moved (void *udata,
|
||||
ctx = (handle_ctx *) udata;
|
||||
g_assert (udata != NULL);
|
||||
g_assert (ctx->sub != NULL);
|
||||
g_assert (ctx->monitor != NULL);
|
||||
g_assert (ctx->source != NULL);
|
||||
|
||||
|
||||
path = _ku_path_concat (ctx->sub->filename, from_path);
|
||||
npath = _ku_path_concat (ctx->sub->filename, to_path);
|
||||
if (path == NULL || npath == NULL)
|
||||
{
|
||||
KH_W ("Failed to allocate strings for event");
|
||||
return;
|
||||
}
|
||||
|
||||
file = g_file_new_for_path (path);
|
||||
other = g_file_new_for_path (npath);
|
||||
|
||||
if (ctx->sub->pair_moves)
|
||||
{
|
||||
g_file_monitor_emit_event (ctx->monitor,
|
||||
file,
|
||||
other,
|
||||
G_FILE_MONITOR_EVENT_MOVED);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_file_monitor_emit_event (ctx->monitor,
|
||||
file,
|
||||
NULL,
|
||||
G_FILE_MONITOR_EVENT_DELETED);
|
||||
g_file_monitor_emit_event (ctx->monitor,
|
||||
other,
|
||||
NULL,
|
||||
G_FILE_MONITOR_EVENT_CREATED);
|
||||
}
|
||||
|
||||
g_free (path);
|
||||
g_free (npath);
|
||||
|
||||
g_object_unref (file);
|
||||
g_object_unref (other);
|
||||
g_file_monitor_source_handle_event (ctx->source, G_FILE_MONITOR_EVENT_RENAMED,
|
||||
from_path, to_path, NULL, g_get_monotonic_time ());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* handle_overwritten:
|
||||
* @data: a pointer to user data (#handle_context).
|
||||
@ -277,34 +209,18 @@ static void
|
||||
handle_overwritten (void *udata, const char *path, ino_t inode)
|
||||
{
|
||||
handle_ctx *ctx = NULL;
|
||||
GFile *file = NULL;
|
||||
gchar *fpath = NULL;
|
||||
|
||||
(void) inode;
|
||||
ctx = (handle_ctx *) udata;
|
||||
g_assert (udata != NULL);
|
||||
g_assert (ctx->sub != NULL);
|
||||
g_assert (ctx->monitor != NULL);
|
||||
g_assert (ctx->source != NULL);
|
||||
|
||||
fpath = _ku_path_concat (ctx->sub->filename, path);
|
||||
if (fpath == NULL)
|
||||
{
|
||||
KH_W ("Failed to allocate a string for a new event");
|
||||
return;
|
||||
}
|
||||
g_file_monitor_source_handle_event (ctx->source, G_FILE_MONITOR_EVENT_DELETED,
|
||||
path, NULL, NULL, g_get_monotonic_time ());
|
||||
|
||||
file = g_file_new_for_path (fpath);
|
||||
g_file_monitor_emit_event (ctx->monitor,
|
||||
file,
|
||||
NULL,
|
||||
G_FILE_MONITOR_EVENT_DELETED);
|
||||
g_file_monitor_emit_event (ctx->monitor,
|
||||
file,
|
||||
NULL,
|
||||
G_FILE_MONITOR_EVENT_CREATED);
|
||||
|
||||
g_free (fpath);
|
||||
g_object_unref (file);
|
||||
g_file_monitor_source_handle_event (ctx->source, G_FILE_MONITOR_EVENT_CREATED,
|
||||
path, NULL, NULL, g_get_monotonic_time ());
|
||||
}
|
||||
|
||||
static const traverse_cbs cbs = {
|
||||
@ -320,17 +236,17 @@ static const traverse_cbs cbs = {
|
||||
|
||||
|
||||
void
|
||||
_kh_dir_diff (kqueue_sub *sub, GFileMonitor *monitor)
|
||||
_kh_dir_diff (kqueue_sub *sub, GFileMonitorSource *source)
|
||||
{
|
||||
dep_list *was;
|
||||
handle_ctx ctx;
|
||||
|
||||
g_assert (sub != NULL);
|
||||
g_assert (monitor != NULL);
|
||||
g_assert (source != NULL);
|
||||
|
||||
memset (&ctx, 0, sizeof (handle_ctx));
|
||||
ctx.sub = sub;
|
||||
ctx.monitor = monitor;
|
||||
ctx.source = source;
|
||||
|
||||
was = sub->deps;
|
||||
sub->deps = dl_listing (sub->filename);
|
||||
@ -363,7 +279,7 @@ process_kqueue_notifications (GIOChannel *gioc,
|
||||
{
|
||||
struct kqueue_notification n;
|
||||
kqueue_sub *sub = NULL;
|
||||
GFileMonitor *monitor = NULL;
|
||||
GFileMonitorSource *source = NULL;
|
||||
GFileMonitorEvent mask = 0;
|
||||
|
||||
g_assert (kqueue_socket_pair[0] != -1);
|
||||
@ -384,8 +300,8 @@ process_kqueue_notifications (GIOChannel *gioc,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
monitor = G_FILE_MONITOR (sub->user_data);
|
||||
g_assert (monitor != NULL);
|
||||
source = sub->user_data;
|
||||
g_assert (source != NULL);
|
||||
|
||||
if (n.flags & (NOTE_DELETE | NOTE_REVOKE))
|
||||
{
|
||||
@ -408,7 +324,7 @@ process_kqueue_notifications (GIOChannel *gioc,
|
||||
|
||||
if (sub->is_dir && n.flags & (NOTE_WRITE | NOTE_EXTEND))
|
||||
{
|
||||
_kh_dir_diff (sub, monitor);
|
||||
_kh_dir_diff (sub, source);
|
||||
n.flags &= ~(NOTE_WRITE | NOTE_EXTEND);
|
||||
}
|
||||
|
||||
@ -417,11 +333,7 @@ process_kqueue_notifications (GIOChannel *gioc,
|
||||
gboolean done = FALSE;
|
||||
mask = convert_kqueue_events_to_gio (n.flags, &done);
|
||||
if (done == TRUE)
|
||||
{
|
||||
GFile *file = g_file_new_for_path (sub->filename);
|
||||
g_file_monitor_emit_event (monitor, file, NULL, mask);
|
||||
g_object_unref (file);
|
||||
}
|
||||
g_file_monitor_source_handle_event (source, mask, NULL, NULL, NULL, g_get_monotonic_time ());
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
@ -24,6 +24,7 @@
|
||||
#define __KQUEUE_HELPER_H
|
||||
|
||||
#include "kqueue-sub.h"
|
||||
#include <gio/glocalfilemonitor.h>
|
||||
#include <gio/gfilemonitor.h>
|
||||
|
||||
gboolean _kh_startup (void);
|
||||
@ -32,6 +33,6 @@ gboolean _kh_cancel_sub (kqueue_sub *sub);
|
||||
|
||||
gboolean _kh_start_watching (kqueue_sub *sub);
|
||||
|
||||
void _kh_dir_diff (kqueue_sub *sub, GFileMonitor *monitor);
|
||||
void _kh_dir_diff (kqueue_sub *sub, GFileMonitorSource *source);
|
||||
|
||||
#endif /* __KQUEUE_HELPER_H */
|
||||
|
@ -208,35 +208,3 @@ _ku_file_information (int fd, int *is_dir, ino_t *inode)
|
||||
if (inode != NULL)
|
||||
*inode = st.st_ino;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a file path using its name and a path to its directory.
|
||||
*
|
||||
* @param[in] dir A path to a file directory. May end with a '/'.
|
||||
* @param[in] file File name.
|
||||
* @return A concatenated path. Should be freed with free().
|
||||
**/
|
||||
gchar*
|
||||
_ku_path_concat (const gchar *dir, const gchar *file)
|
||||
{
|
||||
int dir_len = strlen (dir);
|
||||
int file_len = strlen (file);
|
||||
|
||||
char *path = g_malloc (dir_len + file_len + 2);
|
||||
if (path == NULL)
|
||||
{
|
||||
KU_W ("Failed to allocate memory path for concatenation");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy (path, dir);
|
||||
|
||||
if (dir[dir_len - 1] != '/') {
|
||||
++dir_len;
|
||||
path[dir_len - 1] = '/';
|
||||
}
|
||||
|
||||
strcpy (path + dir_len, file);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
@ -50,8 +50,4 @@ gboolean _ku_write (int fd, gconstpointer data, gsize size);
|
||||
|
||||
void _ku_file_information (int fd, int *is_dir, ino_t *inode);
|
||||
|
||||
gchar* _ku_path_concat (const gchar *dir, const gchar *file);
|
||||
|
||||
|
||||
|
||||
#endif /* __KQUEUE_UTILS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user