[nautilus-actions] Do not try to import a null or empty list



commit 5d0f435bf18dc06784a726cd7a6c952e9c1d15ff
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sun May 22 18:19:54 2011 +0200

    Do not try to import a null or empty list
    
    This may fix a crash when trying to import a desktop file in NACT, though the
    exact reason why the list to be imported is empty has not been found.

 ChangeLog                        |   14 ++++++++++++++
 src/core/na-iimporter.c          |    8 +++++++-
 src/io-desktop/nadp-reader.c     |    2 +-
 src/nact/nact-assistant-import.c |   37 ++++++++++++++++++-------------------
 src/nact/nact-tree-ieditable.c   |    1 +
 5 files changed, 41 insertions(+), 21 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6b45ead..d0d4733 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-05-22 Pierre Wieser <pwieser trychlos org>
+
+	* src/core/na-iimporter.c (na_iimporter_manage_import_mode):
+	Setup default values.
+
+	* src/io-desktop/nadp-reader.c (nadp_reader_iimporter_import_from_uri):
+	Add trace message before unreffing the imported object.
+
+	* src/nact/nact-assistant-import.c (assistant_apply):
+	Do not try to import an empty list.
+
+	* src/nact/nact-tree-ieditable.c (nact_tree_ieditable_insert_items):
+	Check for non empty list.
+
 2011-05-20 Pierre Wieser <pwieser trychlos org>
 
 	* tools/release-tarball.sh: Use new Gnome release script ftpadmin.
