file-roller r2204 - in trunk: . src



Author: paobac
Date: Tue Apr  1 12:24:53 2008
New Revision: 2204
URL: http://svn.gnome.org/viewvc/file-roller?rev=2204&view=rev

Log:
2008-04-01  Paolo Bacchilega  <paobac svn gnome org>

	* src/fr-archive.c: 
	* src/file-utils.h: 
	* src/file-utils.c: 
	* src/file-data.c: 
	* src/actions.c: 

	Continuing GIO port.


Modified:
   trunk/ChangeLog
   trunk/src/actions.c
   trunk/src/file-data.c
   trunk/src/file-utils.c
   trunk/src/file-utils.h
   trunk/src/fr-archive.c

Modified: trunk/src/actions.c
==============================================================================
--- trunk/src/actions.c	(original)
+++ trunk/src/actions.c	Tue Apr  1 12:24:53 2008
@@ -129,8 +129,10 @@
 get_archive_filename_from_selector (FrWindow  *window,
 				    GtkWidget *file_sel)
 {
-	char *path = NULL;
-	char *dir;
+	char      *path = NULL;
+	GFile     *file, *dir;
+	GFileInfo *info;
+	GError    *err = NULL;
 
 	path = get_full_path (file_sel);
 	if ((path == NULL) || (*path == 0)) {
@@ -149,11 +151,31 @@
 		return NULL;
 	}
 
-	dir = remove_level_from_path (path);
-	if (! check_permissions (dir, R_OK | W_OK | X_OK)) {
+	file = g_file_new_for_uri (path);
+
+	dir = g_file_get_parent (file);
+	info = g_file_query_info (dir,
+				  G_FILE_ATTRIBUTE_ACCESS_CAN_READ "," 
+				  G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE "," 
+				  G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE,
+				  0, NULL, &err);
+	if (err != NULL) {
+		g_warning ("Failed to get permission for extraction dir: %s",
+			   err->message);
+		g_clear_error (&err);
+		g_object_unref (info);
+		g_object_unref (dir);
+		g_object_unref (file);
+		g_free (path);
+		return NULL;
+	}
+
+	if (! g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) {
 		GtkWidget *dialog;
 
-		g_free (dir);
+		g_object_unref (info);
+		g_object_unref (dir);
+		g_object_unref (file);
 		g_free (path);
 
 		dialog = _gtk_error_dialog_new (GTK_WINDOW (file_sel),
@@ -165,7 +187,8 @@
 		gtk_widget_destroy (GTK_WIDGET (dialog));
 		return NULL;
 	}
-	g_free (dir);
+	g_object_unref (info);
+	g_object_unref (dir);
 
 	/* if the user did not specify a valid extension use the filetype combobox current type
 	 * or tar.gz if automatic is selected. */
@@ -191,8 +214,6 @@
 	if (path_is_file (path)) {
 		GtkWidget *dialog;
 		int        r;
-		GFile     *file;
-		GError    *err = NULL;
 
 		if (! is_supported_extension (file_sel, path)) {
 			dialog = _gtk_error_dialog_new (GTK_WINDOW (file_sel),
@@ -222,12 +243,11 @@
 
 		if (r != GTK_RESPONSE_YES) {
 			g_free (path);
+			g_object_unref (file);
 			return NULL;
 		}
 
-		file = g_file_new_for_uri (path);
 		g_file_delete (file, NULL, &err);
-		g_object_unref (file);
 		if (err != NULL) {
 			GtkWidget *dialog;
 			dialog = _gtk_error_dialog_new (GTK_WINDOW (file_sel),
@@ -237,12 +257,15 @@
 							err->message);
 			gtk_dialog_run (GTK_DIALOG (dialog));
 			gtk_widget_destroy (GTK_WIDGET (dialog));
-			g_free (path);
 			g_error_free (err);
+			g_free (path);
+			g_object_unref (file);
 			return NULL;
 		}
 	}
-
+	
+	g_object_unref (file);
+	
 	return path;
 }
 
@@ -286,25 +309,31 @@
 	int         idx;
 	const char *filename;
 	const char *ext, *newext;
-	char       *escaped_uri;
-	char       *unescaped_uri;	
 	char       *new_filename, *filename_noext;
+	const char *uri;
+	GFile      *file;
+	GFileInfo  *info;
+	GError     *err = NULL;
 
 	idx = gtk_combo_box_get_active (combo_box) - 1;
 	if (idx < 0)
 		return;
 
-	escaped_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (file_sel));
-	if (escaped_uri == NULL)
+	uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (file_sel));
+	if (uri == NULL)
 		return;
 
-	unescaped_uri = gnome_vfs_format_uri_for_display (escaped_uri);
-	filename = file_name_from_path (unescaped_uri);
-	if (filename == NULL) {
-		g_free (unescaped_uri);
+	file = g_file_new_for_uri (uri);
+	info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, &err);
+	if (err != NULL) {
+		g_warning ("Failed to get display name for uri %s: %s", uri, err->message);
+		g_clear_error (&err);
+		g_object_unref (file);
+		g_free (uri);
 		return;
 	}
 
+	filename = g_file_info_get_display_name (info);
 	ext = fr_archive_utils__get_file_name_ext (filename);
 	if (ext == NULL)
 		ext = "";
@@ -317,7 +346,6 @@
 
 	g_free (new_filename);
 	g_free (filename_noext);
-	g_free (unescaped_uri);
 }
 
 
@@ -555,8 +583,6 @@
 	GtkWidget     *combo_box;
 	GtkFileFilter *filter;
 	int            i;
-	const char    *escaped_uri = NULL;
-	char          *unescaped_uri = NULL;
 
 	file_sel = gtk_file_chooser_dialog_new (_("Save"),
 						GTK_WINDOW (window),
@@ -570,10 +596,28 @@
 	gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (file_sel), fr_window_get_open_default_dir (window));
 
 	if (fr_window_get_archive_uri (window)) {
-		escaped_uri = fr_window_get_archive_uri (window);
-		unescaped_uri = gnome_vfs_format_uri_for_display (escaped_uri);
-		gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (file_sel), file_name_from_path (unescaped_uri));
-		g_free (unescaped_uri);
+		const char *uri;
+		GFile     *file;
+		GFileInfo *info;
+		GError    *err = NULL;
+
+		uri = fr_window_get_archive_uri (window);
+		file = g_file_new_for_uri (uri);
+		info = g_file_query_info (file,
+				G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+				0, NULL, &err);
+
+		if (err != NULL) {
+			g_warning ("Failed to get display name for uri %s: %s", uri, err->message);
+			g_clear_error (&err);
+		} 
+		else {
+			gtk_file_chooser_set_current_name (
+					GTK_FILE_CHOOSER (file_sel),
+					g_file_info_get_display_name (info));
+		}
+		g_object_unref (info);
+		g_object_unref (file);
 	}
 
 	filter = gtk_file_filter_new ();

