class LogStash::Outputs::LogstashAzureBlobOutput::TemporaryFile

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.

Attributes

fd[R]
temp_path[R]

gets path to temporary directory

Public Class Methods

create_from_existing_file(file_path, temporary_folder) click to toggle source

creates the temporary file in an existing temporary directory from existing file @param file_path [String] path to the file @param temporary_folder [String] path to the temporary folder

# 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
new(key, fd, temp_path) click to toggle source

initialize the class

# 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

Public Instance Methods

ctime() click to toggle source

gets the created at time

# File lib/logstash/outputs/blob/temporary_file.rb, line 27
def ctime
  @created_at
end
delete!() click to toggle source

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.

# 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?() click to toggle source

boolean method to determine if the file is empty

# File lib/logstash/outputs/blob/temporary_file.rb, line 64
def empty?
  size.zero?
end
key() click to toggle source

gets the key

# File lib/logstash/outputs/blob/temporary_file.rb, line 46
def key
  @key.gsub(/^\//, '')
end
size() click to toggle source

gets the size of file

# 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