Class: LogStash::Outputs::LogstashAzureBlobOutput::TemporaryFile
- Inherits:
-
Object
- Object
- LogStash::Outputs::LogstashAzureBlobOutput::TemporaryFile
- Extended by:
- Forwardable
- Defined in:
- lib/logstash/outputs/blob/temporary_file.rb
Overview
a sub class of LogstashAzureBlobOutput
Wrap the actual file descriptor into an utility classe It make it more OOP and easier to reason with the paths.
Instance Attribute Summary collapse
-
#fd ⇒ Object
readonly
Returns the value of attribute fd.
-
#temp_path ⇒ Object
readonly
gets path to temporary directory.
Class Method Summary collapse
-
.create_from_existing_file(file_path, temporary_folder) ⇒ Object
creates the temporary file in an existing temporary directory from existing file.
Instance Method Summary collapse
-
#ctime ⇒ Object
gets the created at time.
-
#delete! ⇒ Object
Each temporary file is made inside a directory named with an UUID, instead of deleting the file directly and having the risk of deleting other files we delete the root of the UUID, using a UUID also remove the risk of deleting unwanted file, it acts as a sandbox.
-
#empty? ⇒ Boolean
boolean method to determine if the file is empty.
-
#initialize(key, fd, temp_path) ⇒ TemporaryFile
constructor
initialize the class.
-
#key ⇒ Object
gets the key.
-
#size ⇒ Object
gets the size of file.
Constructor Details
#initialize(key, fd, temp_path) ⇒ TemporaryFile
initialize the class
19 20 21 22 23 24 |
# File 'lib/logstash/outputs/blob/temporary_file.rb', line 19 def initialize(key, fd, temp_path) @fd = fd @key = key @temp_path = temp_path @created_at = Time.now end |
Instance Attribute Details
#fd ⇒ Object (readonly)
Returns the value of attribute fd.
16 17 18 |
# File 'lib/logstash/outputs/blob/temporary_file.rb', line 16 def fd @fd end |
#temp_path ⇒ Object (readonly)
gets path to temporary directory
32 33 34 |
# File 'lib/logstash/outputs/blob/temporary_file.rb', line 32 def temp_path @temp_path end |
Class Method Details
.create_from_existing_file(file_path, temporary_folder) ⇒ Object
creates the temporary file in an existing temporary directory from existing file
71 72 73 74 75 76 77 |
# File 'lib/logstash/outputs/blob/temporary_file.rb', line 71 def self.create_from_existing_file(file_path, temporary_folder) key_parts = Pathname.new(file_path).relative_path_from(temporary_folder).to_s.split(::File::SEPARATOR) TemporaryFile.new(key_parts.slice(1, key_parts.size).join('/'), ::File.open(file_path, 'r'), ::File.join(temporary_folder, key_parts.slice(0, 1))) end |
Instance Method Details
#ctime ⇒ Object
gets the created at time
27 28 29 |
# File 'lib/logstash/outputs/blob/temporary_file.rb', line 27 def ctime @created_at end |
#delete! ⇒ Object
Each temporary file is made inside a directory named with an UUID, instead of deleting the file directly and having the risk of deleting other files we delete the root of the UUID, using a UUID also remove the risk of deleting unwanted file, it acts as a sandbox.
54 55 56 57 58 59 60 61 |
# File 'lib/logstash/outputs/blob/temporary_file.rb', line 54 def delete! begin @fd.close rescue IOError end FileUtils.rm_r(@temp_path, secure: true) end |
#empty? ⇒ Boolean
boolean method to determine if the file is empty
64 65 66 |
# File 'lib/logstash/outputs/blob/temporary_file.rb', line 64 def empty? size.zero? end |
#key ⇒ Object
gets the key
46 47 48 |
# File 'lib/logstash/outputs/blob/temporary_file.rb', line 46 def key @key.gsub(/^\//, '') end |
#size ⇒ Object
gets the size of file
35 36 37 38 39 40 41 42 43 |
# File 'lib/logstash/outputs/blob/temporary_file.rb', line 35 def size # Use the fd size to get the accurate result, # so we dont have to deal with fsync # if the file is close we will use the File::size @fd.size rescue IOError ::File.size(path) end |