chiark / gitweb /
minor tidying following last change
[disorder] / server / trackdb.c
index 223dc808c85f2a67457c4b7d5bc52297020d0bb3..6f89f2a8ec2329041d62a187561c0c2dcfc21172 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder
- * Copyright (C) 2005, 2006 Richard Kettlewell
+ * Copyright (C) 2005, 2006, 2007 Richard Kettlewell
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -491,9 +491,12 @@ static char **track_to_words(const char *track,
   struct vector v;
   char **w;
   int nw;
+  const char *rootless = track_rootless(track);
 
+  if(!rootless)
+    rootless = track;                   /* bodge */
   vector_init(&v);
-  if((w = words(casefold(strip_extension(track_rootless(track))), &nw)))
+  if((w = words(casefold(strip_extension(rootless)), &nw)))
     vector_append_many(&v, w, nw);
 
   for(; p; p = p->next)
@@ -578,11 +581,15 @@ static int compute_alias(char **aliasp,
   const char *s = config->alias, *t, *expansion, *part;
   int c, used_db = 0, slash_prefix, err;
   struct kvp *at;
+  const char *const root = find_track_root(track);
 
-  if(strstr(track, "Troggs"))
-    D(("computing alias for %s", track));
+  if(!root) {
+    /* Bodge for tracks with no root */
+    *aliasp = 0;
+    return 0;
+  }
   dynstr_init(&d);
-  dynstr_append_string(&d, find_track_root(track));
+  dynstr_append_string(&d, root);
   while((c = (unsigned char)*s++)) {
     if(c != '{') {
       dynstr_append(&d, c);
@@ -615,20 +622,11 @@ static int compute_alias(char **aliasp,
    * an alias) */
   switch(err = trackdb_getdata(trackdb_tracksdb, d.vec, &at, tid)) {
   case 0:
-    if(strstr(track, "Troggs"))
-      D(("found a hit for alias"));
     if((s = kvp_get(at, "_alias_for"))
        && !strcmp(s, track)) {
     case DB_NOTFOUND:
-      if(strstr(track, "Troggs"))
-        D(("accepting anyway"));
       *aliasp = d.vec;
     } else {
-      if(strstr(track, "Troggs")) {
-        D(("rejecting"));
-        D(("%s", track));
-        D(("%s", s ? s : "(null)"));
-      }
       *aliasp = 0;
     }
     return 0;
@@ -1162,7 +1160,8 @@ static int tag_intersection(char **a, char **b) {
 }
 
 /* Check whether a track is suitable for random play.  Returns 0 if it is,
- * DB_NOTFOUND if it or DB_LOCK_DEADLOCK. */
+ * DB_NOTFOUND if it is not or DB_LOCK_DEADLOCK if the database gave us
+ * that. */
 static int check_suitable(const char *track,
                           DB_TXN *tid,
                           char **required_tags,
@@ -1172,6 +1171,12 @@ static int check_suitable(const char *track,
   struct kvp *p, *t;
   const char *pick_at_random, *played_time;
 
+  /* don't pick tracks that aren't in any surviving collection (for instance
+   * you've edited the config but the rescan hasn't done its job yet) */
+  if(!find_track_root(track)) {
+    info("found track not in any collection: %s", track);
+    return DB_NOTFOUND;
+  }
   /* don't pick aliases - only pick the canonical form */
   if(gettrackdata(track, &t, &p, 0, 0, tid) == DB_LOCK_DEADLOCK)
     return DB_LOCK_DEADLOCK;
@@ -1830,4 +1835,3 @@ fill-column:79
 indent-tabs-mode:nil
 End:
 */
-/* arch-tag:/CBQ6uebrasgkefvjc+fHQ */