Class: Fluent::WindowsFile
- Inherits:
-
Object
- Object
- Fluent::WindowsFile
- Includes:
- Windows::Error, Windows::File, Windows::Handle, Windows::NIO
- Defined in:
- lib/fluent/plugin/file_wrapper.rb
Overview
To open and get stat with setting FILE_SHARE_DELETE
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(path, mode = 'r', sharemode = FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE) ⇒ WindowsFile
constructor
A new instance of WindowsFile.
- #ino ⇒ Object
- #io ⇒ Object
- #stat ⇒ Object
Constructor Details
#initialize(path, mode = 'r', sharemode = FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE) ⇒ WindowsFile
Returns a new instance of WindowsFile.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/fluent/plugin/file_wrapper.rb', line 103 def initialize(path, mode='r', sharemode=FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE) @path = path @file_handle = INVALID_HANDLE_VALUE @mode = mode access, creationdisposition, seektoend = case mode.delete('b') when "r" ; [FILE_GENERIC_READ , OPEN_EXISTING, false] when "r+"; [FILE_GENERIC_READ | FILE_GENERIC_WRITE, OPEN_ALWAYS , false] when "w" ; [FILE_GENERIC_WRITE , CREATE_ALWAYS, false] when "w+"; [FILE_GENERIC_READ | FILE_GENERIC_WRITE, CREATE_ALWAYS, false] when "a" ; [FILE_GENERIC_WRITE , OPEN_ALWAYS , true] when "a+"; [FILE_GENERIC_READ | FILE_GENERIC_WRITE, OPEN_ALWAYS , true] else raise "unknown mode '#{mode}'" end @file_handle = CreateFile.call(@path, access, sharemode, 0, creationdisposition, FILE_ATTRIBUTE_NORMAL, 0) if @file_handle == INVALID_HANDLE_VALUE win32err = Win32Error.new(Win32::API.last_error, path) errno = ServerEngine::RbWinSock.rb_w32_map_errno(win32err.errcode) if errno == Errno::EINVAL::Errno || win32err.wsaerr? # maybe failed to map raise win32err else raise SystemCallError.new(win32err., errno) end end end |
Instance Method Details
#close ⇒ Object
133 134 135 136 |
# File 'lib/fluent/plugin/file_wrapper.rb', line 133 def close CloseHandle.call(@file_handle) @file_handle = INVALID_HANDLE_VALUE end |
#ino ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/fluent/plugin/file_wrapper.rb', line 148 def ino by_handle_file_information = '\0'*(4+8+8+8+4+4+4+4+4+4) #72bytes unless GetFileInformationByHandle.call(@file_handle, by_handle_file_information) return 0 end by_handle_file_information.unpack("I11Q1")[11] # fileindex end |
#io ⇒ Object
138 139 140 141 142 143 144 145 146 |
# File 'lib/fluent/plugin/file_wrapper.rb', line 138 def io fd = _open_osfhandle(@file_handle, 0) raise Errno::ENOENT if fd == -1 io = File.for_fd(fd, @mode) io.instance_variable_set :@ino, self.ino io.instance_variable_set :@path, @path io.extend WindowsFileExtension io end |
#stat ⇒ Object
179 180 181 182 183 184 185 |
# File 'lib/fluent/plugin/file_wrapper.rb', line 179 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 |