Class: LogStash::Outputs::OSS::TemporaryFile

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/logstash/outputs/oss/temporary_file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, object_key, temporary_path) ⇒ TemporaryFile

Returns a new instance of TemporaryFile.



13
14
15
16
17
18
# File 'lib/logstash/outputs/oss/temporary_file.rb', line 13

def initialize(file, object_key, temporary_path)
  @file = file
  @object_key = object_key
  @temporary_path = temporary_path
  @creation_time = Time.now
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



11
12
13
# File 'lib/logstash/outputs/oss/temporary_file.rb', line 11

def file
  @file
end

Class Method Details

.create_existing_file(path, temporary_directory) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/logstash/outputs/oss/temporary_file.rb', line 49

def self.create_existing_file(path, temporary_directory)
  # path is #{temporary_directory}/${uuid}/${prefix}/${key}
  elements = Pathname.new(path).relative_path_from(Pathname.new(temporary_directory)).to_s.split(::File::SEPARATOR)
  uuid = elements[0]
  object_key = ::File.join(elements.slice(1, elements.size - 1))
  TemporaryFile.new(::File.open(path, "r"), object_key, ::File.join(temporary_directory, uuid))
end

Instance Method Details

#ctimeObject



20
21
22
# File 'lib/logstash/outputs/oss/temporary_file.rb', line 20

def ctime
  @creation_time
end

#delete!Object



40
41
42
43
# File 'lib/logstash/outputs/oss/temporary_file.rb', line 40

def delete!
  @file.close rescue IOError
  FileUtils.rm_r(@temporary_path, :secure => true)
end

#empty?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/logstash/outputs/oss/temporary_file.rb', line 45

def empty?
  size == 0
end

#keyObject



36
37
38
# File 'lib/logstash/outputs/oss/temporary_file.rb', line 36

def key
  @object_key.gsub(/^\//, "")
end

#sizeObject



28
29
30
31
32
33
34
# File 'lib/logstash/outputs/oss/temporary_file.rb', line 28

def size
  begin
    @file.size
  rescue IOError
    ::File.size(path)
  end
end

#temporary_pathObject



24
25
26
# File 'lib/logstash/outputs/oss/temporary_file.rb', line 24

def temporary_path
  @temporary_path
end