summaryrefslogtreecommitdiffabout
path: root/libetpan/src/low-level/maildir/maildir.c
Unidiff
Diffstat (limited to 'libetpan/src/low-level/maildir/maildir.c') (more/less context) (show whitespace changes)
-rw-r--r--libetpan/src/low-level/maildir/maildir.c15
1 files changed, 14 insertions, 1 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
@@ -107,24 +107,37 @@ static char * maildir_get_new_message_filename(struct maildir * md,
107 char * tmpfile) 107 char * tmpfile)
108{ 108{
109 char filename[PATH_MAX]; 109 char filename[PATH_MAX];
110 char basename[PATH_MAX]; 110 char basename[PATH_MAX];
111 int k; 111 int k;
112 time_t now; 112 time_t now;
113 //LR
114 struct stat f_stat;
113 int got_file; 115 int got_file;
114 int r; 116 int r;
115 117
116 got_file = 0; 118 got_file = 0;
117 now = time(NULL); 119 now = time(NULL);
118 k = 0; 120 k = 0;
119 while (k < MAX_TRY_ALLOC) { 121 while (k < MAX_TRY_ALLOC) {
120 snprintf(basename, sizeof(basename), "%lu.%u_%u.%s", 122 snprintf(basename, sizeof(basename), "%lu.%u_%u.%s",
121 (unsigned long) now, md->mdir_pid, md->mdir_counter, md->mdir_hostname); 123 (unsigned long) now, md->mdir_pid, md->mdir_counter, md->mdir_hostname);
122 snprintf(filename, sizeof(filename), "%s/tmp/%s", 124 snprintf(filename, sizeof(filename), "%s/tmp/%s",
123 md->mdir_path, basename); 125 md->mdir_path, basename);
124 126
127 // LR changed following lines
128 if ( stat( filename, &f_stat ) == -1 ) {
129 char * dup_filename;
130
131 dup_filename = strdup(filename);
132 if (dup_filename == NULL) {
133 //unlink(filename);
134 return NULL;
135 }
136 rename (tmpfile,dup_filename );
137#if 0
125 if (link(tmpfile, filename) == 0) { 138 if (link(tmpfile, filename) == 0) {
126 got_file = 1; 139 got_file = 1;
127 unlink(tmpfile); 140 unlink(tmpfile);
128 } 141 }
129 else if (errno == EXDEV) { 142 else if (errno == EXDEV) {
130 unlink(tmpfile); 143 unlink(tmpfile);
@@ -144,13 +157,13 @@ static char * maildir_get_new_message_filename(struct maildir * md,
144 157
145 dup_filename = strdup(filename); 158 dup_filename = strdup(filename);
146 if (dup_filename == NULL) { 159 if (dup_filename == NULL) {
147 unlink(filename); 160 unlink(filename);
148 return NULL; 161 return NULL;
149 } 162 }
150 163#endif
151 md->mdir_counter ++; 164 md->mdir_counter ++;
152 165
153 return dup_filename; 166 return dup_filename;
154 } 167 }
155 168
156 md->mdir_counter ++; 169 md->mdir_counter ++;