Modified: trunk/src/file-data.c
==============================================================================
--- trunk/src/file-data.c	(original)
+++ trunk/src/file-data.c	Tue Apr  1 12:24:53 2008
@@ -22,7 +22,7 @@
 
 #include <config.h>
 #include <glib/gi18n.h>
-#include <libgnomevfs/gnome-vfs-mime-handlers.h>
+#include <gio/gio.h>
 #include "file-data.h"
 #include "file-utils.h"
 

Modified: trunk/src/file-utils.c
==============================================================================
--- trunk/src/file-utils.c	(original)
+++ trunk/src/file-utils.c	Tue Apr  1 12:24:53 2008
@@ -35,8 +35,6 @@
 #include <dirent.h>
 
 #include <glib.h>
-#include <libgnomevfs/gnome-vfs.h>
-#include <libgnomevfs/gnome-vfs-mime.h>
 #include <gio/gio.h>
 #include <gconf/gconf-client.h>
 #include "file-utils.h"
@@ -51,6 +49,7 @@
 #define BUF_SIZE 4096
 #define FILE_PREFIX    "file://"
 #define FILE_PREFIX_L  7
+#define SPECIAL_DIR(x) ((strcmp ((x), "..") == 0) || (strcmp ((x), ".") == 0))
 
 
 gboolean
@@ -119,29 +118,38 @@
 
 
 gboolean
