changeset 915:8cca92a61c6c

do not create duplicate FileData entries
author nadvornik
date Tue, 22 Jul 2008 22:05:20 +0000
parents 9427c91951e8
children 64fd2fc5cb7a
files src/filedata.c
diffstat 1 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/filedata.c	Tue Jul 22 21:46:08 2008 +0000
+++ b/src/filedata.c	Tue Jul 22 22:05:20 2008 +0000
@@ -179,6 +179,9 @@
 		g_hash_table_remove(file_data_pool, fd->original_path);
 		g_free(fd->original_path);
 		}
+
+	g_assert(!g_hash_table_lookup(file_data_pool, path));
+
 	fd->original_path = g_strdup(path);
 	g_hash_table_insert(file_data_pool, fd->original_path, fd);
 
@@ -1758,7 +1761,20 @@
 		{
 		DEBUG_1("planned change: applying %s -> %s", fd->change->dest, fd->path);
 		file_data_planned_change_remove(fd);
-		file_data_set_path(fd, fd->change->dest);
+		
+		if (g_hash_table_lookup(file_data_pool, fd->change->dest))
+			{
+			/* this change overwrites another file which is already known to other modules
+			   renaming fd would create duplicate FileData structure
+			   the best thing we can do is nothing
+			   FIXME: maybe we could copy stuff like marks
+			*/
+			DEBUG_1("can't rename fd, target exists %s -> %s", fd->change->dest, fd->path);
+			}
+		else
+			{
+			file_data_set_path(fd, fd->change->dest);
+			}
 		}
 	file_data_increment_version(fd);
 	file_data_send_notification(fd, NOTIFY_TYPE_CHANGE);