commit 47aae751c0efa08b82093efa810177dfc69c2331
parent d47c710063147ca90dfa07cae7cc284398cc5115
Author: Jaromil <jaromil@dyne.org>
Date: Wed, 29 Aug 2012 11:07:21 +0200
added rename() option to mairix to speedup backup function
Diffstat:
5 files changed, 18 insertions(+), 65 deletions(-)
diff --git a/src/fetchdate.c b/src/fetchdate.c
@@ -27,6 +27,7 @@
int verbose = 0;
int do_hardlinks = 0;
+int do_movefiles = 0;
char dateformat[256];
void out_of_mem(char *file, int line, size_t size);
diff --git a/src/mairix/mairix.c b/src/mairix/mairix.c
@@ -41,6 +41,7 @@ int total_bytes=0;
int verbose = 0;
int do_hardlinks = 0;
+int do_movefiles = 0;
static char *folder_base = NULL;
static char *maildir_folders = NULL;
@@ -417,6 +418,7 @@ static void usage(void)/*{{{*/
"-o <mfolder> : override setting of mfolder from mairixrc file\n"
"-r : force raw output regardless of mformat setting in mairixrc file\n"
"-H : force hard links rather than symbolic ones\n"
+ "-M : force moving files between maildirs, deleting originals\n"
"expr_i : search expression (all expr's AND'ed together):\n"
" word : match word in message body and major headers\n"
" t:word : match word in To: header\n"
@@ -532,6 +534,8 @@ int main (int argc, char **argv)/*{{{*/
do_excerpt_output = 1;
} else if (!strcmp(*argv, "-H") || !strcmp(*argv, "--force-hardlinks")) {
do_hardlinks = 1;
+ } else if (!strcmp(*argv, "-M") || !strcmp(*argv, "--force-move")) {
+ do_movefiles = 1;
} else if (!strcmp(*argv, "-Q") || !strcmp(*argv, "--no-integrity-checks")) {
do_integrity_checks = 0;
} else if (!strcmp(*argv, "--unlock")) {
diff --git a/src/mairix/mairix.h b/src/mairix/mairix.h
@@ -285,6 +285,7 @@ extern struct traverse_methods mbox_traverse_methods;
extern int verbose; /* cmd line -v switch */
extern int do_hardlinks; /* cmd line -H switch */
+extern int do_movefiles; /* cmd line -M switch */
/* Lame fix for systems where NAME_MAX isn't defined after including the above
* set of .h files (Solaris, FreeBSD so far). Probably grossly oversized but
diff --git a/src/mairix/search.c b/src/mairix/search.c
@@ -291,51 +291,6 @@ static void match_substring_in_table(struct read_db *db, struct toktable_db *tt,
if (nr) free(nr);
}
/*}}}*/
-static void match_substring_in_table2(struct read_db *db, struct toktable2_db *tt, char *substring, int max_errors, int left_anchor, char *hits)/*{{{*/
-{
-
- int i, got_hit;
- unsigned long a[256];
- unsigned long *r=NULL, *nr=NULL;
- unsigned long hit;
- char *token;
-
- build_match_vector(substring, a, &hit);
-
- got_hit = 0;
- if (max_errors > 3) {
- r = new_array(unsigned long, 1 + max_errors);
- nr = new_array(unsigned long, 1 + max_errors);
- }
- for (i=0; i<tt->n; i++) {
- token = db->data + tt->tok_offsets[i];
- switch (max_errors) {
- /* Optimise common cases for few errors to allow optimizer to keep bitmaps
- * in registers */
- case 0:
- got_hit = substring_match_0(a, hit, left_anchor, token);
- break;
- case 1:
- got_hit = substring_match_1(a, hit, left_anchor, token);
- break;
- case 2:
- got_hit = substring_match_2(a, hit, left_anchor, token);
- break;
- case 3:
- got_hit = substring_match_3(a, hit, left_anchor, token);
- break;
- default:
- got_hit = substring_match_general(a, hit, left_anchor, token, max_errors, r, nr);
- break;
- }
- if (got_hit) {
- mark_hits_in_table2(db, tt, i, hits);
- }
- }
- if (r) free(r);
- if (nr) free(nr);
-}
-/*}}}*/
static void match_substring_in_paths(struct read_db *db, char *substring, int max_errors, int left_anchor, char *hits)/*{{{*/
{
@@ -656,7 +611,16 @@ static int looks_like_maildir_new_p(const char *p)/*{{{*/
/*}}}*/
static void create_symlink(char *link_target, char *new_link)/*{{{*/
{
- if ((!do_hardlinks && symlink(link_target, new_link) < 0) || link(link_target, new_link)) {
+ // added possibility to move files (delete origin)
+ if (do_movefiles>0) {
+ if( rename(link_target, new_link) != 0) {
+ if (verbose) {
+ perror("rename");
+ fprintf(stderr, "Failed rename <%s> -> <%s>\n", link_target, new_link);
+ }
+ }
+
+ } else if ((!do_hardlinks && symlink(link_target, new_link) < 0) || link(link_target, new_link)) {
if (verbose) {
perror("symlink");
fprintf(stderr, "Failed path <%s> -> <%s>\n", link_target, new_link);
@@ -929,7 +893,6 @@ static int do_search(struct read_db *db, char **args, char *output_path, int sho
char *andsep;
char *word, *orig_word, *lower_word;
char *equal;
- char *p;
int negate;
int had_orsep;
int max_errors;
diff --git a/src/zlibs/search b/src/zlibs/search
@@ -255,27 +255,11 @@ maildir=${folders}
mfolder=$dst
mformat=maildir
EOF
- found=`mairix -F -f ${mairixrc} -H ${expr} 2>/dev/null | awk '{print $2}'`
+ found=`mairix -F -f ${mairixrc} -t -M ${expr} 2>/dev/null | awk '{print $2}'`
notice "$found matches found, destination folder size is `du -hs $basedir/$dst | awk '{print $1}'`"
${=rm} ${mairixrc}
${=rm} ${mairixdb}
- # invert the order of folders to start with destination in rmdupes
- typeset -al revfold
- c=$(( ${#fold} ))
- while [ $c -gt 0 ]; do
- func "${fold[$c]}"
- revfold+=(${fold[$c]})
- c=$(( $c - 1 ))
- done
-
- formail_cache=$TMPDIR/filter.rmdupes.$datestamp.$RANDOM
- newlock $formail_cache
-
- rmdupes ${=revfold}
-
- unlink $formail_cache
-
- notice "Backup completed to destination: $dst"
+ act "Backup completed to destination: $dst"
}