diff --git a/src/core/na-iimporter.c b/src/core/na-iimporter.c
index 7ce08a0..6256c48 100644
--- a/src/core/na-iimporter.c
+++ b/src/core/na-iimporter.c
@@ -168,7 +168,8 @@ na_iimporter_import_from_uri( const NAIImporter *importer, NAIImporterImportFrom
 
 	if( iimporter_initialized && !iimporter_finalized ){
 
-		g_debug( "%s: importer=%p, parms=%p", thisfn, ( void * ) importer, ( void * ) parms );
+		g_debug( "%s: importer=%p (%s), parms=%p", thisfn,
+				( void * ) importer, G_OBJECT_TYPE_NAME( importer), ( void * ) parms );
 
 		if( NA_IIMPORTER_GET_INTERFACE( importer )->import_from_uri ){
 			code = NA_IIMPORTER_GET_INTERFACE( importer )->import_from_uri( importer, parms );
@@ -213,6 +214,7 @@ na_iimporter_import_from_uri( const NAIImporter *importer, NAIImporterImportFrom
 guint
 na_iimporter_manage_import_mode( NAIImporterManageImportModeParms *parms )
 {
+	static const gchar *thisfn = "na_iimporter_manage_import_mode";
 	guint code;
 	NAObjectItem *exists;
 	guint mode;
@@ -223,6 +225,8 @@ na_iimporter_manage_import_mode( NAIImporterManageImportModeParms *parms )
 	code = IMPORTER_CODE_OK;
 	exists = NULL;
 	mode = 0;
+	parms->exist = FALSE;
+	parms->import_mode = parms->asked_mode;
 
 	if( parms->check_fn ){
 		exists = ( *parms->check_fn )( parms->imported, parms->check_fn_data );
@@ -233,6 +237,8 @@ na_iimporter_manage_import_mode( NAIImporterManageImportModeParms *parms )
 		parms->import_mode = IMPORTER_MODE_RENUMBER;
 	}
 
+	g_debug( "%s: exists=%p", thisfn, exists );
+
 	if( exists ){
 		parms->exist = TRUE;
 
diff --git a/src/io-desktop/nadp-reader.c b/src/io-desktop/nadp-reader.c
index f2406eb..8f2bb6c 100644
--- a/src/io-desktop/nadp-reader.c
+++ b/src/io-desktop/nadp-reader.c
@@ -375,7 +375,6 @@ nadp_reader_iimporter_import_from_uri( const NAIImporter *instance, NAIImporterI
 				ndf, &parms->messages );
 
 		if( parms->imported ){
-			code = IMPORTER_CODE_OK;
 			g_return_val_if_fail( NA_IS_OBJECT_ITEM( parms->imported ), IMPORTER_CODE_NOT_WILLING_TO );
 
 			/* remove the weak reference on desktop file set by 'item_from_desktop_file'
@@ -402,6 +401,7 @@ nadp_reader_iimporter_import_from_uri( const NAIImporter *instance, NAIImporterI
 
 		if( code != IMPORTER_CODE_OK ){
 			if( parms->imported ){
+				g_debug( "%s: unreffing imported item %p as na_iimporter_manage_import_mode didn't return IMPORTER_CODE_OK", thisfn, parms->imported );
 				g_object_unref( parms->imported );
 				parms->imported = NULL;
 			}
diff --git a/src/nact/nact-assistant-import.c b/src/nact/nact-assistant-import.c
index 86d974d..be4ba70 100644
--- a/src/nact/nact-assistant-import.c
+++ b/src/nact/nact-assistant-import.c
@@ -606,7 +606,7 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 {
 	static const gchar *thisfn = "nact_assistant_import_assistant_apply";
 	NactAssistantImport *window;
-	NAImporterParms import_parms;
+	NAImporterParms importer_parms;
 	GtkWidget *chooser;
 	BaseWindow *main_window;
 	GList *it;
@@ -622,32 +622,29 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 	window = NACT_ASSISTANT_IMPORT( wnd );
 
 	imported_items = NULL;
-	memset( &import_parms, '\0', sizeof( NAImporterParms ));
+	memset( &importer_parms, '\0', sizeof( NAImporterParms ));
 
 	g_object_get( G_OBJECT( wnd ), BASE_PROP_PARENT, &main_window, NULL );
-	import_parms.parent = base_window_get_gtk_toplevel( main_window );
-
+	importer_parms.parent = base_window_get_gtk_toplevel( main_window );
 	chooser = base_window_get_widget( BASE_WINDOW( window ), "ImportFileChooser" );
-	import_parms.uris = gtk_file_chooser_get_uris( GTK_FILE_CHOOSER( chooser ));
-	import_parms.mode = get_import_mode( window );
-
-	import_parms.check_fn = ( NAIImporterCheckFn ) check_for_existence;
-	import_parms.check_fn_data = main_window;
-
+	importer_parms.uris = gtk_file_chooser_get_uris( GTK_FILE_CHOOSER( chooser ));
+	importer_parms.mode = get_import_mode( window );
+	importer_parms.check_fn = ( NAIImporterCheckFn ) check_for_existence;
+	importer_parms.check_fn_data = main_window;
 	application = NACT_APPLICATION( base_window_get_application( main_window ));
 	updater = nact_application_get_updater( application );
-	na_importer_import_from_list( NA_PIVOT( updater ), &import_parms );
 
-	for( it = import_parms.results ; it ; it = it->next ){
-		result = ( NAImporterResult * ) it->data;
+	na_importer_import_from_list( NA_PIVOT( updater ), &importer_parms );
 
+	for( it = importer_parms.results ; it ; it = it->next ){
+		result = ( NAImporterResult * ) it->data;
 		if( result->imported ){
 			imported_items = g_list_prepend( imported_items, result->imported );
 		}
 	}
 
-	na_core_utils_slist_free( import_parms.uris );
-	window->private->results = import_parms.results;
+	na_core_utils_slist_free( importer_parms.uris );
+	window->private->results = importer_parms.results;
 
 	/* then insert the list
 	 * assuring that actions will be inserted in the same order as uris
@@ -656,10 +653,12 @@ assistant_apply( BaseAssistant *wnd, GtkAssistant *assistant )
 	 * on the inserted objects; the pointers so remain valid even after
 	 * having released the imported_items list
 	 */
-	imported_items = g_list_reverse( imported_items );
-	items_view = nact_main_window_get_items_view( NACT_MAIN_WINDOW( main_window ));
-	nact_tree_ieditable_insert_items( NACT_TREE_IEDITABLE( items_view ), imported_items, NULL );
-	na_object_free_items( imported_items );
+	if( imported_items ){
+		imported_items = g_list_reverse( imported_items );
+		items_view = nact_main_window_get_items_view( NACT_MAIN_WINDOW( main_window ));
+		nact_tree_ieditable_insert_items( NACT_TREE_IEDITABLE( items_view ), imported_items, NULL );
+		na_object_free_items( imported_items );
+	}
 }
 
 static NAObjectItem *
diff --git a/src/nact/nact-tree-ieditable.c b/src/nact/nact-tree-ieditable.c
index 8a8b684..1286fea 100644
--- a/src/nact/nact-tree-ieditable.c
+++ b/src/nact/nact-tree-ieditable.c
@@ -670,6 +670,7 @@ nact_tree_ieditable_insert_items( NactTreeIEditable *instance, GList *items, NAO
 	NAObject *object, *parent;
 
 	g_return_if_fail( NACT_IS_TREE_IEDITABLE( instance ));
+	g_return_if_fail( items );
 
 	if( st_tree_ieditable_initialized && !st_tree_ieditable_finalized ){
 		g_debug( "%s: instance=%p, items=%p (count=%d), sibling=%p",



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