updated on Thu Jan 12 04:00:44 UTC 2012
[aur-mirror.git] / exo-eject / eject.patch
blob316f081b4394f20c01844bd93c4e23edb494b565
1 diff --git a/exo-mount/exo-mount-hal.c b/exo-mount/exo-mount-hal.c
2 index 791a536..4084719 100644
3 --- a/exo-mount/exo-mount-hal.c
4 +++ b/exo-mount/exo-mount-hal.c
5 @@ -145,6 +145,42 @@ exo_mount_hal_propagate_error (GError **error,
9 +static gboolean
10 +string_in_list(gchar * const *haystack, const gchar *needle)
12 + gint n;
14 + if (!haystack)
15 + return FALSE;
17 + for (n=0; haystack[n]; ++n) {
18 + if (!strcmp (haystack[n], needle))
19 + return TRUE;
20 + }
21 + return FALSE;
25 +static gboolean
26 +device_has_interface(const gchar *udi, const gchar *iface,
27 + DBusError *derror)
29 + gboolean result;
30 + gchar **interfaces;
32 + /* determine the info.interfaces property of the device */
33 + interfaces = libhal_device_get_property_strlist (hal_context, udi,
34 + "info.interfaces", derror);
36 + /* check for the interface we need */
37 + result = string_in_list(interfaces, iface);
38 + libhal_free_string_array(interfaces);
40 + return result;
46 /**
47 * exo_mount_hal_device_from_udi:
48 @@ -158,18 +194,15 @@ exo_mount_hal_propagate_error (GError **error,
49 * or %NULL in case of an error.
50 **/
51 ExoMountHalDevice*
52 -exo_mount_hal_device_from_udi (const gchar *udi,
53 +exo_mount_hal_device_from_udi (const gchar *in_udi,
54 GError **error)
56 ExoMountHalDevice *device = NULL;
57 DBusError derror;
58 - gchar **interfaces;
59 - gchar **volume_udis;
60 - gchar *volume_udi = NULL;
61 gint n_volume_udis;
62 - gint n;
63 + gchar *udi;
65 - g_return_val_if_fail (udi != NULL, NULL);
66 + g_return_val_if_fail (in_udi != NULL, NULL);
67 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
69 /* make sure the HAL support is initialized */
70 @@ -179,55 +212,60 @@ exo_mount_hal_device_from_udi (const gchar *udi,
71 /* initialize D-Bus error */
72 dbus_error_init (&derror);
74 -again:
75 - /* determine the info.interfaces property of the device */
76 - interfaces = libhal_device_get_property_strlist (hal_context, udi, "info.interfaces", &derror);
77 - if (G_UNLIKELY (interfaces == NULL))
78 + udi = g_strdup (in_udi);
79 + /* at this point, we own udi */
81 + /* maybe we have a mountable device here */
82 + while(G_UNLIKELY (!device_has_interface (udi,
83 + "org.freedesktop.Hal.Device.Volume", &derror)))
85 - /* reset D-Bus error */
86 - dbus_error_free (&derror);
87 + gchar **volume_udis;
89 - /* release any previous volume UDI */
90 - g_free (volume_udi);
91 - volume_udi = NULL;
92 + /* maybe there was a D-Bus error? gotta check */
93 + if (G_UNLIKELY (dbus_error_is_set (&derror)))
94 + {
95 + exo_mount_hal_propagate_error (error, &derror);
96 + g_free (udi);
97 + return NULL;
98 + }
100 + /* maybe we have a volume whose parent is identified by the udi */
101 + volume_udis = libhal_manager_find_device_string_match (hal_context,
102 + "info.parent", udi, &n_volume_udis, &derror);
104 - /* ok, but maybe we have a volume whose parent is identified by the udi */
105 - volume_udis = libhal_manager_find_device_string_match (hal_context, "info.parent", udi, &n_volume_udis, &derror);
106 if (G_UNLIKELY (volume_udis == NULL))
108 -err0: exo_mount_hal_propagate_error (error, &derror);
109 - goto out;
110 + exo_mount_hal_propagate_error (error, &derror);
111 + g_free (udi);
112 + return NULL;
114 else if (G_UNLIKELY (n_volume_udis < 1))
116 - /* no match, we cannot handle that device */
117 libhal_free_string_array (volume_udis);
118 - goto err1;
119 + dbus_error_free (&derror);
120 + /* definitely not a device that we're able to
121 + * mount, eject or unmount */
122 + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
123 + _("Given device \"%s\" is not a volume or drive"), udi);
124 + g_free (udi);
125 + return NULL;
128 + g_free (udi);
130 /* use the first volume UDI... */
131 - volume_udi = g_strdup (volume_udis[0]);
132 + udi = g_strdup (volume_udis[0]);
133 libhal_free_string_array (volume_udis);
135 /* ..and try again using that UDI */
136 - udi = (const gchar *) volume_udi;
137 - goto again;
140 - /* verify that we have a mountable device here */
141 - for (n = 0; interfaces[n] != NULL; ++n)
142 - if (strcmp (interfaces[n], "org.freedesktop.Hal.Device.Volume") == 0)
143 - break;
144 - if (G_UNLIKELY (interfaces[n] == NULL))
146 - /* definitely not a device that we're able to mount, eject or unmount */
147 -err1: g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Given device \"%s\" is not a volume or drive"), udi);
148 - goto out;
150 + /* at this point, udi contains the UDI of something
151 + * that implements Hal.Device.Volume.
152 + * udi is the only resource that we hold here. */
154 /* setup the device struct */
155 device = g_new0 (ExoMountHalDevice, 1);
156 - device->udi = g_strdup (udi);
157 + device->udi = udi;
159 /* check if we have a volume here */
160 device->volume = libhal_volume_from_udi (hal_context, udi);
161 @@ -269,8 +307,8 @@ err1: g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Given device \"%
162 if (G_UNLIKELY (device->file == NULL || device->name == NULL))
164 exo_mount_hal_device_free (device);
165 - device = NULL;
166 - goto err0;
167 + exo_mount_hal_propagate_error(error, &derror);
168 + return NULL;
171 /* check if we failed */
172 @@ -282,11 +320,7 @@ err1: g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Given device \"%
173 device = NULL;
176 -out:
177 - /* cleanup */
178 - libhal_free_string_array (interfaces);
179 - g_free (volume_udi);
181 + dbus_error_free (&derror);
182 return device;
185 @@ -313,7 +347,7 @@ exo_mount_hal_device_from_file (const gchar *file,
186 gchar **interfaces;
187 gchar **udis;
188 gint n_udis;
189 - gint n, m;
190 + gint n;
192 g_return_val_if_fail (g_path_is_absolute (file), NULL);
193 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
194 @@ -347,12 +381,7 @@ exo_mount_hal_device_from_file (const gchar *file,
195 continue;
197 /* check if we have a mountable device here */
198 - for (m = 0; interfaces[m] != NULL; ++m)
199 - if (strcmp (interfaces[m], "org.freedesktop.Hal.Device.Volume") == 0)
200 - break;
202 - /* check if it's a usable device */
203 - if (interfaces[m] != NULL)
204 + if (string_in_list (interfaces, "org.freedesktop.Hal.Device.Volume"))
206 libhal_free_string_array (interfaces);
207 break;