Class: Proxy::OpenSCAP::StorageFs

Inherits:
Storage
  • Object
show all
Includes:
StorageFsCommon
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:



34
35
36
37
38
39
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 34

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



41
42
43
44
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 41

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

#get_arf_xml(digest) ⇒ Object



30
31
32
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 30

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

#get_path(digest) ⇒ Object

Raises:



46
47
48
49
50
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 46

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



57
58
59
# File 'lib/smart_proxy_openscap/storage_fs.rb', line 57

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

#move_corrupted(digest, spooldir) ⇒ Object



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

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

#spool_errorsObject



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

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

#store_archive(data) ⇒ Object



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

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

#store_corrupted(data) ⇒ Object



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

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

#store_failed(data) ⇒ Object



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

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

#store_spool(data) ⇒ Object



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

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