Lines Matching refs:file

1 /* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */
8 #include "file-dotlock.h"
52 struct mail_duplicate_file *file;
88 mail_duplicate_read_records(struct mail_duplicate_file *file,
120 i_error("broken mail_duplicate file %s", file->path);
126 i_error("unexpected end of file in %s", file->path);
135 new_id = p_malloc(file->pool, hdr.id_size);
138 d = p_new(file->pool, struct mail_duplicate, 1);
141 d->user = p_strndup(file->pool,
144 hash_table_update(file->hash, d, d);
151 if (hash_table_count(file->hash) *
153 file->changed = TRUE;
157 static int mail_duplicate_read(struct mail_duplicate_file *file)
166 fd = open(file->path, O_RDONLY);
170 i_error("open(%s) failed: %m", file->path);
188 mail_duplicate_read_records(file, input, record_size) < 0)
189 i_unlink_if_exists(file->path);
193 i_error("close(%s) failed: %m", file->path);
200 struct mail_duplicate_file *file;
207 file = p_new(pool, struct mail_duplicate_file, 1);
208 file->pool = pool;
209 file->path = p_strdup(pool, db->path);
210 file->new_fd = file_dotlock_open(&db->dotlock_set, file->path, 0,
211 &file->dotlock);
212 if (file->new_fd != -1)
215 i_error("file_dotlock_open(%s) failed: %m", file->path);
217 i_error("Creating lock file for %s timed out in %u secs",
218 file->path, db->dotlock_set.timeout);
220 hash_table_create(&file->hash, pool, 0, mail_duplicate_hash, mail_duplicate_cmp);
222 (void)mail_duplicate_read(file);
223 return file;
228 struct mail_duplicate_file *file = *_file;
231 if (file->dotlock != NULL)
232 file_dotlock_delete(&file->dotlock);
234 hash_table_destroy(&file->hash);
235 pool_unref(&file->pool);
243 if (db->file == NULL) {
248 db->file = mail_duplicate_file_new(db);
255 return hash_table_lookup(db->file->hash, &d) != NULL;
265 if (db->file == NULL) {
270 db->file = mail_duplicate_file_new(db);
273 new_id = p_malloc(db->file->pool, id_size);
276 d = p_new(db->file->pool, struct mail_duplicate, 1);
279 d->user = p_strdup(db->file->pool, user);
282 db->file->changed = TRUE;
283 hash_table_update(db->file->hash, d, d);
288 struct mail_duplicate_file *file = db->file;
295 if (file == NULL)
297 if (!file->changed || file->new_fd == -1) {
299 mail_duplicate_file_free(&db->file);
306 output = o_stream_create_fd_file(file->new_fd, 0, FALSE);
311 iter = hash_table_iterate_init(file->hash);
312 while (hash_table_iterate(iter, file->hash, &d, &d)) {
324 i_error("write(%s) failed: %s", file->path,
327 mail_duplicate_file_free(&db->file);
332 if (file_dotlock_replace(&file->dotlock, 0) < 0)
333 i_error("file_dotlock_replace(%s) failed: %m", file->path);
334 mail_duplicate_file_free(&db->file);
365 if (db->file != NULL) {
367 i_assert(db->file == NULL);