Mercurial > geeqie.yaz
comparison src/filedata.c @ 779:8b21337bc47b
filelist_read_real(): optimize and clean up.
author | zas_ |
---|---|
date | Tue, 03 Jun 2008 09:41:00 +0000 |
parents | 4acde7a0bb01 |
children | 44128da39e13 |
comparison
equal
deleted
inserted
replaced
778:21ec5e6d3ddf | 779:8b21337bc47b |
---|---|
618 | 618 |
619 static gint filelist_read_real(const gchar *path, GList **files, GList **dirs, gint follow_symlinks) | 619 static gint filelist_read_real(const gchar *path, GList **files, GList **dirs, gint follow_symlinks) |
620 { | 620 { |
621 DIR *dp; | 621 DIR *dp; |
622 struct dirent *dir; | 622 struct dirent *dir; |
623 struct stat ent_sbuf; | |
624 gchar *pathl; | 623 gchar *pathl; |
625 GList *dlist; | 624 GList *dlist = NULL; |
626 GList *flist; | 625 GList *flist = NULL; |
627 | 626 int (*stat_func)(const char *path, struct stat *buf); |
628 dlist = NULL; | 627 |
629 flist = NULL; | 628 g_assert(files || dirs); |
629 | |
630 if (files) *files = NULL; | |
631 if (dirs) *dirs = NULL; | |
630 | 632 |
631 pathl = path_from_utf8(path); | 633 pathl = path_from_utf8(path); |
632 if (!pathl || (dp = opendir(pathl)) == NULL) | 634 if (!pathl) return FALSE; |
635 | |
636 dp = opendir(pathl); | |
637 if (dp == NULL) | |
633 { | 638 { |
634 g_free(pathl); | 639 g_free(pathl); |
635 if (files) *files = NULL; | |
636 if (dirs) *dirs = NULL; | |
637 return FALSE; | 640 return FALSE; |
638 } | 641 } |
639 | 642 |
643 if (follow_symlinks) | |
644 stat_func = stat; | |
645 else | |
646 stat_func = lstat; | |
647 | |
640 while ((dir = readdir(dp)) != NULL) | 648 while ((dir = readdir(dp)) != NULL) |
641 { | 649 { |
642 gchar *name = dir->d_name; | 650 struct stat ent_sbuf; |
643 if (options->file_filter.show_hidden_files || !ishidden(name)) | 651 const gchar *name = dir->d_name; |
652 gchar *filepath; | |
653 | |
654 if (!options->file_filter.show_hidden_files && ishidden(name)) | |
655 continue; | |
656 | |
657 filepath = g_build_filename(pathl, name, NULL); | |
658 if (stat_func(filepath, &ent_sbuf) >= 0) | |
644 { | 659 { |
645 gchar *filepath = g_build_filename(pathl, name, NULL); | 660 if (S_ISDIR(ent_sbuf.st_mode)) |
646 if ((follow_symlinks ? | |
647 stat(filepath, &ent_sbuf) : | |
648 lstat(filepath, &ent_sbuf)) >= 0) | |
649 { | 661 { |
650 if (S_ISDIR(ent_sbuf.st_mode)) | 662 /* we ignore the .thumbnails dir for cleanliness */ |
663 if (dirs && | |
664 !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) && | |
665 strcmp(name, GQ_CACHE_LOCAL_THUMB) != 0 && | |
666 strcmp(name, GQ_CACHE_LOCAL_METADATA) != 0 && | |
667 strcmp(name, THUMB_FOLDER_LOCAL) != 0) | |
651 { | 668 { |
652 /* we ignore the .thumbnails dir for cleanliness */ | 669 dlist = g_list_prepend(dlist, file_data_new_local(filepath, &ent_sbuf, FALSE)); |
653 if ((dirs) && | |
654 !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) && | |
655 strcmp(name, GQ_CACHE_LOCAL_THUMB) != 0 && | |
656 strcmp(name, GQ_CACHE_LOCAL_METADATA) != 0 && | |
657 strcmp(name, THUMB_FOLDER_LOCAL) != 0) | |
658 { | |
659 dlist = g_list_prepend(dlist, file_data_new_local(filepath, &ent_sbuf, FALSE)); | |
660 } | |
661 } | |
662 else | |
663 { | |
664 if ((files) && filter_name_exists(name)) | |
665 { | |
666 flist = g_list_prepend(flist, file_data_new_local(filepath, &ent_sbuf, TRUE)); | |
667 } | |
668 } | 670 } |
669 } | 671 } |
670 g_free(filepath); | 672 else |
673 { | |
674 if (files && filter_name_exists(name)) | |
675 { | |
676 flist = g_list_prepend(flist, file_data_new_local(filepath, &ent_sbuf, TRUE)); | |
677 } | |
678 } | |
671 } | 679 } |
680 g_free(filepath); | |
672 } | 681 } |
673 | 682 |
674 closedir(dp); | 683 closedir(dp); |
675 | 684 |
676 g_free(pathl); | 685 g_free(pathl); |
677 | 686 |
678 flist = filelist_filter_out_sidecars(flist); | |
679 | |
680 if (dirs) *dirs = dlist; | 687 if (dirs) *dirs = dlist; |
681 if (files) *files = flist; | 688 if (files) *files = filelist_filter_out_sidecars(flist); |
682 | 689 |
683 return TRUE; | 690 return TRUE; |
684 } | 691 } |
685 | 692 |
686 gint filelist_read(const gchar *path, GList **files, GList **dirs) | 693 gint filelist_read(const gchar *path, GList **files, GList **dirs) |