-dir_is_empty (const char *path)
+dir_is_empty (const char *uri)
 {
-	DIR *dp;
-	int  n;
-
-	if (strcmp (path, "/") == 0)
-		return FALSE;
+	GFile           *file;
+	GFileEnumerator *file_enum;
+	GFileInfo       *info;
+	GError          *error = NULL;
+	int              n = 0;
 
-	dp = opendir (path);
-	if (dp == NULL)
+	file = g_file_new_for_uri (uri);
+	file_enum = g_file_enumerate_children (file, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &error);
+	if (error != NULL) {
+		g_warning ("Failed to enumerate children of %s: %s", uri, error->message);
+		g_error_free (error);
+		g_object_unref (file_enum);
+		g_object_unref (file);
 		return TRUE;
-
-	n = 0;
-	while (readdir (dp) != NULL) {
-		n++;
-		if (n > 2) {
-			closedir (dp);
-			return FALSE;
+	}
+	
+	while ((n == 0) && ((info = g_file_enumerator_next_file (file_enum, NULL, &error)) != NULL)) {
+		if (error != NULL) {
+			g_warning ("Encountered error while enumerating children of %s (ignoring): %s", uri, error->message);
+			g_error_free (error);
 		}
+		else if (! SPECIAL_DIR (g_file_info_get_name (info))) 
+			n++;
+		g_object_unref (info);
 	}
-	closedir (dp);
 
-	return TRUE;
+	g_object_unref (file);
+	g_object_unref (file_enum);
+	
+	return (n == 0);
 }
 
 
@@ -238,8 +246,7 @@
 	}
 	
 	if (err != NULL) {
-		g_warning ("Failed to get info after enumerating children: %s",
-			   err->message);
+		g_warning ("Failed to get info after enumerating children: %s", err->message);
 		g_clear_error (&err);
 	}
 
@@ -353,65 +360,6 @@
 
 
 gboolean
-file_copy (const gchar *from,
-	   const gchar *to)
-{
-	FILE *fin, *fout;
-	gchar buf[BUF_SIZE];
-	gchar *dest_dir;
-	gint  n;
-
-	if (strcmp (from, to) == 0) {
-		g_warning ("cannot copy file %s: source and destination are the same\n", from);
-		return FALSE;
-	}
-
-	fin = fopen (from, "rb");
-	if (! fin)
-		return FALSE;
-
-	dest_dir = remove_level_from_path (to);
-	if (! ensure_dir_exists (dest_dir, 0755)) {
-		g_free (dest_dir);
-		fclose (fin);
-		return FALSE;
-	}
-
-	fout = fopen (to, "wb");
-	if (! fout) {
-		g_free (dest_dir);
-		fclose (fin);
-		return FALSE;
-	}
-
-	while ((n = fread (buf, sizeof (char), BUF_SIZE, fin)) != 0)
-		if (fwrite (buf, sizeof (char), n, fout) != n) {
-			g_free (dest_dir);
-			fclose (fin);
-			fclose (fout);
-			return FALSE;
-		}
-
-	g_free (dest_dir);
-	fclose (fin);
-	fclose (fout);
-
-	return TRUE;
-}
-
-
-gboolean
-file_move (const gchar *from,
-	   const gchar *to)
-{
-	if (file_copy (from, to) && ! unlink (from))
-		return TRUE;
-
-	return FALSE;
-}
-
-
-gboolean
 file_is_hidden (const gchar *name)
 {
 	if (name[0] != '.') return FALSE;
@@ -523,8 +471,8 @@
 }
 
 
-gchar *
-remove_ending_separator (const gchar *path)
+char *
+remove_ending_separator (const char *path)
 {
 	gint len, copy_len;
 
@@ -539,39 +487,57 @@
 }
 
 
-gboolean
-ensure_dir_exists (const gchar *a_path,
-		   mode_t       mode)
+static gboolean
+make_directory_tree (GFile    *dir,
+		     mode_t    mode,
+		     GError  **error)
 {
-	if (! a_path) return FALSE;
+	GFile *parent;
 
-	if (! path_is_dir (a_path)) {
-		char *path = g_strdup (a_path);
-		char *p = path;
-
-		while (*p != '\0') {
-			p++;
-			if ((*p == '/') || (*p == '\0')) {
-				gboolean end = TRUE;
+	if (dir == NULL) 
+		return FALSE;
 
-				if (*p != '\0') {
-					*p = '\0';
-					end = FALSE;
-				}
-
-				if (! path_is_dir (path)) {
-					if (gnome_vfs_make_directory (path, mode) != GNOME_VFS_OK) {
-						g_warning ("directory creation failed: %s.", path);
-						g_free (path);
-						return FALSE;
-					}
-				}
-				if (! end) *p = '/';
-			}
+	parent = g_file_get_parent (dir);
+	if (parent != NULL) {
+		ensure_dir_exists (parent, mode, error);
+		if (error != NULL) {
+			g_object_unref (parent);
+			return FALSE;
 		}
-		g_free (path);
 	}
+	g_object_unref (parent);
+	
+	g_file_make_directory (dir, NULL, error);
+	if (error != NULL)	
+		return FALSE;
+
+	g_file_set_attribute_uint32 (dir,
+				     G_FILE_ATTRIBUTE_UNIX_MODE,
+				     mode, 
+				     0, 
+				     NULL, 
+				     error);
+	return TRUE;
+}
 
+
+gboolean
+ensure_dir_exists (const char *uri,
+		   mode_t      mode)
+{
+	GFile  *dir;
+	GError *error;
+	
+	if (uri == NULL)
+		return FALSE;
+	
+	dir = g_file_new_for_uri (uri);
+	if (! make_directory_tree (dir, mode, &error)) {
+		g_warning ("could create directory %s: %s", uri, error->message);
+		g_clear_error (&error);
+		return FALSE;
+	}
+	
 	return TRUE;
 }
 
@@ -592,71 +558,10 @@
 
 
 gboolean
-is_mime_type (const char* type, const char* pattern) {
-	return (strncasecmp (type, pattern, strlen (pattern)) == 0);
-}
-
-
-GHashTable *static_strings = NULL;
-
-
-static const char *
-get_static_string (const char *s)
-{
-        const char *result;
-
-        if (s == NULL)
-                return NULL;
-
-        if (static_strings == NULL)
-                static_strings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-
-        if (! g_hash_table_lookup_extended (static_strings, s, (gpointer*) &result, NULL)) {
-                result = g_strdup (s);
-                g_hash_table_insert (static_strings,
-                                     (gpointer) result,
-                                     GINT_TO_POINTER (1));
-        }
-
-        return result;
-}
-
-
-static const char *
-get_extension (const char *path)
-{
-        int         len;
-        int         p;
-        const char *ptr = path;
-
-        if (! path)
-                return NULL;
-
-        len = strlen (path);
-        if (len <= 1)
-                return NULL;
-
-        p = len - 1;
-        while ((p >= 0) && (ptr[p] != '.'))
-                p--;
-
-        if (p < 0)
-                return NULL;
-
-        return path + p;
-}
-
-
-static char*
-get_sample_name (const char *filename)
+is_mime_type (const char *type, 
+	      const char *pattern) 
 {
-        const char *ext;
-
-        ext = get_extension (filename);
-        if (ext == NULL)
-                return NULL;
-
-        return g_strconcat ("a", get_extension (filename), NULL);
+	return (strncasecmp (type, pattern, strlen (pattern)) == 0);
 }
 
 
@@ -664,37 +569,23 @@
 get_file_mime_type (const char *filename,
                     gboolean    fast_file_type)
 {
-	const char *result = NULL;
-	
-        if (filename == NULL)
-                return NULL;
+	GFile      *file;
+	GFileInfo  *info;
+	GError     *err = NULL;
+ 	const char *result = NULL;
+ 	
+	info = g_file_query_info (file, 
+				  fast_file_type ?
+				  G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE :
+				  G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+				  0, NULL, &err);
+
+	result = g_file_info_get_content_type (info);
 
-        if (fast_file_type) {
-                char *sample_name;
-                char *n1;
-
-                sample_name = get_sample_name (filename);
-                if (sample_name != NULL) {
-                        n1 = g_filename_to_utf8 (sample_name, -1, 0, 0, 0);
-                        if (n1 != NULL) {
-                                char *n2 = g_utf8_strdown (n1, -1);
-                                char *n3 = g_filename_from_utf8 (n2, -1, 0, 0, 0);
-                                if (n3 != NULL)
-                                        result = gnome_vfs_mime_type_from_name_or_default (file_name_from_path (n3), NULL);
-                                g_free (n3);
-                                g_free (n2);
-                                g_free (n1);
-                        }
-                        g_free (sample_name);
-                }
-        } 
-        else {
-                if (uri_scheme_is_file (filename))
-                        filename = get_file_path_from_uri (filename);
-                result = gnome_vfs_get_file_mime_type (filename, NULL, FALSE);
-        }
+	g_object_unref (info);
+	g_object_unref (file);
 
-        return get_static_string (result);
+	return result;
 }
 
 
@@ -743,100 +634,67 @@
 }
 
 
-#define SPECIAL_DIR(x) (! strcmp (x, "..") || ! strcmp (x, "."))
-
-
 static gboolean
-get_directory_content (const char  *uri,
-	       	       GList      **files,
-	               GList      **dirs)
-{
-	GnomeVFSDirectoryHandle *h;
-	GnomeVFSResult           result;
-	GnomeVFSFileInfo        *info;
-	GList                   *f_list = NULL;
-	GList                   *d_list = NULL;
-		
-	if (dirs) 
-		*dirs = NULL;
-	if (files) 
-		*files = NULL;
-
-	result = gnome_vfs_directory_open (&h, uri, GNOME_VFS_FILE_INFO_DEFAULT);
-	if (result != GNOME_VFS_OK)
-		return FALSE;	
-
-	info = gnome_vfs_file_info_new ();
-	
-	while ((result = gnome_vfs_directory_read_next (h, info)) == GNOME_VFS_OK) {
-		char *entry_uri;
-		char *e_name;
+delete_directory_recursive (GFile   *dir,
+			    GError **error)
+{
+	GFileEnumerator *file_enum;
+	GFileInfo       *info;
+	gboolean         error_occurred = FALSE;
+	         
+	file_enum = g_file_enumerate_children (dir, 
+					       G_FILE_ATTRIBUTE_STANDARD_NAME "," 
+					       G_FILE_ATTRIBUTE_STANDARD_TYPE,
+					       0, NULL, error);
+
+	while (! error_occurred && (info = g_file_enumerator_next_file (file_enum, NULL, error)) != NULL) {
+		const char *name;
+		char       *child_uri;
+		GFile      *child;
 		
-		e_name = gnome_vfs_escape_string (info->name);
-		entry_uri = g_strconcat (uri, "/", e_name, NULL);
-		g_free (e_name);
+		child_uri = g_build_path ("/", uri, g_file_info_get_name (info), NULL);
+		child = g_file_new_for_uri (child_uri);
 		
-		if (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) {
-			if (! SPECIAL_DIR (info->name)) {
-				d_list = g_list_prepend (d_list, entry_uri);
-				entry_uri = NULL;
-			}
-		}
-		else if (info->type == GNOME_VFS_FILE_TYPE_REGULAR) {
-			f_list = g_list_prepend (f_list, entry_uri);
-			entry_uri = NULL;
+		switch (g_file_info_get_file_type (info)) {
+		case G_FILE_TYPE_DIRECTORY:
+			if (! delete_directory_recursive (child, error)) 
+				error_occurred = TRUE;
+			break;
+		default:
+			if (! g_file_delete (child, NULL, error)) 
+				error_occurred = TRUE;
+			break;
 		}
 		
-		g_free (entry_uri);	
+		g_object_unref (child);
+		g_free (child_uri);
 	}
+
+	if (! error_occurred && ! g_file_delete (dir, NULL, error)) 
+ 		error_occurred = TRUE;
 	
-	gnome_vfs_file_info_unref (info);
-	gnome_vfs_directory_close (h);
+	g_object_unref (file_enum);
 	
-	if (dirs) 
-		*dirs = g_list_reverse (d_list);
-	if (files) 
-		*files = g_list_reverse (f_list);
-
-	return TRUE;
+	return ! error_occurred;
 }
 
 
 gboolean
 remove_directory (const char *uri)
 {
-	GList          *files, *dirs;
-	GList          *scan;
-	gboolean        error = FALSE;
-	GnomeVFSResult  result;
-
-	if (! get_directory_content (uri, &files, &dirs))
-		return FALSE;
-
-	for (scan = files; scan; scan = scan->next) {
-		char *file = scan->data;
-		
-		result = gnome_vfs_unlink (file);
-		if (result != GNOME_VFS_OK) {
-			g_warning ("Cannot delete %s: %s\n", file, gnome_vfs_result_to_string (result));
-			error = TRUE;
-		}
+	GFile     *dir;
+	gboolean   result;
+	GError    *error;
+	
+	dir = g_file_new_for_uri (uri);
+	result = delete_directory_recursive (dir, &error);
+	if (error != NULL) {
+		g_warning ("Cannot delete %s: %s", uri, error->message);
+		g_clear_error (&err);
 	}
-
-	for (scan = dirs; scan; scan = scan->next) 
-		if (! remove_directory ((char*) scan->data))
-			error = TRUE;
+	g_object_unref (dir);
 	
-	path_list_free (files);
-	path_list_free (dirs);
-
-	result = gnome_vfs_remove_directory (uri);
-	if (result != GNOME_VFS_OK) {
-		g_warning ("Cannot delete %s: %s\n", uri, gnome_vfs_result_to_string (result));
-		error = TRUE;
-	}
-
-	return ! error;
+	return result;
 }
 
 
@@ -854,51 +712,19 @@
 }
 
 
-GnomeVFSResult
-make_tree (const char *uri)
+gboolean
+make_tree (const char  *uri,
+	   GError     **error)
 {
-	char  *root;
-	char **parts;
-	char  *parent;
-	int    i;
-
-	root = get_uri_host (uri);
-	if ((uricmp (root, uri) == 0) || (strlen (uri) <= strlen (root) + 1)) {
-		g_free (root);
-		return GNOME_VFS_OK;
-	}
-
-	parts = g_strsplit (uri + strlen (root) + 1, "/", -1);
-	if ((parts == NULL) || (parts[0] == NULL) || (parts[1] == NULL)) {
-		if (parts != NULL)
-			g_strfreev (parts);
-		g_free (root);
-		return GNOME_VFS_OK;
-	}
-
-	parent = g_strdup (root);
-	for (i = 0; parts[i + 1] != NULL; i++) {
-		char           *tmp;
-		GnomeVFSResult  result;
-
-		tmp = g_strconcat (parent, "/", parts[i], NULL);
-		g_free (parent);
-		parent = tmp;
-
-		result = gnome_vfs_make_directory (parent, 0755);
-		if ((result != GNOME_VFS_OK) && (result != GNOME_VFS_ERROR_FILE_EXISTS)) {
-			g_free (parent);
-			g_strfreev (parts);
-			g_free (root);
-			return result;
-		}
+	GFile  *dir;
+	
+	dir = g_file_new_for_uri (uri);
+	if (! make_directory_tree (dir, 0755, error)) {
+		g_warning ("could create directory %s: %s", uri, error->message);
+		return FALSE;
 	}
-
-	g_free (parent);
-	g_strfreev (parts);
-	g_free (root);
-
-	return GNOME_VFS_OK;
+	
+	return TRUE;
 }
 
 
@@ -1011,7 +837,8 @@
 		if (*p != '%') {
 			if (*p != *l)
 				return FALSE;
-		} else {
+		} 
+		else {
 			p++;
 			switch (*p) {
 			case 'a':
@@ -1153,31 +980,29 @@
 check_permissions (const char *uri,
 		   int         mode)
 {
-	GnomeVFSFileInfo *info;
-	GnomeVFSResult    vfs_result;
-	gboolean          result = TRUE;
-
-	info = gnome_vfs_file_info_new ();
-	vfs_result = gnome_vfs_get_file_info (uri,
-					      info,
-					      (GNOME_VFS_FILE_INFO_FOLLOW_LINKS
-					       | GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS));
+	gboolean   result = TRUE;
+	GFile     *file;
+	GFileInfo *info;
+	GError    *err = NULL;
 
-	if (vfs_result != GNOME_VFS_OK)
+	file = g_file_new_for_uri (uri);
+	info = g_file_query_info (file, "access::*", 0, NULL, &err);
+	if (err != NULL) {
+		g_warning ("Failed to get access permissions for %s: %s", uri, err->message);
+		g_clear_error (&err);
 		result = FALSE;
-
-	else if ((mode & R_OK) && ! (info->permissions & GNOME_VFS_PERM_ACCESS_READABLE))
+	}
+	else if ((mode & R_OK) && ! g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ))
 		result = FALSE;
-
-	else if ((mode & W_OK) && ! (info->permissions & GNOME_VFS_PERM_ACCESS_WRITABLE))
+	else if ((mode & W_OK) && ! g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
 		result = FALSE;
-
-	else if ((mode & X_OK) && ! (info->permissions & GNOME_VFS_PERM_ACCESS_EXECUTABLE))
+	else if ((mode & X_OK) && ! g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE))
 		result = FALSE;
 
-	gnome_vfs_file_info_unref (info);
+	g_object_unref (info);
+	g_object_unref (file);
 
-	return TRUE;
+	return result;
 }
 
 
@@ -1218,22 +1043,6 @@
 }
 
 
-GnomeVFSURI *
-new_uri_from_path (const char *path)
-{
-	char        *uri_txt;
-	GnomeVFSURI *uri;
-
-	uri_txt = get_uri_from_local_path (path);
-	uri = gnome_vfs_uri_new (uri_txt);
-	g_free (uri_txt);
-
-	g_return_val_if_fail (uri != NULL, NULL);
-
-	return uri;
-}
-
-
 char *
 get_uri_from_local_path (const char *local_path)
 {

Modified: trunk/src/file-utils.h
==============================================================================
--- trunk/src/file-utils.h	(original)
+++ trunk/src/file-utils.h	Tue Apr  1 12:24:53 2008
@@ -41,27 +41,23 @@
 gboolean            path_is_file                 (const gchar *s);
 gboolean            uri_exists                   (const char  *uri);
 gboolean            path_is_dir                  (const gchar *s);
-gboolean            dir_is_empty                 (const gchar *s);
+gboolean            dir_is_empty                 (const char  *uri);
 gboolean            dir_contains_one_object      (const char  *uri);
 char *              get_directory_content_if_unique (const char  *uri);
 gboolean            path_in_path                 (const char  *path_src,
 						  const char  *path_dest);
 goffset             get_file_size                (const char *uri);
-time_t              get_file_mtime               (const gchar *s);
-time_t              get_file_ctime               (const gchar *s);
-gboolean            file_copy                    (const gchar *from,
-						  const gchar *to);
-gboolean            file_move                    (const gchar *from,
-						  const gchar *to);
-gint                file_in_path                 (const gchar *name);
-gboolean            ensure_dir_exists            (const gchar *a_path,
-						  mode_t       mode);
-gboolean            file_is_hidden               (const gchar *name);
-G_CONST_RETURN char*file_name_from_path          (const gchar *path);
-char *              dir_name_from_path           (const gchar *path);
-gchar *             remove_level_from_path       (const gchar *path);
-gchar *             remove_extension_from_path   (const gchar *path);
-gchar *             remove_ending_separator      (const gchar *path);
+time_t              get_file_mtime               (const char *s);
+time_t              get_file_ctime               (const char *s);
+gint                file_in_path                 (const char *name);
+gboolean            ensure_dir_exists            (const char *uri,
+						  mode_t      mode);
+gboolean            file_is_hidden               (const char *name);
+G_CONST_RETURN char*file_name_from_path          (const char *path);
+char *              dir_name_from_path           (const char *path);
+char *              remove_level_from_path       (const char *path);
+char *              remove_extension_from_path   (const char *path);
+char *              remove_ending_separator      (const char *path);
 gboolean            file_extension_is            (const char *filename,
 						  const char *ext);
 void                path_list_free               (GList *path_list);
@@ -73,7 +69,8 @@
 guint64             get_dest_free_space          (const char  *path);
 gboolean            remove_directory             (const char  *uri);
 gboolean            remove_local_directory       (const char  *directory);
-GnomeVFSResult      make_tree                    (const char  *uri);
+gboolean            make_tree                    (const char  *uri,
+	   					  GError     **error);
 char *              get_temp_work_dir            (void);
 gboolean            is_temp_work_dir             (const char *dir);
 gboolean            is_temp_dir                  (const char *dir);

Modified: trunk/src/fr-archive.c
==============================================================================
--- trunk/src/fr-archive.c	(original)
+++ trunk/src/fr-archive.c	Tue Apr  1 12:24:53 2008
@@ -1824,8 +1824,8 @@
 		local_uri = g_strconcat ("file://", tmp_dir, "/", partial_filename, NULL);
 		local_folder_uri = remove_level_from_path (local_uri);
 		if (g_hash_table_lookup (created_folders, local_folder_uri) == NULL) {
-			GnomeVFSResult result = make_tree (local_uri);
-			if (result != GNOME_VFS_OK) {
+			GError *error;
+			if (! make_tree (local_uri, &error)) {
 				g_free (local_folder_uri);
 				g_free (local_uri);
 				gio_file_list_free (sources);
@@ -1835,7 +1835,8 @@
 				fr_archive_action_completed (archive,
 							     FR_ACTION_COPYING_FILES_FROM_REMOTE,
 							     FR_PROC_ERROR_GENERIC,
-							     gnome_vfs_result_to_string (result));
+							     error->message);
+				g_clear_error (&error);
 				return;
 			}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]