Diffstat (limited to 'libetpan/src/low-level/maildir') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libetpan/src/low-level/maildir/maildir.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/libetpan/src/low-level/maildir/maildir.c b/libetpan/src/low-level/maildir/maildir.c index 98b9f87..e81625d 100644 --- a/libetpan/src/low-level/maildir/maildir.c +++ b/libetpan/src/low-level/maildir/maildir.c @@ -101,36 +101,49 @@ void maildir_free(struct maildir * md) free(md); } #define MAX_TRY_ALLOC 32 static char * maildir_get_new_message_filename(struct maildir * md, char * tmpfile) { char filename[PATH_MAX]; char basename[PATH_MAX]; int k; time_t now; + //LR + struct stat f_stat; int got_file; int r; got_file = 0; now = time(NULL); k = 0; while (k < MAX_TRY_ALLOC) { snprintf(basename, sizeof(basename), "%lu.%u_%u.%s", (unsigned long) now, md->mdir_pid, md->mdir_counter, md->mdir_hostname); snprintf(filename, sizeof(filename), "%s/tmp/%s", md->mdir_path, basename); - + + // LR changed following lines + if ( stat( filename, &f_stat ) == -1 ) { + char * dup_filename; + + dup_filename = strdup(filename); + if (dup_filename == NULL) { + //unlink(filename); + return NULL; + } + rename (tmpfile,dup_filename ); +#if 0 if (link(tmpfile, filename) == 0) { got_file = 1; unlink(tmpfile); } else if (errno == EXDEV) { unlink(tmpfile); return NULL; } else if (errno == EPERM) { r = rename(tmpfile, filename); if (r < 0) { unlink(tmpfile); @@ -138,25 +151,25 @@ static char * maildir_get_new_message_filename(struct maildir * md, } got_file = 1; } if (got_file) { char * dup_filename; dup_filename = strdup(filename); if (dup_filename == NULL) { unlink(filename); return NULL; } - +#endif md->mdir_counter ++; return dup_filename; } md->mdir_counter ++; k ++; } return NULL; } |