From e46739f18cf99914d09494a3f879bb40556cec56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 5 Nov 2018 17:06:52 -0600 Subject: [PATCH 1/2] bookmarkfile: test that moving to the same name works Verify that we can move a bookmark item to the same name, but actually this causes a crash right now. --- glib/tests/bookmarkfile.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/glib/tests/bookmarkfile.c b/glib/tests/bookmarkfile.c index c81561ea2..cc922c0fc 100644 --- a/glib/tests/bookmarkfile.c +++ b/glib/tests/bookmarkfile.c @@ -94,6 +94,13 @@ test_move_item (void) g_assert (res); g_assert_no_error (error); + res = g_bookmark_file_move_item (bookmark, + "file:///tmp/schedule.ps", + "file:///tmp/schedule.ps", + &error); + g_assert (res); + g_assert_no_error (error); + res = g_bookmark_file_move_item (bookmark, "file:///no-such-file.xbel", "file:///tmp/schedule.ps", From 5c6f185e9ba3dfe562b5de2d314f59f4b13e5424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 5 Nov 2018 17:15:32 -0600 Subject: [PATCH 2/2] bookmarkfile: Don't move an item if the uri has not changed This was causing a crash, because we were first removing an item, freeing both the instance itself and the key, and then trying to reuse those. So, in this case, instead of reassigning an item, we can just return TRUE as we have already the item at the right place, while it's not needed to update the modified timestamp, since no modification happened in reality. Fixes #1588 --- glib/gbookmarkfile.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/glib/gbookmarkfile.c b/glib/gbookmarkfile.c index 4661b9daf..7f4bf5fa4 100644 --- a/glib/gbookmarkfile.c +++ b/glib/gbookmarkfile.c @@ -3528,6 +3528,9 @@ g_bookmark_file_move_item (GBookmarkFile *bookmark, if (new_uri && new_uri[0] != '\0') { + if (g_strcmp0 (old_uri, new_uri) == 0) + return TRUE; + if (g_bookmark_file_has_item (bookmark, new_uri)) { if (!g_bookmark_file_remove_item (bookmark, new_uri, error))