Class: Fluent::WindowsFile
- Inherits:
-
Object
- Object
- Fluent::WindowsFile
- Includes:
- File::Constants
- Defined in:
- lib/fluent/plugin/file_wrapper.rb
Constant Summary collapse
- INVALID_HANDLE_VALUE =
-1
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(path, mode = 'r') ⇒ WindowsFile
constructor
A new instance of WindowsFile.
-
#ino ⇒ Object
To keep backward compatibility, we continue to use GetFileInformationByHandle() to get file id.
- #stat ⇒ Object
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
#io ⇒ Object (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
.ino ⇒ Object
52 53 54 |
# File 'lib/fluent/plugin/file_wrapper.rb', line 52 def @io.ino @file_index end |
Instance Method Details
#close ⇒ Object
57 58 59 60 |
# File 'lib/fluent/plugin/file_wrapper.rb', line 57 def close @io.close @file_handle = INVALID_HANDLE_VALUE end |
#ino ⇒ Object
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 |
#stat ⇒ Object
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 |