rufus-cloche 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.txt +5 -0
- data/TODO.txt +1 -0
- data/lib/rufus/cloche.rb +10 -7
- data/lib/rufus/cloche/version.rb +1 -1
- metadata +2 -2
data/CHANGELOG.txt
CHANGED
data/TODO.txt
CHANGED
data/lib/rufus/cloche.rb
CHANGED
@@ -92,7 +92,7 @@ module Rufus
|
|
92
92
|
) if rev.class != Fixnum && rev.class != Bignum
|
93
93
|
|
94
94
|
r =
|
95
|
-
lock(rev == -1, type, key) do |file|
|
95
|
+
lock(rev == -1 ? :create : :write, type, key) do |file|
|
96
96
|
|
97
97
|
cur = do_get(file)
|
98
98
|
|
@@ -111,7 +111,7 @@ module Rufus
|
|
111
111
|
#
|
112
112
|
def get(type, key)
|
113
113
|
|
114
|
-
r = lock(
|
114
|
+
r = lock(:read, type, key) { |f| do_get(f) }
|
115
115
|
|
116
116
|
r == false ? nil : r
|
117
117
|
end
|
@@ -136,7 +136,7 @@ module Rufus
|
|
136
136
|
type, key = doc['type'], doc['_id']
|
137
137
|
|
138
138
|
r =
|
139
|
-
lock(
|
139
|
+
lock(:delete, type, key) do |f|
|
140
140
|
|
141
141
|
cur = do_get(f)
|
142
142
|
|
@@ -287,7 +287,7 @@ module Rufus
|
|
287
287
|
[ File.join(dir_for(type), subdir), "#{nkey}.json" ]
|
288
288
|
end
|
289
289
|
|
290
|
-
def lock(
|
290
|
+
def lock(ltype, type, key, &block)
|
291
291
|
|
292
292
|
@mutex.synchronize do
|
293
293
|
begin
|
@@ -295,8 +295,8 @@ module Rufus
|
|
295
295
|
d, f = path_for(type, key)
|
296
296
|
fn = File.join(d, f)
|
297
297
|
|
298
|
-
FileUtils.mkdir_p(d) if create && ( ! File.exist?(d))
|
299
|
-
FileUtils.touch(fn) if create && ( ! File.exist?(fn))
|
298
|
+
FileUtils.mkdir_p(d) if ltype == :create && ( ! File.exist?(d))
|
299
|
+
FileUtils.touch(fn) if ltype == :create && ( ! File.exist?(fn))
|
300
300
|
|
301
301
|
file = File.new(fn, 'r+') rescue nil
|
302
302
|
|
@@ -304,7 +304,10 @@ module Rufus
|
|
304
304
|
|
305
305
|
file.flock(File::LOCK_EX) unless @nolock
|
306
306
|
|
307
|
-
|
307
|
+
if ltype == :write
|
308
|
+
Thread.pass
|
309
|
+
21.times { return false unless File.exist?(fn) }
|
310
|
+
end
|
308
311
|
#
|
309
312
|
# We got the lock, but is the file still here?
|
310
313
|
#
|
data/lib/rufus/cloche/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rufus-cloche
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rufus-json
|