triglav-agent 1.0.0.rc2 → 1.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/triglav/agent/storage_file.rb +39 -22
- data/lib/triglav/agent/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd4f144e95ca465383d0ad12754c70909b263fb5
|
4
|
+
data.tar.gz: f559069d69b3a33f5e83d88f74c6dd052f313760
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1ef456d07edea624a0ba7db0d76ec5c5fa11258416d4c985992f8b605603407a4f18ada89f18daea34b29e6cb5354c007022edfac2d67ebc0ad22e90ab1882f
|
7
|
+
data.tar.gz: 0512ebfc4faa1f399ba838124ad0208d00748480e7e653661cc55270f24a9360a7335043d1c8a32be6fb87edf62b9fa8e549ec5fa214416c01dfe34254533c76
|
@@ -17,6 +17,24 @@ module Triglav::Agent
|
|
17
17
|
@fp = fp
|
18
18
|
end
|
19
19
|
|
20
|
+
# Load storage file
|
21
|
+
#
|
22
|
+
# @return [Hash]
|
23
|
+
def load
|
24
|
+
if !(content = @fp.read).empty?
|
25
|
+
YAML.load(content) # all keys must be symbols
|
26
|
+
else
|
27
|
+
{}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Dump to storage file
|
32
|
+
#
|
33
|
+
# @param [Hash] hash
|
34
|
+
def dump(hash)
|
35
|
+
File.write(@fp.path, YAML.dump(hash))
|
36
|
+
end
|
37
|
+
|
20
38
|
# Load storage file
|
21
39
|
#
|
22
40
|
# StorageFile.load($setting.status_file)
|
@@ -38,11 +56,28 @@ module Triglav::Agent
|
|
38
56
|
# @param [String] path
|
39
57
|
# @param [Block] block
|
40
58
|
def self.open(path, &block)
|
59
|
+
# Use RDONLY instead of WRONLY not to TRUNCate contents
|
41
60
|
fp = File.open(path, (File::RDONLY | File::CREAT))
|
42
|
-
|
43
|
-
|
44
|
-
|
61
|
+
fp.flock(File::LOCK_EX)
|
62
|
+
begin
|
63
|
+
return yield(StorageFile.new(fp))
|
64
|
+
ensure
|
65
|
+
fp.flock(File::LOCK_UN)
|
66
|
+
fp.close rescue nil
|
45
67
|
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Open storage file to read
|
71
|
+
#
|
72
|
+
# StorageFile.readopen($setting.status_file) do |fp|
|
73
|
+
# status = fp.load
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# @param [String] path
|
77
|
+
# @param [Block] block
|
78
|
+
def self.readopen(path, &block)
|
79
|
+
fp = File.open(path, (File::RDONLY | File::CREAT))
|
80
|
+
fp.flock(File::LOCK_SH)
|
46
81
|
begin
|
47
82
|
return yield(StorageFile.new(fp))
|
48
83
|
ensure
|
@@ -139,25 +174,7 @@ module Triglav::Agent
|
|
139
174
|
# @param [Object] key
|
140
175
|
def self.get(path, key)
|
141
176
|
keys = Array(key)
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
# Load storage file
|
146
|
-
#
|
147
|
-
# @return [Hash]
|
148
|
-
def load
|
149
|
-
if !(content = @fp.read).empty?
|
150
|
-
YAML.load(content) # all keys must be symbols
|
151
|
-
else
|
152
|
-
{}
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
# Dump to storage file
|
157
|
-
#
|
158
|
-
# @param [Hash] hash
|
159
|
-
def dump(hash)
|
160
|
-
File.write(@fp.path, YAML.dump(hash))
|
177
|
+
readopen(path) {|fp| fp.load.dig(*keys) }
|
161
178
|
end
|
162
179
|
|
163
180
|
# Keep specified keys, and remove others
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: triglav-agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Triglav Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: serverengine
|