Avoid false warnings of full dirs when the number of visible entries in a dir equals the limit.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29823 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Magnus Holmgren 2011-05-04 18:33:12 +00:00
parent ffee0b5e94
commit c2ff646b78
2 changed files with 13 additions and 13 deletions

View file

@ -267,8 +267,9 @@ static int compare(const void* p1, const void* p2)
/* load and sort directory into dircache. returns NULL on failure. */ /* load and sort directory into dircache. returns NULL on failure. */
int ft_load(struct tree_context* c, const char* tempdir) int ft_load(struct tree_context* c, const char* tempdir)
{ {
int i; int files_in_dir = 0;
int name_buffer_used = 0; int name_buffer_used = 0;
struct dirent *entry;
bool (*callback_show_item)(char *, int, struct tree_context *) = NULL; bool (*callback_show_item)(char *, int, struct tree_context *) = NULL;
DIR *dir; DIR *dir;
@ -285,12 +286,11 @@ int ft_load(struct tree_context* c, const char* tempdir)
c->dirsindir = 0; c->dirsindir = 0;
c->dirfull = false; c->dirfull = false;
for ( i=0; i < c->dircache_count; i++ ) { while ((entry = readdir(dir))) {
int len; int len;
struct dirent *entry = readdir(dir);
struct dirinfo info; struct dirinfo info;
struct entry* dptr = struct entry* dptr =
(struct entry*)(c->dircache + i * sizeof(struct entry)); (struct entry*)(c->dircache + files_in_dir * sizeof(struct entry));
if (!entry) if (!entry)
break; break;
@ -301,13 +301,11 @@ int ft_load(struct tree_context* c, const char* tempdir)
if ((info.attribute & ATTR_DIRECTORY) && if ((info.attribute & ATTR_DIRECTORY) &&
(((len == 1) && (!strncmp((char *)entry->d_name, ".", 1))) || (((len == 1) && (!strncmp((char *)entry->d_name, ".", 1))) ||
((len == 2) && (!strncmp((char *)entry->d_name, "..", 2))))) { ((len == 2) && (!strncmp((char *)entry->d_name, "..", 2))))) {
i--;
continue; continue;
} }
/* Skip FAT volume ID */ /* Skip FAT volume ID */
if (info.attribute & ATTR_VOLUME_ID) { if (info.attribute & ATTR_VOLUME_ID) {
i--;
continue; continue;
} }
@ -315,7 +313,6 @@ int ft_load(struct tree_context* c, const char* tempdir)
if (*c->dirfilter != SHOW_ALL && if (*c->dirfilter != SHOW_ALL &&
((entry->d_name[0]=='.') || ((entry->d_name[0]=='.') ||
(info.attribute & ATTR_HIDDEN))) { (info.attribute & ATTR_HIDDEN))) {
i--;
continue; continue;
} }
@ -359,15 +356,18 @@ int ft_load(struct tree_context* c, const char* tempdir)
(dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_LUA) || (dptr->attr & FILE_ATTR_MASK) != FILE_ATTR_LUA) ||
(callback_show_item && !callback_show_item(entry->d_name, dptr->attr, c))) (callback_show_item && !callback_show_item(entry->d_name, dptr->attr, c)))
{ {
i--;
continue; continue;
} }
if (len > c->name_buffer_size - name_buffer_used - 1) { if ((len > c->name_buffer_size - name_buffer_used - 1) ||
(files_in_dir >= c->dircache_count)) {
/* Tell the world that we ran out of buffer space */ /* Tell the world that we ran out of buffer space */
c->dirfull = true; c->dirfull = true;
break; break;
} }
++files_in_dir;
dptr->name = &c->name_buffer[name_buffer_used]; dptr->name = &c->name_buffer[name_buffer_used];
dptr->time_write = dptr->time_write =
(long)info.wrtdate<<16 | (long)info.wrtdate<<16 |
@ -378,12 +378,12 @@ int ft_load(struct tree_context* c, const char* tempdir)
if (dptr->attr & ATTR_DIRECTORY) /* count the remaining dirs */ if (dptr->attr & ATTR_DIRECTORY) /* count the remaining dirs */
c->dirsindir++; c->dirsindir++;
} }
c->filesindir = i; c->filesindir = files_in_dir;
c->dirlength = i; c->dirlength = files_in_dir;
closedir(dir); closedir(dir);
compare_sort_dir = c->sort_dir; compare_sort_dir = c->sort_dir;
qsort(c->dircache,i,sizeof(struct entry),compare); qsort(c->dircache, files_in_dir, sizeof(struct entry), compare);
/* If thumbnail talking is enabled, make an extra run to mark files with /* If thumbnail talking is enabled, make an extra run to mark files with
associated thumbnails, so we don't do unsuccessful spinups later. */ associated thumbnails, so we don't do unsuccessful spinups later. */

View file

@ -390,7 +390,7 @@ static int update_dir(void)
#ifdef HAVE_TAGCACHE #ifdef HAVE_TAGCACHE
!id3db && !id3db &&
#endif #endif
(tc.dirfull || tc.filesindir == tc.dircache_count) ) tc.dirfull )
{ {
splash(HZ, ID2P(LANG_SHOWDIR_BUFFER_FULL)); splash(HZ, ID2P(LANG_SHOWDIR_BUFFER_FULL));
} }