Class: Fluent::WindowsFile

Inherits:
Object
  • Object
show all
Includes:
File::Constants
Defined in:
lib/fluent/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_enc = 'r') ⇒ WindowsFile

Returns a new instance of WindowsFile.



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fluent/file_wrapper.rb', line 50

def initialize(path, mode_enc='r')
  @path = path
  mode, enc = mode_enc.split(":", 2)
  @io = File.open(path, mode2flags(mode))
  @io.set_encoding(enc) if enc
  @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.



46
47
48
# File 'lib/fluent/file_wrapper.rb', line 46

def io
  @io
end

Class Method Details

.inoObject



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

def @io.ino
  @file_index
end

Instance Method Details

#closeObject



62
63
64
65
# File 'lib/fluent/file_wrapper.rb', line 62

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.



72
73
74
75
76
77
78
79
80
# File 'lib/fluent/file_wrapper.rb', line 72

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)


82
83
84
85
86
87
88
# File 'lib/fluent/file_wrapper.rb', line 82

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