robustness fixes for the random selector
authorAndre <maan@meins.(none)>
Mon, 11 Sep 2006 22:57:10 +0000 (00:57 +0200)
committerAndre <maan@meins.(none)>
Mon, 11 Sep 2006 22:57:10 +0000 (00:57 +0200)
- do not abort if stat for an audio file failed. Simply skip this file
  instead.

- return proper error message if custom function failed.

- do not error out if the second scan for audio files yields more
  files than the previous run. This happens if audio files are
  added during the audio file scan of the random selector.

db.c
error.h
random_selector.c

diff --git a/db.c b/db.c
index 9db622b..8b06672 100644 (file)
--- a/db.c
+++ b/db.c
@@ -75,14 +75,15 @@ int find_audio_files(const char *dirname, int (*f)(const char *, const char *))
                        continue;
                ret = -E_LSTAT;
                if (lstat(entry->d_name, &s) == -1)
-                       goto out;
+                       continue;
                m = s.st_mode;
                if (!S_ISREG(m) && !S_ISDIR(m)) /* skip links, sockets, ... */
                        continue;
                if (S_ISREG(m)) { /* regular file */
                        if (guess_audio_format(entry->d_name) < 0)
                                continue;
-                       if (f(dirname, entry->d_name) < 0)
+                       ret = f(dirname, entry->d_name);
+                       if (ret < 0)
                                goto out;
                        continue;
                }
diff --git a/error.h b/error.h
index 0f83398..cb5e2b0 100644 (file)
--- a/error.h
+++ b/error.h
@@ -321,7 +321,6 @@ extern const char **para_errlist[];
 
 
 #define RANDOM_SELECTOR_ERRORS \
-       PARA_ERROR(FILE_COUNT, "audio file count exceeded"), \
        PARA_ERROR(NOTHING_FOUND, "no audio files found"), \
 
 
index 123425b..7bf3402 100644 (file)
@@ -40,10 +40,11 @@ static int count_audio_files(__a_unused const char *dir, __a_unused const char *
 
 static int remember_file(const char *dir, const char *name)
 {
-       if (audio_file_count >= num_audio_files)
-               return -E_FILE_COUNT;
-       audio_file_list[audio_file_count] = make_message("%s/%s", dir, name);
-       audio_file_count++;
+       if (audio_file_count < num_audio_files) {
+               audio_file_list[audio_file_count] =
+                       make_message("%s/%s", dir, name);
+               audio_file_count++;
+       }
        return 1;
 }