From c79dc8abf78c71ee0171f8c3734f74a904dff518 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Wed, 8 Feb 2017 15:05:19 +1100 Subject: [PATCH] util/disk_cache: use stat() to check if entry is a directory d_type is not supported on all systems. --- src/util/disk_cache.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c index a70bd66..1f48cef 100644 --- a/src/util/disk_cache.c +++ b/src/util/disk_cache.c @@ -501,12 +501,13 @@ choose_random_file_matching(const char *dir_path, static bool is_regular_non_tmp_file(struct dirent *entry) { - size_t len; + struct stat sb; + stat(entry->d_name, &sb); - if (entry->d_type != DT_REG) + if (!S_ISREG(sb.st_mode)) return false; - len = strlen (entry->d_name); + size_t len = strlen (entry->d_name); if (len >= 4 && strcmp(&entry->d_name[len-4], ".tmp") == 0) return false; @@ -542,7 +543,10 @@ unlink_random_file_from_directory(const char *path) static bool is_two_character_sub_directory(struct dirent *entry) { - if (entry->d_type != DT_DIR) + struct stat sb; + stat(entry->d_name, &sb); + + if (!S_ISDIR(sb.st_mode)) return false; if (strlen(entry->d_name) != 2) -- 2.9.3