Class: Fluent::WindowsFile

Inherits:
Object
  • Object
show all
Includes:
File::Constants
Defined in:
lib/fluent/plugin/file_wrapper.rb

Constant Summary collapse

INVALID_HANDLE_VALUE =
-1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, mode = 'r') ⇒ WindowsFile

Returns a new instance of WindowsFile.



47
48
49
50
51
52
53
54
55
# File 'lib/fluent/plugin/file_wrapper.rb', line 47

def initialize(path, mode='r')
  @path = path
  @io = File.open(path, mode2flags(mode))
  @file_handle = Win32API._get_osfhandle(@io.to_i)
  @io.instance_variable_set(:@file_index, self.ino)
  def @io.ino
    @file_index
  end
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



43
44
45
# File 'lib/fluent/plugin/file_wrapper.rb', line 43

def io
  @io
end

Class Method Details

.inoObject



52
53
54
# File 'lib/fluent/plugin/file_wrapper.rb', line 52

def @io.ino
  @file_index
end

Instance Method Details

#closeObject



57
58
59
60
# File 'lib/fluent/plugin/file_wrapper.rb', line 57

def close
  @io.close
  @file_handle = INVALID_HANDLE_VALUE
end

#inoObject

To keep backward compatibility, we continue to use GetFileInformationByHandle() to get file id. Note that Ruby’s File.stat uses GetFileInformationByHandleEx() with FileIdInfo and returned value is different with above one, former one is 64 bit while later one is 128bit.



67
68
69
70
71
72
73
74
75
# File 'lib/fluent/plugin/file_wrapper.rb', line 67

def ino
  by_handle_file_information = '\0'*(4+8+8+8+4+4+4+4+4+4)   #72bytes

  unless Win32API.GetFileInformationByHandle(@file_handle, by_handle_file_information)
    return 0
  end

  by_handle_file_information.unpack("I11Q1")[11] # fileindex
end

#statObject

Raises:

  • (Errno::ENOENT)


77
78
79
80
81
82
83
# File 'lib/fluent/plugin/file_wrapper.rb', line 77

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