Skip to content

Commit

Permalink
in_tail: workaround "undeletable file" issue on Windows (#2141)
Browse files Browse the repository at this point in the history
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 <fujimoto@ceptord.net>
  • Loading branch information
fujimotos authored and edsiper committed May 8, 2020
1 parent b8c01a2 commit 597edc7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions plugins/in_tail/tail_fs_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 597edc7

Please sign in to comment.