summaryrefslogtreecommitdiffstats
path: root/meta/recipes-kernel/oprofile/oprofileui/migrate-from-gnomevfs-to-gio.patch
blob: bf3979f0d3870687c5699adfb23add55f0406b29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
migrate from gnome-vfs to gio, as gnome-vfs is obsolete.

Signed-off-by: Zhai Edwin <edwin.zhai@intel.com>

Upstream-Status: Pending

Index: git/src/main.c
===================================================================
--- git.orig/src/main.c	2011-06-21 10:35:31.000000000 +0800
+++ git/src/main.c	2011-06-21 10:44:12.000000000 +0800
@@ -44,7 +44,6 @@
 #include <gtk/gtk.h>
 #include <glade/glade.h>
 #include <glib.h>
-#include <libgnomevfs/gnome-vfs.h>
 #include <gconf/gconf-client.h>
 #include <glib/gi18n.h>
 
@@ -1005,8 +1004,7 @@
   /* Cleanup the old archive */
   archive_full_cleanup ();
 
-  if (gnome_vfs_initialized())
-    gnome_vfs_shutdown ();
+  g_type_init();
 
   g_free(opui_config->host);
   g_free(opui_config->opcontrol_params);
Index: git/src/archive.c
===================================================================
--- git.orig/src/archive.c	2011-06-21 10:38:57.000000000 +0800
+++ git/src/archive.c	2011-06-21 10:54:16.000000000 +0800
@@ -45,7 +45,6 @@
 #include <glade/glade.h>
 #include <glib.h>
 #include <glib/gstdio.h>
-#include <libgnomevfs/gnome-vfs.h>
 
 #include "oprofileui.h"
 #include "response.h"
