From 87c8be4a08b4864f0df588c80bc90586f5e512a0 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Thu, 23 Dec 2010 19:02:18 +0000 Subject: RaaA: Improve tagcache search to make the database built. First, it add the ability to tagcache to walk through multiple search roots. Second, it adds symlinks targets to the search roots if they're are not inside any of the current search roots, otherwise the symlink is ignored (unless it's a file). The default search root is still /, so no search root will be actually added. But the tagcache now isn't trapped by recursive symlinks anymore and successfully builds, and it's prepared for a future music directory setting. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28884 a1c6a512-1295-4272-9138-f99709370657 --- uisimulator/common/io.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'uisimulator/common/io.c') diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index fe7bad438f..56abf4b6ad 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c @@ -28,6 +28,7 @@ #include "config.h" #define HAVE_STATVFS (!defined(WIN32)) +#define HAVE_LSTAT (!defined(WIN32)) #if HAVE_STATVFS #include @@ -314,7 +315,7 @@ struct sim_dirent *sim_readdir(MYDIR *dir) static struct sim_dirent secret; STAT_T s; DIRENT_T *x11 = READDIR(dir->dir); - struct tm* tm; + struct tm tm; if(!x11) return (struct sim_dirent *)0; @@ -324,20 +325,35 @@ struct sim_dirent *sim_readdir(MYDIR *dir) /* build file name */ snprintf(buffer, sizeof(buffer), "%s/%s", get_sim_pathname(dir->name), secret.d_name); - STAT(buffer, &s); /* get info */ + if (STAT(buffer, &s)) /* get info */ + return NULL; #define ATTR_DIRECTORY 0x10 - secret.info.attribute = S_ISDIR(s.st_mode)?ATTR_DIRECTORY:0; + secret.info.attribute = 0; + + if (S_ISDIR(s.st_mode)) + secret.info.attribute = ATTR_DIRECTORY; + secret.info.size = s.st_size; + + if (localtime_r(&(s.st_mtime), &tm) == NULL) + return NULL; + secret.info.wrtdate = ((tm.tm_year - 80) << 9) | + ((tm.tm_mon + 1) << 5) | + tm.tm_mday; + secret.info.wrttime = (tm.tm_hour << 11) | + (tm.tm_min << 5) | + (tm.tm_sec >> 1); + +#ifdef HAVE_LSTAT +#define ATTR_LINK 0x80 + if (!lstat(buffer, &s) && S_ISLNK(s.st_mode)) + { + secret.info.attribute |= ATTR_LINK; + } +#endif - tm = localtime(&(s.st_mtime)); - secret.info.wrtdate = ((tm->tm_year - 80) << 9) | - ((tm->tm_mon + 1) << 5) | - tm->tm_mday; - secret.info.wrttime = (tm->tm_hour << 11) | - (tm->tm_min << 5) | - (tm->tm_sec >> 1); return &secret; } -- cgit v1.2.3