From: Marco Bettini Date: Tue, 28 Feb 2023 11:21:10 +0000 (+0000) Subject: dbox: dbox_mailbox_open() - Move dbox_cleanup_temp_files() to dbox_mailbox_close() X-Git-Tag: 2.3.21~89 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4bf0ee1814a67c4f09ae3e8ab2d15dff93378edc;p=thirdparty%2Fdovecot%2Fcore.git dbox: dbox_mailbox_open() - Move dbox_cleanup_temp_files() to dbox_mailbox_close() --- diff --git a/src/lib-storage/index/dbox-common/dbox-storage.c b/src/lib-storage/index/dbox-common/dbox-storage.c index cbf5de30df..53b853be39 100644 --- a/src/lib-storage/index/dbox-common/dbox-storage.c +++ b/src/lib-storage/index/dbox-common/dbox-storage.c @@ -261,31 +261,56 @@ int dbox_mailbox_check_existence(struct mailbox *box, time_t *path_ctime_r) } } -int dbox_mailbox_open(struct mailbox *box, time_t path_ctime) +int dbox_mailbox_open(struct mailbox *box, time_t path_ctime ATTR_UNUSED) { - const char *box_path = mailbox_get_path(box); - if (index_storage_mailbox_open(box, FALSE) < 0) return -1; mail_index_set_fsync_mode(box->index, box->storage->set->parsed_fsync_mode, MAIL_INDEX_FSYNC_MASK_APPENDS | MAIL_INDEX_FSYNC_MASK_EXPUNGES); + return 0; +} + +static void dbox_mailbox_close_cleanup(struct mailbox *box) +{ + if (box->view == NULL) + return; + + const struct mail_index_header *hdr = + mail_index_get_header(box->view); + + const char *box_path = mailbox_get_path(box); + time_t scan_time = hdr->last_temp_file_scan; + time_t change_time = -1; - const struct mail_index_header *hdr = mail_index_get_header(box->view); - uint32_t last_temp_file_scan = hdr->last_temp_file_scan; - if (last_temp_file_scan == 0) { + if (scan_time == 0) { + /* Try to fetch the scan time from dhe directory's atime + if the directory exists. In case, get also the ctime */ struct stat stats; - if (stat(box_path, &stats) == 0) - last_temp_file_scan = stats.st_atim.tv_sec; + if (stat(box_path, &stats) == 0) { + scan_time = stats.st_atim.tv_sec; + change_time = stats.st_ctim.tv_sec; + } else { + if (errno != ENOENT) { + e_error(box->event, + "stat(%s) failed: %m", box_path); + } + return; + } } - if (dbox_cleanup_temp_files(box->list, box_path, - last_temp_file_scan, path_ctime)) { + if (dbox_cleanup_temp_files(box->list, box_path, scan_time, change_time) || + hdr->last_temp_file_scan == 0) { /* temp files were scanned. update the last scan timestamp. */ index_mailbox_update_last_temp_file_scan(box); } - return 0; +} + +void dbox_mailbox_close(struct mailbox *box) +{ + dbox_mailbox_close_cleanup(box); + index_storage_mailbox_close(box); } static int dir_is_empty(struct mail_storage *storage, const char *path) diff --git a/src/lib-storage/index/dbox-common/dbox-storage.h b/src/lib-storage/index/dbox-common/dbox-storage.h index af085df6ba..ca8c835305 100644 --- a/src/lib-storage/index/dbox-common/dbox-storage.h +++ b/src/lib-storage/index/dbox-common/dbox-storage.h @@ -74,6 +74,7 @@ uint32_t dbox_get_uidvalidity_next(struct mailbox_list *list); void dbox_notify_changes(struct mailbox *box); int dbox_mailbox_check_existence(struct mailbox *box, time_t *path_ctime_r); int dbox_mailbox_open(struct mailbox *box, time_t path_ctime); +void dbox_mailbox_close(struct mailbox *box); int dbox_mailbox_create(struct mailbox *box, const struct mailbox_update *update, bool directory); int dbox_mailbox_create_indexes(struct mailbox *box, diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.c b/src/lib-storage/index/dbox-multi/mdbox-storage.c index e7e7f600e5..8148f72c87 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c @@ -201,7 +201,7 @@ static void mdbox_mailbox_close(struct mailbox *box) if (mstorage->corrupted && !mstorage->rebuilding_storage) (void)mdbox_storage_rebuild(mstorage); - index_storage_mailbox_close(box); + dbox_mailbox_close(box); } int mdbox_read_header(struct mdbox_mailbox *mbox, diff --git a/src/lib-storage/index/dbox-single/sdbox-storage.c b/src/lib-storage/index/dbox-single/sdbox-storage.c index 5a6fcaddec..d05343cca6 100644 --- a/src/lib-storage/index/dbox-single/sdbox-storage.c +++ b/src/lib-storage/index/dbox-single/sdbox-storage.c @@ -376,7 +376,8 @@ static void sdbox_mailbox_close(struct mailbox *box) if (mbox->corrupted_rebuild_count != 0) (void)sdbox_sync(mbox, 0); - index_storage_mailbox_close(box); + + dbox_mailbox_close(box); } static int