Class: Proxy::OpenSCAP::StorageFS

Inherits:
Storage
  • Object
show all
Defined in:
lib/smart_proxy_openscap/storage_fs.rb

Instance Method Summary collapse

Methods inherited from Storage

#get_arf_html, #initialize

Constructor Details

This class inherits a constructor from Proxy::OpenSCAP::Storage

Instance Method Details

#delete_arf_fileObject

Raises:



31
32
33
34
35
36
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 31

def delete_arf_file
  path = "#{@path_to_dir}/#{@namespace}/#{@cname}/#{@id}"
  raise FileNotFound, "Can't find path #{path}" if !File.directory?(path) || File.zero?(path)
  FileUtils.rm_r path
  {:id => @id, :deleted => true}.to_json
end

#get_arf_file(digest) ⇒ Object



38
39
40
41
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 38

def get_arf_file(digest)
  file = File.open(get_path digest)
  { :size => File.size(file), :xml => file.read }
end

#get_arf_xml(digest) ⇒ Object



27
28
29
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 27

def get_arf_xml(digest)
  get_arf_file(digest)[:xml]
end

#get_path(digest) ⇒ Object

Raises:



43
44
45
46
47
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 43

def get_path(digest)
  full_path = @path + digest
  raise FileNotFound, "Can't find path #{full_path}" if !File.file?(full_path) || File.zero?(full_path)
  full_path
end

#list_dirs(path) ⇒ Object



54
55
56
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 54

def list_dirs(path)
  Pathname.new(path).children.select(&:directory?)
end

#move_corrupted(digest, spooldir) ⇒ Object



22
23
24
25
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 22

def move_corrupted(digest, spooldir)
  source = "#{spooldir}/#{@namespace}/#{@cname}/#{@id}/#{@date}"
  move "#{source}/#{digest}", StoreCorruptedError
end

#spool_errorsObject



49
50
51
52
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 49

def spool_errors
  path = "#{@path_to_dir}/#{@namespace}"
  { :errors_count => File.exists?(path) ? list_dirs(path).count : 0 }
end

#store_archive(data) ⇒ Object



6
7
8
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 6

def store_archive(data)
  store(data, StoreReportError)
end

#store_corrupted(data) ⇒ Object



18
19
20
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 18

def store_corrupted(data)
  store(data, StoreCorruptedError)
end

#store_failed(data) ⇒ Object



14
15
16
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 14

def store_failed(data)
  store(data, StoreFailedError)
end

#store_spool(data) ⇒ Object



10
11
12
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 10

def store_spool(data)
  store(data, StoreSpoolError)
end