chiark / gitweb /
New tracks list can no longer contains dupes
authorRichard Kettlewell <rjk@greenend.org.uk>
Thu, 26 Jun 2008 19:40:01 +0000 (20:40 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Thu, 26 Jun 2008 19:40:01 +0000 (20:40 +0100)
lib/trackdb.c

index b4036f7bf13637666d6df8b057deb3c0baf951e9..718970a417c0c976da070a36b890f4cc6d4e6db6 100644 (file)
@@ -2422,13 +2422,17 @@ static char **trackdb_new_tid(int *ntracksp,
   DBT k, d;
   int err = 0;
   struct vector tracks[1];
+  hash *h = hash_new(1);
 
   vector_init(tracks);
   c = trackdb_opencursor(trackdb_noticeddb, tid);
   while((maxtracks <= 0 || tracks->nvec < maxtracks)
         && !(err = c->c_get(c, prepare_data(&k), prepare_data(&d), DB_PREV))) {
-    /* See if the track still exists */
     char *const track = xstrndup(d.data, d.size);
+    /* Don't add any track more than once */
+    if(hash_add(h, track, "", HASH_INSERT))
+      continue;
+    /* See if the track still exists */
     err = trackdb_getdata(trackdb_tracksdb, track, NULL/*kp*/, tid);
     if(err == DB_NOTFOUND)
       continue;                         /* It doesn't, skip it */