File fix-crash-when-missing-desktop-icon-size-bsc1001692.diff of Package nautilus

Index: nautilus-3.20.3/src/nautilus-desktop-canvas-view.c
===================================================================
--- nautilus-3.20.3.orig/src/nautilus-desktop-canvas-view.c
+++ nautilus-3.20.3/src/nautilus-desktop-canvas-view.c
@@ -40,6 +40,7 @@
 #include <gdk/gdkx.h>
 #include <glib/gi18n.h>
 #include <libnautilus-private/nautilus-desktop-icon-file.h>
+#include <libnautilus-private/nautilus-canvas-private.h>
 #include <libnautilus-private/nautilus-directory-notify.h>
 #include <libnautilus-private/nautilus-file-changes-queue.h>
 #include <libnautilus-private/nautilus-file-operations.h>
@@ -256,6 +257,7 @@ nautilus_desktop_canvas_view_end_loading
 	guint current_icon_size;
 	gchar *current_icon_size_string;
 	NautilusFile *file;
+	NautilusCanvasContainer *canvas_container;
 
   	NAUTILUS_FILES_VIEW_CLASS (nautilus_desktop_canvas_view_parent_class)->end_loading (view, all_files_seen);
 
@@ -266,12 +268,29 @@ nautilus_desktop_canvas_view_end_loading
   	g_return_if_fail (file != NULL);
 
 	stored_size_icon = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_DESKTOP_ICON_SIZE, NULL);
-	current_zoom = nautilus_canvas_container_get_zoom_level (get_canvas_container (view));
+	canvas_container = get_canvas_container (view);
+	current_zoom = nautilus_canvas_container_get_zoom_level (canvas_container);
 	current_icon_size = nautilus_canvas_container_get_icon_size_for_zoom_level (current_zoom);
 	needs_reorganization = stored_size_icon == NULL || atoi (stored_size_icon) != current_icon_size;
 
 	if (needs_reorganization) {
 		current_icon_size_string = g_strdup_printf ("%d", current_icon_size);
+
+		// If there's no stored_size_icon and any icon has has_lazy_position to TRUE
+		// then nautilus crashes on a g_assert(!auto_layout) in finish_adding_new_icons
+		// because nautilus_canvas_container_sort sets it to TRUE, so in that case
+		// we reassign the position of all icons by setting has_lazy_position to FALSE.
+		if (stored_size_icon == NULL) {
+			GList *p, *new_icons;
+			NautilusCanvasIcon *icon;
+
+			new_icons = canvas_container->details->new_icons;
+			for (p = new_icons; p != NULL; p = p->next) {
+				icon = p->data;
+				icon->has_lazy_position = FALSE;
+			}
+		}
+
 		nautilus_canvas_view_clean_up_by_name (NAUTILUS_CANVAS_VIEW (view));
 	  	nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_DESKTOP_ICON_SIZE,
                                             NULL, current_icon_size_string);
openSUSE Build Service is sponsored by