* To my surprise, XFS doesn't support dt_type in readdir results, so we need to stat each entry of type DT_UNKNOWN.

This commit is contained in:
Justin Maggard
2009-06-04 22:32:10 +00:00
parent 41a6830952
commit a295b448ba
5 changed files with 128 additions and 84 deletions

View File

@ -44,39 +44,6 @@ struct virtual_item
char name[256];
};
int
is_video(const char * file)
{
return (ends_with(file, ".mpg") || ends_with(file, ".mpeg") ||
ends_with(file, ".avi") || ends_with(file, ".divx") ||
ends_with(file, ".asf") || ends_with(file, ".wmv") ||
ends_with(file, ".mp4") || ends_with(file, ".m4v") ||
ends_with(file, ".mts") || ends_with(file, ".m2ts") ||
ends_with(file, ".m2t") || ends_with(file, ".mkv") ||
ends_with(file, ".vob") || ends_with(file, ".ts") ||
#ifdef TIVO_SUPPORT
ends_with(file, ".TiVo") ||
#endif
ends_with(file, ".flv") || ends_with(file, ".xvid"));
}
int
is_audio(const char * file)
{
return (ends_with(file, ".mp3") || ends_with(file, ".flac") ||
ends_with(file, ".wma") || ends_with(file, ".asf") ||
ends_with(file, ".fla") || ends_with(file, ".flc") ||
ends_with(file, ".m4a") || ends_with(file, ".aac") ||
ends_with(file, ".mp4") || ends_with(file, ".m4p") ||
ends_with(file, ".wav"));
}
int
is_image(const char * file)
{
return (ends_with(file, ".jpg") || ends_with(file, ".jpeg"));
}
sqlite_int64
get_next_available_id(const char * table, const char * parentID)
{
@ -755,51 +722,6 @@ filter_media(const struct dirent *d)
) ));
}
#define TYPE_OTHER 0
#define TYPE_DIR 1
#define TYPE_FILE 2
unsigned char
resolve_unknown_type(const char * path, enum media_types dir_type)
{
struct stat entry;
unsigned char type = TYPE_OTHER;
if( stat(path, &entry) == 0 )
{
if( S_ISDIR(entry.st_mode) )
{
type = TYPE_DIR;
}
else if( S_ISREG(entry.st_mode) )
{
switch( dir_type )
{
case ALL_MEDIA:
if( is_image(path) ||
is_audio(path) ||
is_video(path) )
type = TYPE_FILE;
break;
case AUDIO_ONLY:
if( is_audio(path) )
type = TYPE_FILE;
break;
case VIDEO_ONLY:
if( is_video(path) )
type = TYPE_FILE;
break;
case IMAGES_ONLY:
if( is_image(path) )
type = TYPE_FILE;
break;
default:
break;
}
}
}
return type;
}
void
ScanDirectory(const char * dir, const char * parent, enum media_types dir_type)
{
@ -809,7 +731,7 @@ ScanDirectory(const char * dir, const char * parent, enum media_types dir_type)
char full_path[PATH_MAX];
char * name = NULL;
static long long unsigned int fileno = 0;
unsigned char type;
enum file_types type;
setlocale(LC_COLLATE, "");
if( chdir(dir) != 0 )
@ -846,7 +768,7 @@ ScanDirectory(const char * dir, const char * parent, enum media_types dir_type)
for (i=0; i < n; i++)
{
type = 0;
type = TYPE_UNKNOWN;
sprintf(full_path, "%s/%s", dir, namelist[i]->d_name);
name = escape_tag(namelist[i]->d_name);
if( namelist[i]->d_type == DT_DIR )