2 /* Command to manually force a compression/dump of an index file */
16 #include <sys/types.h>
18 #include "camel-list-utils.h"
19 #include "camel-object.h"
20 #include "camel-text-index.h"
22 extern gint camel_init (const gchar *certdb_dir, gboolean nss_init);
24 G_GNUC_NORETURN static void
25 do_usage (gchar *argv0)
27 fprintf(stderr, "Usage: %s [ compress | dump | info ] file(s) ...\n", argv0);
28 fprintf(stderr, " compress - compress (an) index file(s)\n");
29 fprintf(stderr, " dump - dump (an) index file's content to stdout\n");
30 fprintf(stderr, " info - dump summary info to stdout\n");
35 do_compress (gint argc,
41 for (i = 2; i < argc; i++) {
42 printf("Opening index file: %s\n", argv[i]);
43 idx = (CamelIndex *) camel_text_index_new (argv[i], O_RDWR);
45 printf(" Compressing ...\n");
46 if (camel_index_compress (idx) == -1) {
52 printf(" Failed: %s\n", g_strerror (errno));
66 for (i = 2; i < argc; i++) {
67 printf("Opening index file: %s\n", argv[i]);
68 idx = (CamelIndex *) camel_text_index_new (argv[i], O_RDONLY);
70 printf(" Dumping ...\n");
71 camel_text_index_dump ((CamelTextIndex *) idx);
74 printf(" Failed: %s\n", g_strerror (errno));
88 for (i = 2; i < argc; i++) {
89 printf("Opening index file: %s\n", argv[i]);
90 idx = (CamelIndex *) camel_text_index_new (argv[i], O_RDONLY);
92 camel_text_index_info ((CamelTextIndex *) idx);
95 printf(" Failed: %s\n", g_strerror (errno));
109 for (i = 2; i < argc; i++) {
110 printf("Opening index file: %s\n", argv[i]);
111 idx = (CamelIndex *) camel_text_index_new (argv[i], O_RDONLY);
113 camel_text_index_validate ((CamelTextIndex *) idx);
114 g_object_unref (idx);
116 printf(" Failed: %s\n", g_strerror (errno));
123 static gint do_perf (gint argc, gchar **argv);
125 gint main (gint argc, gchar **argv)
130 camel_init (NULL, 0);
132 if (!strcmp(argv[1], "compress"))
133 return do_compress (argc, argv);
134 else if (!strcmp(argv[1], "dump"))
135 return do_dump (argc, argv);
136 else if (!strcmp(argv[1], "info"))
137 return do_info (argc, argv);
138 else if (!strcmp(argv[1], "check"))
139 return do_check (argc, argv);
140 else if (!strcmp(argv[1], "perf"))
141 return do_perf (argc, argv);
148 #include "camel-stream-null.h"
149 #include "camel-stream-filter.h"
150 #include "camel-mime-filter-index.h"
151 #include "camel-stream-fs.h"
159 const gchar *path = "/home/notzed/evolution/local/Inbox/mbox/cur";
161 CamelStream *null, *filter, *stream;
162 CamelMimeFilter *filter_index;
166 dir = opendir (path);
172 idx = (CamelIndex *) camel_text_index_new (
173 "/tmp/index", O_TRUNC|O_CREAT|O_RDWR);
175 perror("open index");
180 null = camel_stream_null_new ();
181 filter = camel_stream_filter_new (null);
182 g_object_unref (null);
183 filter_index = camel_mime_filter_index_new (idx);
184 camel_stream_filter_add ((CamelStreamFilter *) filter, filter_index);
186 while ((d = readdir (dir))) {
187 printf("indexing '%s'\n", d->d_name);
189 idn = camel_index_add_name (idx, d->d_name);
190 camel_mime_filter_index_set_name (
191 CAMEL_MIME_FILTER_INDEX (filter_index), idn);
192 name = g_strdup_printf("%s/%s", path, d->d_name);
193 stream = camel_stream_fs_new_with_name (name, O_RDONLY, 0, NULL);
194 camel_stream_write_to_stream (stream, filter, NULL, NULL);
195 g_object_unref (stream);
198 camel_index_write_name (idx, idn);
199 g_object_unref (idn);
200 camel_mime_filter_index_set_name (
201 CAMEL_MIME_FILTER_INDEX (filter_index), NULL);
206 camel_index_sync (idx);
207 g_object_unref (idx);
209 g_object_unref (filter);
210 g_object_unref (filter_index);