if (*file_r != NULL)
return 1;
/* FIXME: use retry_later somehow */
- if (!mail_index_lookup_seq_range(map->view, 1, uid-1,
+ if (uid == 1 ||
+ !mail_index_lookup_seq_range(map->view, 1, uid-1,
&seq1, &seq))
break;
seq++;
int dbox_sync_file_cleanup(struct dbox_file *file)
{
struct dbox_file *out_file;
+ struct stat st;
struct istream *input;
struct ostream *output = NULL;
struct dbox_metadata_header meta_hdr;
if ((ret = dbox_file_try_lock(file)) <= 0)
return ret;
+ /* make sure the file still exists. another process may have already
+ deleted it. */
+ if (stat(file->current_path, &st) < 0) {
+ dbox_file_unlock(file);
+ if (errno == ENOENT)
+ return 0;
+
+ mail_storage_set_critical(&file->storage->storage,
+ "stat(%s) failed: %m", file->current_path);
+ return -1;
+ }
+
append_ctx = dbox_map_append_begin_storage(file->storage);
i_array_init(&msgs_arr, 128);
ret = -1;
} else if (output == NULL) {
/* everything expunged in this file, unlink it */
- dbox_map_append_rollback(&append_ctx);
ret = dbox_sync_file_unlink(file);
+ dbox_map_append_rollback(&append_ctx);
} else {
/* assign new file_id + offset to moved messages */
if (dbox_map_append_move(append_ctx, &copied_map_uids,
dbox_map_append_rollback(&append_ctx);
ret = -1;
} else {
- dbox_map_append_commit(&append_ctx);
(void)dbox_sync_file_unlink(file);
+ dbox_map_append_commit(&append_ctx);
ret = 1;
}
}