updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / exo-mountopt / exo-0.3.2-alt-eject.patch
blob993615b0e291a0533a87e92f4bb87c95eb9a768c
1 fix #12702: pushing eject on the disc drive should now work.
3 exo/exo-mount/exo-mount-hal.c | 146 ++++++++++++++++++++++++++---------------
5 diff --git a/exo/exo-mount/exo-mount-hal.c b/exo/exo-mount/exo-mount-hal.c
6 index 0b5776a..2f58d1c 100644
7 --- a/exo/exo-mount/exo-mount-hal.c
8 +++ b/exo/exo-mount/exo-mount-hal.c
9 @@ -145,6 +145,42 @@ exo_mount_hal_propagate_error (GError **error,
13 +static gboolean
14 +string_in_list(gchar * const *haystack, const gchar *needle)
16 + gint n;
18 + if (!haystack)
19 + return FALSE;
21 + for (n=0; haystack[n]; ++n) {
22 + if (!strcmp (haystack[n], needle))
23 + return TRUE;
24 + }
25 + return FALSE;
29 +static gboolean
30 +device_has_interface(const gchar *udi, const gchar *iface,
31 + DBusError *derror)
33 + gboolean result;
34 + gchar **interfaces;
36 + /* determine the info.interfaces property of the device */
37 + interfaces = libhal_device_get_property_strlist (hal_context, udi,
38 + "info.interfaces", derror);
40 + /* check for the interface we need */
41 + result = string_in_list(interfaces, iface);
42 + libhal_free_string_array(interfaces);
44 + return result;
50 /**
51 * exo_mount_hal_device_from_udi:
52 @@ -158,18 +194,15 @@ exo_mount_hal_propagate_error (GError **error,
53 * or %NULL in case of an error.
54 **/
55 ExoMountHalDevice*
56 -exo_mount_hal_device_from_udi (const gchar *udi,
57 +exo_mount_hal_device_from_udi (const gchar *in_udi,
58 GError **error)
60 ExoMountHalDevice *device = NULL;
61 DBusError derror;
62 - gchar **interfaces;
63 - gchar **volume_udis;
64 - gchar *volume_udi = NULL;
65 gint n_volume_udis;
66 - gint n;
67 + gchar *udi;
69 - g_return_val_if_fail (udi != NULL, NULL);
70 + g_return_val_if_fail (in_udi != NULL, NULL);
71 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
73 /* make sure the HAL support is initialized */
74 @@ -179,67 +212,74 @@ exo_mount_hal_device_from_udi (const gchar *udi,
75 /* initialize D-Bus error */
76 dbus_error_init (&derror);
78 -again:
79 - /* determine the info.interfaces property of the device */
80 - interfaces = libhal_device_get_property_strlist (hal_context, udi, "info.interfaces", &derror);
81 - if (G_UNLIKELY (interfaces == NULL))
82 + udi = g_strdup (in_udi);
83 + /* at this point, we own udi */
85 + /* maybe we have a mountable device here */
86 + while(G_UNLIKELY (!device_has_interface (udi,
87 + "org.freedesktop.Hal.Device.Volume", &derror)))
89 - /* reset D-Bus error */
90 - dbus_error_free (&derror);
91 + gchar **volume_udis;
93 + /* maybe there was a D-Bus error? gotta check */
94 + if (G_UNLIKELY (dbus_error_is_set (&derror)))
95 + {
96 + exo_mount_hal_propagate_error (error, &derror);
97 + g_free (udi);
98 + return NULL;
99 + }
101 - /* release any previous volume UDI */
102 - g_free (volume_udi);
103 - volume_udi = NULL;
104 + /* maybe we have a volume whose parent is identified by the udi */
105 + volume_udis = libhal_manager_find_device_string_match (hal_context,
106 + "info.parent", udi, &n_volume_udis, &derror);
108 - /* ok, but maybe we have a volume whose parent is identified by the udi */
109 - volume_udis = libhal_manager_find_device_string_match (hal_context, "info.parent", udi, &n_volume_udis, &derror);
110 if (G_UNLIKELY (volume_udis == NULL))
112 -err0: exo_mount_hal_propagate_error (error, &derror);
113 - goto out;
114 + exo_mount_hal_propagate_error (error, &derror);
115 + g_free (udi);
116 + return NULL;
118 else if (G_UNLIKELY (n_volume_udis < 1))
120 - /* no match, we cannot handle that device */
121 libhal_free_string_array (volume_udis);
122 - goto err1;
123 + dbus_error_free (&derror);
124 + /* definitely not a device that we're able to
125 + * mount, eject or unmount */
126 + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
127 + _("Given device \"%s\" is not a volume or drive"), udi);
128 + g_free (udi);
129 + return NULL;
132 + g_free (udi);
134 /* use the first volume UDI... */
135 - volume_udi = g_strdup (volume_udis[0]);
136 + udi = g_strdup (volume_udis[0]);
137 libhal_free_string_array (volume_udis);
139 /* ..and try again using that UDI */
140 - udi = (const gchar *) volume_udi;
141 - goto again;
144 - /* verify that we have a mountable device here */
145 - for (n = 0; interfaces[n] != NULL; ++n)
146 - if (strcmp (interfaces[n], "org.freedesktop.Hal.Device.Volume") == 0)
147 - break;
148 - if (G_UNLIKELY (interfaces[n] == NULL))
150 - /* definitely not a device that we're able to mount, eject or unmount */
151 -err1: g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Given device \"%s\" is not a volume or drive"), udi);
152 - goto out;
154 + /* at this point, udi contains the UDI of something
155 + * that implements Hal.Device.Volume.
156 + * udi is the only resource that we hold here. */
158 /* setup the device struct */
159 device = g_new0 (ExoMountHalDevice, 1);
160 - device->udi = g_strdup (udi);
161 + device->udi = udi;
163 /* check if we have a volume here */
164 device->volume = libhal_volume_from_udi (hal_context, udi);
165 if (G_LIKELY (device->volume != NULL))
167 /* determine the storage drive for the volume */
168 - device->drive = libhal_drive_from_udi (hal_context, libhal_volume_get_storage_device_udi (device->volume));
169 + device->drive = libhal_drive_from_udi (hal_context,
170 + libhal_volume_get_storage_device_udi (device->volume));
171 if (G_LIKELY (device->drive != NULL))
173 /* setup the device internals */
174 device->file = g_strdup (libhal_volume_get_device_file (device->volume));
175 - device->name = exo_hal_volume_compute_display_name (hal_context, device->volume, device->drive);
176 + device->name = exo_hal_volume_compute_display_name (hal_context,
177 + device->volume, device->drive);
179 /* setup the file system internals */
180 device->fstype = libhal_volume_get_fstype (device->volume);
181 @@ -254,7 +294,8 @@ err1: g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Given device \"%
183 /* setup the device internals */
184 device->file = g_strdup (libhal_drive_get_device_file (device->drive));
185 - device->name = exo_hal_drive_compute_display_name (hal_context, device->drive);
186 + device->name = exo_hal_drive_compute_display_name (hal_context,
187 + device->drive);
189 /* setup the file system internals */
190 device->fstype = "";
191 @@ -263,14 +304,15 @@ err1: g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Given device \"%
194 /* determine the valid mount options from the UDI */
195 - device->fsoptions = libhal_device_get_property_strlist (hal_context, udi, "volume.mount.valid_options", &derror);
196 + device->fsoptions = libhal_device_get_property_strlist (hal_context,
197 + udi, "volume.mount.valid_options", &derror);
199 /* sanity checking */
200 if (G_UNLIKELY (device->file == NULL || device->name == NULL))
202 exo_mount_hal_device_free (device);
203 - device = NULL;
204 - goto err0;
205 + exo_mount_hal_propagate_error(error, &derror);
206 + return NULL;
209 /* check if we failed */
210 @@ -282,11 +324,7 @@ err1: g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Given device \"%
211 device = NULL;
214 -out:
215 - /* cleanup */
216 - libhal_free_string_array (interfaces);
217 - g_free (volume_udi);
219 + dbus_error_free (&derror);
220 return device;
223 @@ -313,7 +351,7 @@ exo_mount_hal_device_from_file (const gchar *file,
224 gchar **interfaces;
225 gchar **udis;
226 gint n_udis;
227 - gint n, m;
228 + gint n;
230 g_return_val_if_fail (g_path_is_absolute (file), NULL);
231 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
232 @@ -347,12 +385,7 @@ exo_mount_hal_device_from_file (const gchar *file,
233 continue;
235 /* check if we have a mountable device here */
236 - for (m = 0; interfaces[m] != NULL; ++m)
237 - if (strcmp (interfaces[m], "org.freedesktop.Hal.Device.Volume") == 0)
238 - break;
240 - /* check if it's a usable device */
241 - if (interfaces[m] != NULL)
242 + if (string_in_list (interfaces, "org.freedesktop.Hal.Device.Volume"))
244 libhal_free_string_array (interfaces);
245 break;