From 00c4b870186ea76be34858452c3400136cd6f78d Mon Sep 17 00:00:00 2001 From: Andre Date: Tue, 12 Sep 2006 00:57:10 +0200 Subject: [PATCH] robustness fixes for the random selector - 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 | 5 +++-- error.h | 1 - random_selector.c | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/db.c b/db.c index 9db622bc..8b066726 100644 --- 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 0f83398e..cb5e2b02 100644 --- 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"), \ diff --git a/random_selector.c b/random_selector.c index 123425b0..7bf34026 100644 --- a/random_selector.c +++ b/random_selector.c @@ -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; } -- 2.39.5