[nautilus-actions] Do not try to deal with malformed URIs
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Do not try to deal with malformed URIs
- Date: Mon, 23 Aug 2010 08:56:26 +0000 (UTC)
commit f142c9f1da40e03b73854c612c6e6164e3666ae5
Author: Pierre Wieser <pwieser trychlos org>
Date: Mon Aug 23 10:26:14 2010 +0200
Do not try to deal with malformed URIs
ChangeLog | 7 ++++++
src/core/na-selected-info.c | 40 +++++++++++++++++++++++++------------
src/core/na-selected-info.h | 2 +-
src/utils/nautilus-actions-run.c | 15 ++++++++++++-
4 files changed, 48 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9a1f746..77a5b42 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2010-08-23 Pierre Wieser <pwieser trychlos org>
+ * src/core/na-selected-info.c:
+ * src/core/na-selected-info.h (na_selected_info_create_for_uri):
+ Add errmsg parameter to check for incorrect URIs.
+
+ * src/utils/nautilus-actions-run.c (get_selection_from_strv):
+ Do not try to deal with malformed URIs.
+
* src/utils/nautilus-actions-schemas.c: Include glib-object.h.
* src/api/na-data-boxed.h: Revert to glib-object.h.
diff --git a/src/core/na-selected-info.c b/src/core/na-selected-info.c
index a5b669e..de0efcd 100644
--- a/src/core/na-selected-info.c
+++ b/src/core/na-selected-info.c
@@ -69,8 +69,8 @@ static void instance_finalize( GObject *object );
static void dump( const NASelectedInfo *nsi );
static NASelectedInfo *new_from_nautilus_file_info( NautilusFileInfo *item );
-static NASelectedInfo *new_from_uri( const gchar *uri, const gchar *mimetype );
-static void query_file_attributes( NASelectedInfo *info );
+static NASelectedInfo *new_from_uri( const gchar *uri, const gchar *mimetype, gchar **errmsg );
+static gboolean query_file_attributes( NASelectedInfo *info, gchar **errmsg );
GType
na_selected_info_get_type( void )
@@ -585,17 +585,19 @@ na_selected_info_is_writable( const NASelectedInfo *nsi )
* na_selected_info_create_for_uri:
* @uri: an URI.
* @mimetype: the corresponding Nautilus mime type, or %NULL.
+ * @errmsg: a pointer to a string which will contain an error message on
+ * return.
*
* Returns: a newly allocated #NASelectedInfo object for the given @uri.
*/
NASelectedInfo *
-na_selected_info_create_for_uri( const gchar *uri, const gchar *mimetype )
+na_selected_info_create_for_uri( const gchar *uri, const gchar *mimetype, gchar **errmsg )
{
static const gchar *thisfn = "na_selected_info_create_for_uri";
g_debug( "%s: uri=%s, mimetype=%s", thisfn, uri, mimetype );
- NASelectedInfo *obj = new_from_uri( uri, mimetype );
+ NASelectedInfo *obj = new_from_uri( uri, mimetype, errmsg );
return( obj );
}
@@ -619,7 +621,7 @@ new_from_nautilus_file_info( NautilusFileInfo *item )
{
gchar *uri = nautilus_file_info_get_uri( item );
gchar *mimetype = nautilus_file_info_get_mime_type( item );
- NASelectedInfo *info = new_from_uri( uri, mimetype );
+ NASelectedInfo *info = new_from_uri( uri, mimetype, NULL );
g_free( mimetype );
g_free( uri );
@@ -627,7 +629,7 @@ new_from_nautilus_file_info( NautilusFileInfo *item )
}
static NASelectedInfo *
-new_from_uri( const gchar *uri, const gchar *mimetype )
+new_from_uri( const gchar *uri, const gchar *mimetype, gchar **errmsg )
{
NASelectedInfo *info = g_object_new( NA_SELECTED_INFO_TYPE, NULL );
@@ -635,18 +637,24 @@ new_from_uri( const gchar *uri, const gchar *mimetype )
if( mimetype ){
info->private->mimetype = g_strdup( mimetype );
}
+
info->private->location = g_file_new_for_uri( uri );
info->private->vfs = g_new0( NAGnomeVFSURI, 1 );
-
- query_file_attributes( info );
na_gnome_vfs_uri_parse( info->private->vfs, info->private->uri );
- dump( info );
+ if( query_file_attributes( info, errmsg )){
+ dump( info );
+
+ } else {
+ g_object_unref( info );
+ info = NULL;
+ }
+
return( info );
}
-static void
-query_file_attributes( NASelectedInfo *nsi )
+static gboolean
+query_file_attributes( NASelectedInfo *nsi, gchar **errmsg )
{
static const gchar *thisfn = "na_selected_info_query_file_attributes";
GError *error;
@@ -662,9 +670,13 @@ query_file_attributes( NASelectedInfo *nsi )
G_FILE_QUERY_INFO_NONE, NULL, &error );
if( error ){
- g_warning( "%s: g_file_query_info: %s", thisfn, error->message );
+ if( errmsg ){
+ *errmsg = g_strdup_printf( "Error when querying informations for %s URI: %s", nsi->private->uri, error->message );
+ } else {
+ g_warning( "%s: g_file_query_info: %s", thisfn, error->message );
+ }
g_error_free( error );
- return;
+ return( FALSE );
}
if( !nsi->private->mimetype ){
@@ -680,4 +692,6 @@ query_file_attributes( NASelectedInfo *nsi )
nsi->private->owner = g_strdup( g_file_info_get_attribute_as_string( info, G_FILE_ATTRIBUTE_OWNER_USER ));
g_object_unref( info );
+
+ return( TRUE );
}
diff --git a/src/core/na-selected-info.h b/src/core/na-selected-info.h
index 18072a9..c316d5d 100644
--- a/src/core/na-selected-info.h
+++ b/src/core/na-selected-info.h
@@ -93,7 +93,7 @@ gboolean na_selected_info_is_owner ( const NASelectedInfo *nsi, cons
gboolean na_selected_info_is_readable ( const NASelectedInfo *nsi );
gboolean na_selected_info_is_writable ( const NASelectedInfo *nsi );
-NASelectedInfo *na_selected_info_create_for_uri( const gchar *uri, const gchar *mimetype );
+NASelectedInfo *na_selected_info_create_for_uri( const gchar *uri, const gchar *mimetype, gchar **errmsg );
G_END_DECLS
diff --git a/src/utils/nautilus-actions-run.c b/src/utils/nautilus-actions-run.c
index fa04404..6f6e08e 100644
--- a/src/utils/nautilus-actions-run.c
+++ b/src/utils/nautilus-actions-run.c
@@ -336,6 +336,7 @@ get_selection_from_strv( const gchar **strv, gboolean has_mimetype )
{
GList *list;
gchar **iter;
+ gchar *errmsg;
list = NULL;
iter = ( gchar ** ) strv;
@@ -347,8 +348,18 @@ get_selection_from_strv( const gchar **strv, gboolean has_mimetype )
iter++;
mimetype = ( const gchar * ) *iter;
}
- NASelectedInfo *nsi = na_selected_info_create_for_uri( uri, mimetype );
- list = g_list_prepend( list, nsi );
+
+ errmsg = NULL;
+ NASelectedInfo *nsi = na_selected_info_create_for_uri( uri, mimetype, &errmsg );
+
+ if( errmsg ){
+ g_printerr( "%s\n", errmsg );
+ g_free( errmsg );
+ }
+
+ if( nsi ){
+ list = g_list_prepend( list, nsi );
+ }
iter++;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]