author | zautrix <zautrix> | 2005-03-18 22:05:02 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-18 22:05:02 (UTC) |
commit | 297208a61298fceab6d96bbd1c46198b1c0f7a76 (patch) (unidiff) | |
tree | 50f0c6f775393c1eec15b71691a798d1dacab86d /libetpan/src/low-level/maildir | |
parent | f0232b7801f098b5842e3cd5a1fd804af98ab862 (diff) | |
download | kdepimpi-297208a61298fceab6d96bbd1c46198b1c0f7a76.zip kdepimpi-297208a61298fceab6d96bbd1c46198b1c0f7a76.tar.gz kdepimpi-297208a61298fceab6d96bbd1c46198b1c0f7a76.tar.bz2 |
fixes applied
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 | |||
@@ -65,134 +65,147 @@ struct maildir * maildir_new(const char * path) | |||
65 | 65 | ||
66 | md->mdir_counter = 0; | 66 | md->mdir_counter = 0; |
67 | md->mdir_mtime_new = (time_t) -1; | 67 | md->mdir_mtime_new = (time_t) -1; |
68 | md->mdir_mtime_cur = (time_t) -1; | 68 | md->mdir_mtime_cur = (time_t) -1; |
69 | 69 | ||
70 | md->mdir_pid = getpid(); | 70 | md->mdir_pid = getpid(); |
71 | gethostname(md->mdir_hostname, sizeof(md->mdir_hostname)); | 71 | gethostname(md->mdir_hostname, sizeof(md->mdir_hostname)); |
72 | strncpy(md->mdir_path, path, sizeof(md->mdir_path)); | 72 | strncpy(md->mdir_path, path, sizeof(md->mdir_path)); |
73 | md->mdir_path[PATH_MAX - 1] = '\0'; | 73 | md->mdir_path[PATH_MAX - 1] = '\0'; |
74 | 74 | ||
75 | md->mdir_msg_list = carray_new(128); | 75 | md->mdir_msg_list = carray_new(128); |
76 | if (md->mdir_msg_list == NULL) | 76 | if (md->mdir_msg_list == NULL) |
77 | goto free; | 77 | goto free; |
78 | 78 | ||
79 | md->mdir_msg_hash = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYNONE); | 79 | md->mdir_msg_hash = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYNONE); |
80 | if (md->mdir_msg_hash == NULL) | 80 | if (md->mdir_msg_hash == NULL) |
81 | goto free_msg_list; | 81 | goto free_msg_list; |
82 | 82 | ||
83 | return md; | 83 | return md; |
84 | 84 | ||
85 | free_msg_list: | 85 | free_msg_list: |
86 | carray_free(md->mdir_msg_list); | 86 | carray_free(md->mdir_msg_list); |
87 | free: | 87 | free: |
88 | free(md); | 88 | free(md); |
89 | err: | 89 | err: |
90 | return NULL; | 90 | return NULL; |
91 | } | 91 | } |
92 | 92 | ||
93 | static void maildir_flush(struct maildir * md, int msg_new); | 93 | static void maildir_flush(struct maildir * md, int msg_new); |
94 | 94 | ||
95 | void maildir_free(struct maildir * md) | 95 | void maildir_free(struct maildir * md) |
96 | { | 96 | { |
97 | maildir_flush(md, 0); | 97 | maildir_flush(md, 0); |
98 | maildir_flush(md, 1); | 98 | maildir_flush(md, 1); |
99 | chash_free(md->mdir_msg_hash); | 99 | chash_free(md->mdir_msg_hash); |
100 | carray_free(md->mdir_msg_list); | 100 | carray_free(md->mdir_msg_list); |
101 | free(md); | 101 | free(md); |
102 | } | 102 | } |
103 | 103 | ||
104 | #define MAX_TRY_ALLOC 32 | 104 | #define MAX_TRY_ALLOC 32 |
105 | 105 | ||
106 | static char * maildir_get_new_message_filename(struct maildir * md, | 106 | 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); |
131 | return NULL; | 144 | return NULL; |
132 | } | 145 | } |
133 | else if (errno == EPERM) { | 146 | else if (errno == EPERM) { |
134 | r = rename(tmpfile, filename); | 147 | r = rename(tmpfile, filename); |
135 | if (r < 0) { | 148 | if (r < 0) { |
136 | unlink(tmpfile); | 149 | unlink(tmpfile); |
137 | return NULL; | 150 | return NULL; |
138 | } | 151 | } |
139 | got_file = 1; | 152 | got_file = 1; |
140 | } | 153 | } |
141 | 154 | ||
142 | if (got_file) { | 155 | if (got_file) { |
143 | char * dup_filename; | 156 | char * dup_filename; |
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 ++; |
157 | k ++; | 170 | k ++; |
158 | } | 171 | } |
159 | 172 | ||
160 | return NULL; | 173 | return NULL; |
161 | } | 174 | } |
162 | 175 | ||
163 | 176 | ||
164 | static void msg_free(struct maildir_msg * msg) | 177 | static void msg_free(struct maildir_msg * msg) |
165 | { | 178 | { |
166 | free(msg->msg_uid); | 179 | free(msg->msg_uid); |
167 | free(msg->msg_filename); | 180 | free(msg->msg_filename); |
168 | free(msg); | 181 | free(msg); |
169 | } | 182 | } |
170 | 183 | ||
171 | /* | 184 | /* |
172 | msg_new() | 185 | msg_new() |
173 | 186 | ||
174 | filename is given without path | 187 | filename is given without path |
175 | */ | 188 | */ |
176 | 189 | ||
177 | static struct maildir_msg * msg_new(char * filename, int new_msg) | 190 | static struct maildir_msg * msg_new(char * filename, int new_msg) |
178 | { | 191 | { |
179 | struct maildir_msg * msg; | 192 | struct maildir_msg * msg; |
180 | char * p; | 193 | char * p; |
181 | int flags; | 194 | int flags; |
182 | size_t uid_len; | 195 | size_t uid_len; |
183 | char * begin_uid; | 196 | char * begin_uid; |
184 | 197 | ||
185 | /* name of file : xxx-xxx_xxx-xxx:2,SRFT */ | 198 | /* name of file : xxx-xxx_xxx-xxx:2,SRFT */ |
186 | 199 | ||
187 | msg = malloc(sizeof(* msg)); | 200 | msg = malloc(sizeof(* msg)); |
188 | if (msg == NULL) | 201 | if (msg == NULL) |
189 | goto err; | 202 | goto err; |
190 | 203 | ||
191 | msg->msg_filename = strdup(filename); | 204 | msg->msg_filename = strdup(filename); |
192 | if (msg->msg_filename == NULL) | 205 | if (msg->msg_filename == NULL) |
193 | goto free; | 206 | goto free; |
194 | 207 | ||
195 | begin_uid = filename; | 208 | begin_uid = filename; |
196 | 209 | ||
197 | uid_len = strlen(begin_uid); | 210 | uid_len = strlen(begin_uid); |
198 | 211 | ||