[nautilus-actions] NadpDesktopFile: do not try to import empty or not DES-EMA files
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] NadpDesktopFile: do not try to import empty or not DES-EMA files
- Date: Fri, 2 Dec 2011 10:50:22 +0000 (UTC)
commit a36425f78f04b46c186cbd3b16730b1e2bae02e2
Author: Pierre Wieser <pwieser trychlos org>
Date: Tue Nov 29 20:50:37 2011 +0100
NadpDesktopFile: do not try to import empty or not DES-EMA files
ChangeLog | 4 ++
src/io-desktop/nadp-desktop-file.c | 65 +++++++++++++++++++++++++-----------
src/io-desktop/nadp-reader.c | 2 +-
3 files changed, 50 insertions(+), 21 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 30f0ab6..0b27451 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2011-11-28 Pierre Wieser <pwieser trychlos org>
+ * src/io-desktop/nadp-desktop-file.c (check_key_file):
+ - Do not even try to read zero byte length files.
+ - Check Type key before trying to import the file.
+
* src/core/na-importer-ask.c:
* src/core/na-importer-ask.ui: Make NAImporterAsk normally answer to
response codes, and quit on Esc.
diff --git a/src/io-desktop/nadp-desktop-file.c b/src/io-desktop/nadp-desktop-file.c
index 0410218..50d83c0 100644
--- a/src/io-desktop/nadp-desktop-file.c
+++ b/src/io-desktop/nadp-desktop-file.c
@@ -53,6 +53,7 @@ struct _NadpDesktopFilePrivate {
gboolean dispose_has_run;
gchar *id;
gchar *uri;
+ gchar *type;
GKeyFile *key_file;
};
@@ -178,6 +179,7 @@ instance_finalize( GObject *object )
g_free( self->private->id );
g_free( self->private->uri );
+ g_free( self->private->type );
if( self->private->key_file ){
g_key_file_free( self->private->key_file );
@@ -280,10 +282,14 @@ nadp_desktop_file_new_from_uri( const gchar *uri )
g_debug( "%s: uri=%s", thisfn, uri );
g_return_val_if_fail( uri && g_utf8_strlen( uri, -1 ), ndf );
- ndf = ndf_new( uri );
data = na_core_utils_file_load_from_uri( uri, &length );
+ if( !length ){
+ g_debug( "%s: file is empty", thisfn );
+ return( NULL );
+ }
error = NULL;
+ ndf = ndf_new( uri );
g_key_file_load_from_data( ndf->private->key_file, data, length, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error );
g_free( data );
@@ -439,6 +445,7 @@ check_key_file( NadpDesktopFile *ndf )
gchar *start_group;
gboolean has_key;
gboolean hidden;
+ gchar *type;
GError *error;
ret = TRUE;
@@ -472,6 +479,42 @@ check_key_file( NadpDesktopFile *ndf )
}
}
+ /* must have no Type (which defaults to Action)
+ * or a known one (Action or Menu)
+ */
+ if( ret ){
+ type = NULL;
+ has_key = g_key_file_has_key( ndf->private->key_file, start_group, NADP_KEY_TYPE, &error );
+ if( error ){
+ g_debug( "%s: %s", thisfn, error->message );
+ g_error_free( error );
+ ret = FALSE;
+
+ } else if( has_key ){
+ type = g_key_file_get_string( ndf->private->key_file, start_group, NADP_KEY_TYPE, &error );
+ if( error ){
+ g_debug( "%s: %s", thisfn, error->message );
+ g_free( type );
+ g_error_free( error );
+ ret = FALSE;
+ }
+ }
+ if( ret ){
+ if( !type || !strlen( type )){
+ type = g_strdup( NADP_VALUE_TYPE_ACTION );
+
+ } else if( strcmp( type, NADP_VALUE_TYPE_MENU ) && strcmp( type, NADP_VALUE_TYPE_ACTION )){
+ g_debug( "%s: unmanaged type: %s", thisfn, type );
+ g_free( type );
+ ret = FALSE;
+ }
+ }
+ if( ret ){
+ g_return_val_if_fail( type && strlen( type ), FALSE );
+ ndf->private->type = type;
+ }
+ }
+
g_free( start_group );
return( ret );
@@ -487,10 +530,7 @@ check_key_file( NadpDesktopFile *ndf )
gchar *
nadp_desktop_file_get_file_type( const NadpDesktopFile *ndf )
{
- static const gchar *thisfn = "nadp_desktop_file_get_file_type";
gchar *type;
- gboolean has_key;
- GError *error;
g_return_val_if_fail( NADP_IS_DESKTOP_FILE( ndf ), NULL );
@@ -498,22 +538,7 @@ nadp_desktop_file_get_file_type( const NadpDesktopFile *ndf )
if( !ndf->private->dispose_has_run ){
- error = NULL;
-
- has_key = g_key_file_has_key( ndf->private->key_file, NADP_GROUP_DESKTOP, NADP_KEY_TYPE, &error );
- if( error ){
- g_warning( "%s: %s", thisfn, error->message );
- g_error_free( error );
-
- } else if( has_key ){
- type = g_key_file_get_string( ndf->private->key_file, NADP_GROUP_DESKTOP, NADP_KEY_TYPE, &error );
- if( error ){
- g_warning( "%s: %s", thisfn, error->message );
- g_error_free( error );
- g_free( type );
- type = NULL;
- }
- }
+ type = g_strdup( ndf->private->type );
}
return( type );
diff --git a/src/io-desktop/nadp-reader.c b/src/io-desktop/nadp-reader.c
index 7fee963..f2037df 100644
--- a/src/io-desktop/nadp-reader.c
+++ b/src/io-desktop/nadp-reader.c
@@ -279,7 +279,7 @@ item_from_desktop_file( const NadpDesktopProvider *provider, NadpDesktopFile *nd
item = NULL;
type = nadp_desktop_file_get_file_type( ndf );
- if( !type || !strlen( type ) || !strcmp( type, NADP_VALUE_TYPE_ACTION )){
+ if( !strcmp( type, NADP_VALUE_TYPE_ACTION )){
item = NA_IFACTORY_OBJECT( na_object_action_new());
} else if( !strcmp( type, NADP_VALUE_TYPE_MENU )){
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]