Skip to content

Commit

Permalink
WindowsFile: Allow Fluentd to respect DeletePending
Browse files Browse the repository at this point in the history
This is a Fluentd port of the following fix: fluent-bit#2027

Windows has a concept of DeletePending, which means "DeleteFile()
was called on that file. NTFS will remove this file once everyone
close the handlers for it".

This patch teaches Fluentd to respect the DeletePending flag.

Signed-off-by: Fujimoto Seiji <[email protected]>
  • Loading branch information
fujimotos committed Jul 13, 2021
1 parent f73c601 commit f61c08c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/fluent/plugin/file_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,29 @@ def ino
by_handle_file_information.unpack("I11Q1")[11] # fileindex
end

# DeletePending is a Windows-specific file state that roughly means
# "this file is queued for deletion, so close any open handlers"
#
# This flag can be retrieved via GetFileInformationByHandleEx().
#
# https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getfileinformationbyhandleex
#
def delete_pending
file_standard_info = 0x01
bufsize = 1024
buf = '\0' * bufsize

unless GetFileInformationByHandleEx.call(@file_handle, file_standard_info, buf, bufsize)
return false
end

return buf.unpack("QQICC")[3] != 0
end

private :delete_pending

def stat
raise Errno::ENOENT if delete_pending
s = File.stat(@path)
s.instance_variable_set :@ino, self.ino
def s.ino; @ino; end
Expand Down

0 comments on commit f61c08c

Please sign in to comment.