Commit Diff


commit - ee7b409c1f35a02e204ac2e248414c19d73d6f41
commit + 9fad5d8c4a361d55ab50c7d41ddb1353d76c7302
blob - a8d58ed6d271776f1f9c6cfee7e9fa65c38bdf9b
blob + 50ef32d0850f5f4fc8b740e2895e1d5996b0df27
--- include/got_error.h
+++ include/got_error.h
@@ -169,6 +169,7 @@
 #define GOT_ERR_NO_PATCH	149
 #define GOT_ERR_HUNK_FAILED	150
 #define GOT_ERR_PATCH_FAILED	151
+#define GOT_ERR_FILEIDX_DUP_ENTRY 152
 
 struct got_error {
         int code;
blob - 2411c3dde4d6b94f6ce98e88a3b798ee6b941285
blob + bbef129d76eb0c6b8a5a3712a558f9a05d225755
--- lib/error.c
+++ lib/error.c
@@ -222,6 +222,7 @@ static const struct got_error got_errors[] = {
 	{ GOT_ERR_NO_PATCH, "no patch found" },
 	{ GOT_ERR_HUNK_FAILED, "hunk failed to apply" },
 	{ GOT_ERR_PATCH_FAILED, "patch failed to apply" },
+	{ GOT_ERR_FILEIDX_DUP_ENTRY, "duplicate file index entry" },
 };
 
 static struct got_custom_error {
blob - 90e142ecff05e48b31d5eacde6c048c20d94880e
blob + bbbf920360215773ac2f4f979efd72d2e5f2d742
--- lib/fileindex.c
+++ lib/fileindex.c
@@ -262,7 +262,9 @@ add_entry(struct got_fileindex *fileindex, struct got_
 	if (fileindex->nentries >= GOT_FILEIDX_MAX_ENTRIES)
 		return got_error(GOT_ERR_NO_SPACE);
 
-	RB_INSERT(got_fileindex_tree, &fileindex->entries, ie);
+	if (RB_INSERT(got_fileindex_tree, &fileindex->entries, ie) != NULL)
+		return got_error_path(ie->path, GOT_ERR_FILEIDX_DUP_ENTRY);
+
 	fileindex->nentries++;
 	return NULL;
 }
blob - 0756600c6c7bca294f7a50bfa99260c2474ee20e
blob + fcd77a0c22a86ae56b534d992bc21b9c76aa5354
--- lib/object_idset.c
+++ lib/object_idset.c
@@ -101,7 +101,11 @@ got_object_idset_add(struct got_object_idset *set, str
 	memcpy(&new->id, id, sizeof(new->id));
 	new->data = data;
 
-	RB_INSERT(got_object_idset_tree, &set->entries, new);
+	if (RB_INSERT(got_object_idset_tree, &set->entries, new) != NULL) {
+		free(new);
+		return got_error(GOT_ERR_OBJ_EXISTS);
+	}
+
 	set->totelem++;
 	return NULL;
 }