Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Avoid unnecessary work if mount watching not specified (#585360)
Browse files Browse the repository at this point in the history
If G_FILE_MONITOR_WATCH_MOUNTS isn't specified, don't do all the work
when the mtab changes.
  • Loading branch information
alexlarsson authored and Matthias Clasen committed Jun 23, 2009
1 parent 4ab9132 commit 6cf974a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
29 changes: 25 additions & 4 deletions gio/glocaldirectorymonitor.c
Expand Up @@ -36,7 +36,8 @@
enum
{
PROP_0,
PROP_DIRNAME
PROP_DIRNAME,
PROP_FLAGS
};

static gboolean g_local_directory_monitor_cancel (GFileMonitor *monitor);
Expand Down Expand Up @@ -74,6 +75,9 @@ g_local_directory_monitor_set_property (GObject *object,
case PROP_DIRNAME:
/* Do nothing */
break;
case PROP_FLAGS:
/* Do nothing */
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
Expand All @@ -89,6 +93,7 @@ g_local_directory_monitor_constructor (GType type,
GLocalDirectoryMonitorClass *klass;
GObjectClass *parent_class;
GLocalDirectoryMonitor *local_monitor;
GFileMonitorFlags flags = 0;
const gchar *dirname = NULL;
gint i;

Expand All @@ -106,13 +111,19 @@ g_local_directory_monitor_constructor (GType type,
{
g_warn_if_fail (G_VALUE_HOLDS_STRING (construct_properties[i].value));
dirname = g_value_get_string (construct_properties[i].value);
break;
}
if (strcmp ("flags", g_param_spec_get_name (construct_properties[i].pspec)) == 0)
{
g_warn_if_fail (G_VALUE_HOLDS_FLAGS (construct_properties[i].value));
flags = g_value_get_flags (construct_properties[i].value);
}
}

local_monitor->dirname = g_strdup (dirname);
local_monitor->flags = flags;

if (!klass->mount_notify)
if (!klass->mount_notify &&
(flags & G_FILE_MONITOR_WATCH_MOUNTS))
{
#ifdef G_OS_WIN32
/*claim everything was mounted */
Expand Down Expand Up @@ -159,6 +170,16 @@ g_local_directory_monitor_class_init (GLocalDirectoryMonitorClass* klass)
G_PARAM_CONSTRUCT_ONLY|
G_PARAM_WRITABLE|
G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
g_object_class_install_property (gobject_class,
PROP_FLAGS,
g_param_spec_flags ("flags",
P_("Monitor flags"),
P_("Monitor flags"),
G_TYPE_FILE_MONITOR_FLAGS,
0,
G_PARAM_CONSTRUCT_ONLY|
G_PARAM_WRITABLE|
G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));

klass->mount_notify = FALSE;
}
Expand Down Expand Up @@ -268,7 +289,7 @@ _g_local_directory_monitor_new (const char *dirname,

monitor = NULL;
if (type != G_TYPE_INVALID)
monitor = G_FILE_MONITOR (g_object_new (type, "dirname", dirname, NULL));
monitor = G_FILE_MONITOR (g_object_new (type, "dirname", dirname, "flags", flags, NULL));
else
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
_("Unable to find default local directory monitor type"));
Expand Down
1 change: 1 addition & 0 deletions gio/glocaldirectorymonitor.h
Expand Up @@ -45,6 +45,7 @@ struct _GLocalDirectoryMonitor
GFileMonitor parent_instance;

gchar *dirname;
GFileMonitorFlags flags;
/* For mount emulation */
GUnixMountMonitor *mount_monitor;
gboolean was_mounted;
Expand Down

0 comments on commit 6cf974a

Please sign in to comment.