mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-28 01:57:14 +02:00
GFileMonitor: add APPEARED event
...and try to send it for some common cases in inotify. We're now abusing the WATCH_MOVES flag as a general "opt-in to new API". That's bad.
This commit is contained in:
@@ -67,6 +67,10 @@ gio_watch_callback (GFileMonitor *monitor,
|
|||||||
g_assert (!other);
|
g_assert (!other);
|
||||||
g_print ("%s: deleted", child_str);
|
g_print ("%s: deleted", child_str);
|
||||||
break;
|
break;
|
||||||
|
case G_FILE_MONITOR_EVENT_APPEARED:
|
||||||
|
g_assert (!other);
|
||||||
|
g_print ("%s: appeared", child_str);
|
||||||
|
break;
|
||||||
case G_FILE_MONITOR_EVENT_CREATED:
|
case G_FILE_MONITOR_EVENT_CREATED:
|
||||||
g_assert (!other);
|
g_assert (!other);
|
||||||
g_print ("%s: created", child_str);
|
g_print ("%s: created", child_str);
|
||||||
|
@@ -422,6 +422,7 @@ typedef enum {
|
|||||||
G_FILE_MONITOR_EVENT_PRE_UNMOUNT,
|
G_FILE_MONITOR_EVENT_PRE_UNMOUNT,
|
||||||
G_FILE_MONITOR_EVENT_UNMOUNTED,
|
G_FILE_MONITOR_EVENT_UNMOUNTED,
|
||||||
G_FILE_MONITOR_EVENT_MOVED,
|
G_FILE_MONITOR_EVENT_MOVED,
|
||||||
|
G_FILE_MONITOR_EVENT_APPEARED,
|
||||||
G_FILE_MONITOR_EVENT_RENAMED,
|
G_FILE_MONITOR_EVENT_RENAMED,
|
||||||
G_FILE_MONITOR_EVENT_MOVED_IN,
|
G_FILE_MONITOR_EVENT_MOVED_IN,
|
||||||
G_FILE_MONITOR_EVENT_MOVED_OUT
|
G_FILE_MONITOR_EVENT_MOVED_OUT
|
||||||
|
@@ -387,6 +387,14 @@ g_file_monitor_source_handle_event (GFileMonitorSource *fms,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case G_FILE_MONITOR_EVENT_APPEARED:
|
||||||
|
g_assert (!other && !rename_to);
|
||||||
|
if (fms->flags & G_FILE_MONITOR_WATCH_MOVES)
|
||||||
|
g_file_monitor_source_send_event (fms, event_type, child, NULL);
|
||||||
|
else
|
||||||
|
g_file_monitor_source_send_synthetic_created (fms, child);
|
||||||
|
break;
|
||||||
|
|
||||||
case G_FILE_MONITOR_EVENT_DELETED:
|
case G_FILE_MONITOR_EVENT_DELETED:
|
||||||
case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
|
case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
|
||||||
case G_FILE_MONITOR_EVENT_PRE_UNMOUNT:
|
case G_FILE_MONITOR_EVENT_PRE_UNMOUNT:
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
/* Just include the local header to stop all the pain */
|
/* Just include the local header to stop all the pain */
|
||||||
#include <sys/inotify.h>
|
#include <sys/inotify.h>
|
||||||
#include <gio/glocalfilemonitor.h>
|
#include <gio/glocalfilemonitor.h>
|
||||||
@@ -193,8 +194,42 @@ ih_event_callback (ik_event_t *event,
|
|||||||
g_object_unref (other);
|
g_object_unref (other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (event->mask & IN_CREATE)
|
||||||
|
{
|
||||||
|
GFileMonitorEvent event_type;
|
||||||
|
const gchar *parent_dir;
|
||||||
|
gchar *fullname;
|
||||||
|
struct stat buf;
|
||||||
|
gint s;
|
||||||
|
|
||||||
|
/* The kernel reports IN_CREATE for two types of events:
|
||||||
|
*
|
||||||
|
* - creat(), in which case IN_CLOSE_WRITE will come soon; or
|
||||||
|
* - link(), mkdir(), mknod(), etc., in which case it won't
|
||||||
|
*
|
||||||
|
* We can attempt to detect the second case and turn it into an
|
||||||
|
* APPEARED event so that the user isn't expecting CHANGES_DONE.
|
||||||
|
*
|
||||||
|
* The detection for link() is not 100% reliable since the link
|
||||||
|
* count could be 1 if the original link was deleted or if
|
||||||
|
* O_TMPFILE was being used, but in that case the virtual
|
||||||
|
* CHANGES_DONE will be emitted to close the loop.
|
||||||
|
*/
|
||||||
|
|
||||||
|
parent_dir = _ip_get_path_for_wd (event->wd);
|
||||||
|
fullname = _ih_fullpath_from_event (event, parent_dir, NULL);
|
||||||
|
s = stat (fullname, &buf);
|
||||||
|
g_free (fullname);
|
||||||
|
|
||||||
|
/* does it look like the result of creat()? */
|
||||||
|
if (s == 0 && S_ISREG (buf.st_mode) && buf.st_nlink == 1)
|
||||||
|
event_type = G_FILE_MONITOR_EVENT_CREATED;
|
||||||
|
else
|
||||||
|
event_type = G_FILE_MONITOR_EVENT_APPEARED;
|
||||||
|
|
||||||
|
g_file_monitor_source_handle_event (sub->user_data, event_type, event->name, NULL, NULL, event->timestamp);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
/* unpaired event -- no 'other' field */
|
|
||||||
g_file_monitor_source_handle_event (sub->user_data, ih_mask_to_EventFlags (event->mask),
|
g_file_monitor_source_handle_event (sub->user_data, ih_mask_to_EventFlags (event->mask),
|
||||||
event->name, NULL, NULL, event->timestamp);
|
event->name, NULL, NULL, event->timestamp);
|
||||||
}
|
}
|
||||||
@@ -202,7 +237,7 @@ ih_event_callback (ik_event_t *event,
|
|||||||
static void
|
static void
|
||||||
ih_not_missing_callback (inotify_sub *sub)
|
ih_not_missing_callback (inotify_sub *sub)
|
||||||
{
|
{
|
||||||
g_file_monitor_source_handle_event (sub->user_data, G_FILE_MONITOR_EVENT_CREATED,
|
g_file_monitor_source_handle_event (sub->user_data, G_FILE_MONITOR_EVENT_APPEARED,
|
||||||
sub->filename, NULL, NULL, g_get_monotonic_time ());
|
sub->filename, NULL, NULL, g_get_monotonic_time ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user