00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00031 #include "stdinc.h"
00032
00033 #include "config.h"
00034 #include "vfs.h"
00035 #include "vfs_modules.h"
00036
00037 int
00038 vfs_file_match(struct vfsent *ve, int isdir)
00039 {
00040 return (isdir);
00041 }
00042
00043 FILE *
00044 vfs_file_open(struct vfsent *ve)
00045 {
00046 return fopen(ve->filename, "rb");
00047 }
00048
00049 int
00050 vfs_dir_match(struct vfsent *ve, int isdir)
00051 {
00052 #ifdef S_ISLNK
00053 struct stat fs;
00054 #endif
00055
00056 if (!isdir)
00057 return (-1);
00058
00059 #ifdef S_ISLNK
00060
00061 if (lstat(ve->filename, &fs) != 0)
00062 return (-1);
00063 if (S_ISLNK(fs.st_mode))
00064 ve->recurse = 0;
00065 #endif
00066
00067 return (0);
00068 }
00069
00070 int
00071 vfs_dir_populate(struct vfsent *ve)
00072 {
00073 GDir *dir;
00074 const char *sfn;
00075 struct vfsref *nvr, *svr;
00076 int hide_dotfiles;
00077
00078 hide_dotfiles = config_getopt_bool("vfs.dir.hide_dotfiles");
00079
00080 if ((dir = g_dir_open(ve->filename, 0, NULL)) == NULL)
00081 return (-1);
00082
00083 while ((sfn = g_dir_read_name(dir)) != NULL) {
00084
00085 if (hide_dotfiles && sfn[0] == '.')
00086 continue;
00087
00088 if ((nvr = vfs_lookup(sfn, NULL, ve->filename, 1)) == NULL)
00089 continue;
00090
00091
00092
00093
00094 VFS_LIST_FOREACH(&ve->population, svr) {
00095
00096 if (nvr->ent->vmod->sortorder < svr->ent->vmod->sortorder ||
00097
00098 (nvr->ent->vmod->sortorder == svr->ent->vmod->sortorder &&
00099 strcasecmp(vfs_name(nvr), vfs_name(svr)) < 0)) {
00100 vfs_list_insert_before(&ve->population, nvr, svr);
00101 break;
00102 }
00103 }
00104
00105 if (svr == NULL)
00106 vfs_list_insert_tail(&ve->population, nvr);
00107 }
00108
00109 g_dir_close(dir);
00110
00111 return (0);
00112 }