mood: Don't add files without valid information to the score table.
authorAndre Noll <maan@systemlinux.org>
Wed, 4 Sep 2013 19:18:59 +0000 (19:18 +0000)
committerAndre Noll <maan@systemlinux.org>
Sun, 13 Oct 2013 13:25:06 +0000 (15:25 +0200)
Currently if get_afsi_of_row() fails, we add the file to the score
list anyway. This function should never fail, and if it does, we are
in serious trouble anyway and should return the proper error code
rather than success.

mood.c

diff --git a/mood.c b/mood.c
index e60ef2f..465a48e 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -474,13 +474,9 @@ static long compute_last_played_score(struct afs_info *afsi)
                statistics.last_played_sum, statistics.last_played_qd);
 }
 
-static long compute_dynamic_score(const struct osl_row *aft_row)
+static long compute_dynamic_score(struct afs_info *afsi)
 {
-       struct afs_info afsi;
-
-       if (get_afsi_of_row(aft_row, &afsi) < 0)
-               return -100;
-       return compute_num_played_score(&afsi) + compute_last_played_score(&afsi);
+       return compute_num_played_score(afsi) + compute_last_played_score(afsi);
 }
 
 static int add_afs_statistics(const struct osl_row *row)
@@ -672,7 +668,13 @@ static int update_afs_statistics(struct afs_info *old_afsi, struct afs_info *new
 
 static int add_to_score_table(const struct osl_row *aft_row, long mood_score)
 {
-       long score = (compute_dynamic_score(aft_row) + mood_score) / 3;
+       long score;
+       struct afs_info afsi;
+       int ret = get_afsi_of_row(aft_row, &afsi);
+
+       if (ret < 0)
+               return ret;
+       score = (compute_dynamic_score(&afsi) + mood_score) / 3;
        return score_add(aft_row, score);
 }