Class: Braavos::Storage::File
Instance Method Summary
collapse
Methods inherited from StorageBase
#find_node_id, #get_cluster, #list_backups, #verify_cluster
Instance Method Details
#clear_result(location) ⇒ Object
19
20
21
|
# File 'lib/braavos/storage/file.rb', line 19
def clear_result(location)
FileUtils.rm_f File.join(location, "_FAILED")
end
|
#has_success?(location) ⇒ Boolean
23
24
25
26
27
|
# File 'lib/braavos/storage/file.rb', line 23
def has_success?(location)
path = File.join(location, "_COMPLETED")
list_dir(location).size > 0 &&
File.exists?(path)
end
|
#list_dir(location) ⇒ Object
Returns a recursive listing of => true if directory and => *file size* if file
9
10
11
12
13
14
15
16
17
|
# File 'lib/braavos/storage/file.rb', line 9
def list_dir(location)
Braavos.logger.debug("list_dir: #{location}")
listing = Dir["#{location}/**/*"].inject({}) do |h,i|
h[i] = File.size?(i) if not File.directory?(i)
h
end
Braavos.logger.debug("\t#{listing}")
listing
end
|
#load_file(location) ⇒ Object
3
4
5
6
|
# File 'lib/braavos/storage/file.rb', line 3
def load_file(location)
Braavos.logger.debug("load_file: #{location}")
File.read(location)
end
|
#script_path(location) ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/braavos/storage/file.rb', line 29
def script_path(location)
@mkdir_cache ||= Hash.new do |h, key|
FileUtils.mkdir_p(key)
h[key] = true
end
@mkdir_cache[File.dirname(location)]
location
end
|
#write_file(location, contents) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/braavos/storage/file.rb', line 39
def write_file(location, contents)
script_path(location) if contents.is_a?(Hash) && contents.include?(:file)
FileUtils.cp(contents[:file], location)
else
File.open(location, 'w') do |f| f.write contents end
end
end
|