@@ -86,56 +85,113 @@
 
   if (ret < 0)
     {
-      /* Use gnomevfs to copy the file as a fallback */
-      GnomeVFSURI *src_uri, *dst_uri;
-      GnomeVFSResult res;
-
-      src_uri = gnome_vfs_uri_new (gnome_vfs_get_uri_from_local_path(src));
-      dst_uri = gnome_vfs_uri_new (gnome_vfs_get_uri_from_local_path(dest));
-      res = gnome_vfs_xfer_uri (src_uri, dst_uri,
-          GNOME_VFS_XFER_DEFAULT |
-          GNOME_VFS_XFER_NEW_UNIQUE_DIRECTORY, 
-          GNOME_VFS_XFER_ERROR_MODE_ABORT,
-          GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
-          NULL, NULL);
-      if (res != GNOME_VFS_OK)
+      /* Use gio to copy the file as a fallback */
+      GFile *src_file, *dst_file;
+      gboolean res;
+      GError *error = NULL;
+
+      src_file = g_file_new_for_path (src);
+      dst_file = g_file_new_for_path (dest);
+
+      res = g_file_copy(src_file, dst_file,
+                        G_FILE_COPY_NOFOLLOW_SYMLINKS |
+                        G_FILE_COPY_OVERWRITE,
+                        NULL,
+                        NULL,
+                        NULL,
+                        &error);
+
+      if (!res && error)
         {
-          const gchar *err_string = gnome_vfs_result_to_string (res);
+          printf ("GIO: error %s (%s to %s)\n", error->message, src, dest);
 
-          printf ("GNOME-VFS: error %s (%s to %s)\n", err_string, src, dest);
+          g_error_free(error);
         }
+
+      g_object_unref(src_file);
+      g_object_unref(dst_file);
+
+    }
+}
+
+#define IS_IO_ERROR(__error, KIND) (((__error)->domain == G_IO_ERROR && (__error)->code == G_IO_ERROR_ ## KIND))
+
+static gboolean
+remove_target_recursively(GFile *file)
+{
+  GFileEnumerator *enumerator;
+  GError *error = NULL;
+  GFile *child;
+  GFileInfo *info;
+  gboolean stop = FALSE;
+
+  enumerator = g_file_enumerate_children(file,
+                                         G_FILE_ATTRIBUTE_STANDARD_NAME,
+                                         G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                         NULL,
+                                         &error);
+
+  if (enumerator)
+    {
+      error = NULL;
+
+      while ( (info = g_file_enumerator_next_file(enumerator, NULL, &error))
+               != NULL ) {
+
+        child = g_file_get_child(file, g_file_info_get_name(info));
+        if (!remove_target_recursively(child))
+          {
+              stop = TRUE;
+              break;
+          }
+        g_object_unref(child);
+        g_object_unref(info);
+      }
+
+      g_object_unref(enumerator);
+    }
+  else if (IS_IO_ERROR(error, NOT_DIRECTORY))
+    {
+      g_error_free(error);
     }
+  else
+    {
+      g_error_free(error);
+      stop = TRUE;
+    }
+
+  if (stop)
+    return FALSE;
+
+  error = NULL;
+  if (!g_file_delete(file, NULL, &error))
+    {
+      char *path = g_file_get_path(file);
+      printf ("GIO: error %s when deleteing file %s.\n", error->message, path);
+      g_free(path);
+
+      g_error_free(error);
+      return FALSE;
+    }
+
+  return TRUE;
+
 }
 
 /* Delete the directory specified by path */
 static void
 archive_removedir(gchar *path)
 {
-  GnomeVFSResult res;
-  GnomeVFSURI *src_uri;
-  GList uri_list;
+  GFile *src_file;
 
   if (path == NULL)
     return;
 
-  gnome_vfs_init ();
-
-  src_uri = gnome_vfs_uri_new (gnome_vfs_get_uri_from_local_path(path));
-
-  uri_list.data = src_uri;
-  uri_list.next = NULL;
-  uri_list.prev = NULL;
+  src_file = g_file_new_for_path (path);
 
-  res = gnome_vfs_xfer_delete_list (&uri_list,
-      GNOME_VFS_XFER_ERROR_MODE_ABORT,
-      GNOME_VFS_XFER_EMPTY_DIRECTORIES,
-      NULL, NULL);
-
-  if (res != GNOME_VFS_OK)
+  if (! remove_target_recursively(src_file))
     {
-      const gchar *err_string = gnome_vfs_result_to_string (res);
-
-      printf ("GNOME-VFS: error %s\n", err_string);
+      printf ("GIO:remove %s failed", path);
     }
 }
 
@@ -242,8 +298,6 @@
   gchar **tmp;
   int i;
 
-  gnome_vfs_init ();
-
   tmp = g_strsplit (reply->payload, "\n", 0);
 
   for (i=0; i < g_strv_length (tmp); i++)
@@ -436,8 +490,6 @@
 {
   gint counter;
 
-  gnome_vfs_init ();
-
   downloaded_files = g_slist_append (downloaded_files, g_strdup("/var/lib/oprofile/.converted"));
 
   archive_save_window_show (g_slist_length (downloaded_files) +
Index: git/configure.ac
===================================================================
--- git.orig/configure.ac	2011-06-21 10:49:40.000000000 +0800
+++ git/configure.ac	2011-06-21 10:49:58.000000000 +0800
@@ -29,7 +29,7 @@
 AM_CONDITIONAL(ENABLE_SERVER, test x$enable_server = xyes)
 AM_CONDITIONAL(ENABLE_CLIENT, test x$enable_client = xyes)
 
-PKG_CHECK_MODULES(OPROFILEUI, [glib-2.0 libglade-2.0 gtk+-2.0 libxml-2.0 gnome-vfs-2.0 gconf-2.0])
+PKG_CHECK_MODULES(OPROFILEUI, [glib-2.0 libglade-2.0 gtk+-2.0 libxml-2.0 gconf-2.0])
 AC_SUBST(OPROFILEUI_CFLAGS)
 AC_SUBST(OPROFILEUI_LIBS)