From e5cccb4e70ceb925bcf508cea760a04487de61ea Mon Sep 17 00:00:00 2001 From: Fujimoto Seiji Date: Thu, 30 Apr 2020 16:25:58 +0900 Subject: [PATCH] in_tail: Work around "undeletable file" issue on Windows Windows will not actually delete a file as long as there is any open handler for it. Until we close the last open handler, the file is kept alive as "pending delete". Obviously this has been breaking the log rotation mechanism for some users. Work arount that by checking the "DeletePending" flag manually in tail_fs_check(). Signed-off-by: Fujimoto Seiji --- plugins/in_tail/tail_fs_stat.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/plugins/in_tail/tail_fs_stat.c b/plugins/in_tail/tail_fs_stat.c index 32dd5c262a8..28f2858482f 100644 --- a/plugins/in_tail/tail_fs_stat.c +++ b/plugins/in_tail/tail_fs_stat.c @@ -116,6 +116,26 @@ static int tail_fs_check(struct flb_input_instance *ins, continue; } +#ifdef FLB_SYSTEM_WINDOWS + HANDLE h; + FILE_STANDARD_INFO info; + + h = _get_osfhandle(file->fd); + if (GetFileInformationByHandleEx(h, FileStandardInfo, + &info, sizeof(info))) { + if (info.DeletePending) { + flb_plg_debug(ctx->ins, "file is to be delete: %s", file->name); +#ifdef FLB_HAVE_SQLDB + if (ctx->db) { + flb_tail_db_file_delete(file, ctx); + } +#endif + flb_tail_file_remove(file); + continue; + } + } +#endif + /* Discover the current file name for the open file descriptor */ name = flb_tail_file_name(file); if (!name) {