dirscan.c (mairix-0.23) | : | dirscan.c (mairix-0.24) | ||
---|---|---|---|---|
skipping to change at line 38 | skipping to change at line 38 | |||
#include <unistd.h> | #include <unistd.h> | |||
#include <dirent.h> | #include <dirent.h> | |||
#include <assert.h> | #include <assert.h> | |||
#include "mairix.h" | #include "mairix.h" | |||
struct msgpath_array *new_msgpath_array(void)/*{{{*/ | struct msgpath_array *new_msgpath_array(void)/*{{{*/ | |||
{ | { | |||
struct msgpath_array *result; | struct msgpath_array *result; | |||
result = new(struct msgpath_array); | result = new(struct msgpath_array); | |||
result->paths = NULL; | result->paths = NULL; | |||
result->type = NULL; | ||||
result->n = 0; | result->n = 0; | |||
result->max = 0; | result->max = 0; | |||
return result; | return result; | |||
} | } | |||
/*}}}*/ | /*}}}*/ | |||
void free_msgpath_array(struct msgpath_array *x)/*{{{*/ | void free_msgpath_array(struct msgpath_array *x)/*{{{*/ | |||
{ | { | |||
int i; | int i; | |||
if (x->paths) { | if (x->paths) { | |||
for (i=0; i<x->n; i++) { | for (i=0; i<x->n; i++) { | |||
switch (x->type[i]) { | switch (x->paths[i].type) { | |||
case MTY_FILE: | case MTY_FILE: | |||
case MTY_IMAP: | ||||
free(x->paths[i].src.mpf.path); | free(x->paths[i].src.mpf.path); | |||
break; | break; | |||
case MTY_MBOX: | case MTY_MBOX: | |||
break; | break; | |||
case MTY_DEAD: | case MTY_DEAD: | |||
break; | break; | |||
} | } | |||
} | } | |||
free(x->type); | ||||
free(x->paths); | free(x->paths); | |||
} | } | |||
free(x); | free(x); | |||
} | } | |||
/*}}}*/ | /*}}}*/ | |||
static void add_file_to_list(char *x, struct msgpath_array *arr) {/*{{{*/ | static void add_file_to_list(char *x, struct msgpath_array *arr, enum folder_typ e ft) {/*{{{*/ | |||
char *y = new_string(x); | char *y = new_string(x); | |||
if (arr->n == arr->max) { | if (arr->n == arr->max) { | |||
arr->max += 1024; | arr->max += 1024; | |||
arr->paths = grow_array(struct msgpath, arr->max, arr->paths); | arr->paths = grow_array(struct msgpath, arr->max, arr->paths); | |||
arr->type = grow_array(enum message_type, arr->max, arr->type); | ||||
} | } | |||
arr->type[arr->n] = MTY_FILE; | arr->paths[arr->n].type = MTY_FILE; | |||
arr->paths[arr->n].src.mpf.path = y; | arr->paths[arr->n].src.mpf.path = y; | |||
arr->paths[arr->n].source_ft = ft; | ||||
++arr->n; | ++arr->n; | |||
return; | return; | |||
} | } | |||
/*}}}*/ | /*}}}*/ | |||
static void get_maildir_message_paths(char *folder, struct msgpath_array *arr)/* {{{*/ | static void get_maildir_message_paths(char *folder, struct msgpath_array *arr)/* {{{*/ | |||
{ | { | |||
char *subdir, *fname; | char *subdir, *fname; | |||
int i; | int i; | |||
static char *subdirs[] = {"new", "cur"}; | static char *subdirs[] = {"new", "cur"}; | |||
DIR *d; | DIR *d; | |||
skipping to change at line 107 | skipping to change at line 106 | |||
while ((de = readdir(d))) { | while ((de = readdir(d))) { | |||
/* TODO : Perhaps we ought to do some validation on the path here? | /* TODO : Perhaps we ought to do some validation on the path here? | |||
i.e. check that the filename looks valid for a maildir message. */ | i.e. check that the filename looks valid for a maildir message. */ | |||
if (!strcmp(de->d_name, ".") || | if (!strcmp(de->d_name, ".") || | |||
!strcmp(de->d_name, "..")) { | !strcmp(de->d_name, "..")) { | |||
continue; | continue; | |||
} | } | |||
strcpy(fname, subdir); | strcpy(fname, subdir); | |||
strcat(fname, "/"); | strcat(fname, "/"); | |||
strcat(fname, de->d_name); | strcat(fname, de->d_name); | |||
add_file_to_list(fname, arr); | add_file_to_list(fname, arr, FT_MAILDIR); | |||
} | } | |||
closedir(d); | closedir(d); | |||
} | } | |||
} | } | |||
free(subdir); | free(subdir); | |||
free(fname); | free(fname); | |||
return; | return; | |||
} | } | |||
/*}}}*/ | /*}}}*/ | |||
int valid_mh_filename_p(const char *x)/*{{{*/ | int valid_mh_filename_p(const char *x)/*{{{*/ | |||
skipping to change at line 154 | skipping to change at line 153 | |||
if (d) { | if (d) { | |||
while ((de = readdir(d))) { | while ((de = readdir(d))) { | |||
if (!strcmp(de->d_name, ".") || | if (!strcmp(de->d_name, ".") || | |||
!strcmp(de->d_name, "..")) { | !strcmp(de->d_name, "..")) { | |||
continue; | continue; | |||
} | } | |||
strcpy(fname, folder); | strcpy(fname, folder); | |||
strcat(fname, "/"); | strcat(fname, "/"); | |||
strcat(fname, de->d_name); | strcat(fname, de->d_name); | |||
if (valid_mh_filename_p(de->d_name)) { | if (valid_mh_filename_p(de->d_name)) { | |||
add_file_to_list(fname, arr); | add_file_to_list(fname, arr, FT_MH); | |||
} | } | |||
} | } | |||
closedir(d); | closedir(d); | |||
} | } | |||
free(fname); | free(fname); | |||
return; | return; | |||
} | } | |||
/*}}}*/ | /*}}}*/ | |||
static int child_stat(const char *base, const char *child, struct stat *sb)/*{{{ */ | static int child_stat(const char *base, const char *child, struct stat *sb)/*{{{ */ | |||
{ | { | |||
skipping to change at line 354 | skipping to change at line 353 | |||
closedir(d); | closedir(d); | |||
} | } | |||
free(fname); | free(fname); | |||
free(sname); | free(sname); | |||
free(name); | free(name); | |||
return; | return; | |||
} | } | |||
/*}}}*/ | /*}}}*/ | |||
#endif | #endif | |||
static int message_compare(const void *a, const void *b)/*{{{*/ | ||||
{ | ||||
/* FIXME : Is this a sensible way to do this with mbox messages in the picture | ||||
? */ | ||||
struct msgpath *aa = (struct msgpath *) a; | ||||
struct msgpath *bb = (struct msgpath *) b; | ||||
/* This should only get called on 'file' type messages - TBC! */ | ||||
return strcmp(aa->src.mpf.path, bb->src.mpf.path); | ||||
} | ||||
/*}}}*/ | ||||
static void sort_message_list(struct msgpath_array *arr)/*{{{*/ | ||||
{ | ||||
qsort(arr->paths, arr->n, sizeof(struct msgpath), message_compare); | ||||
} | ||||
/*}}}*/ | ||||
/*{{{ void build_message_list */ | /*{{{ void build_message_list */ | |||
void build_message_list(char *folder_base, char *folders, enum folder_type ft, | void build_message_list(char *folder_base, char *folders, enum folder_type ft, | |||
struct msgpath_array *msgs, | struct msgpath_array *msgs, | |||
struct globber_array *omit_globs) | struct globber_array *omit_globs) | |||
{ | { | |||
char **raw_paths, **paths; | char **raw_paths, **paths; | |||
int n_raw_paths, n_paths, i; | int n_raw_paths, n_paths, i; | |||
split_on_colons(folders, &n_raw_paths, &raw_paths); | split_on_colons(folders, &n_raw_paths, &raw_paths); | |||
switch (ft) { | switch (ft) { | |||
skipping to change at line 397 | skipping to change at line 382 | |||
get_mh_message_paths(paths[i], msgs); | get_mh_message_paths(paths[i], msgs); | |||
} | } | |||
break; | break; | |||
default: | default: | |||
assert(0); | assert(0); | |||
break; | break; | |||
} | } | |||
if (paths) free(paths); | if (paths) free(paths); | |||
sort_message_list(msgs); | ||||
return; | return; | |||
} | } | |||
/*}}}*/ | /*}}}*/ | |||
#ifdef TEST | #ifdef TEST | |||
int main (int argc, char **argv) | int main (int argc, char **argv) | |||
{ | { | |||
int i; | int i; | |||
struct msgpath_array *arr; | struct msgpath_array *arr; | |||
End of changes. 12 change blocks. | ||||
24 lines changed or deleted | 7 lines changed or added |