filelock 1.1.0 → 1.1.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +10 -0
- data/lib/filelock.rb +3 -3
- data/lib/filelock/version.rb +1 -1
- data/spec/filelock_spec.rb +11 -0
- 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: 8306638bf16d2c4aa3be2543c24d68e0a673fd31
|
4
|
+
data.tar.gz: 8d19eb1e21833db47e8b7fe67f36915482a5b6ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2042a3b18be5cd3045051369501b5a50437e407841050d7c637254b0858a97a555160f19d91e7b2feb507e6e350fad9dc2561ace97d614eb7c918dc992bb197e
|
7
|
+
data.tar.gz: 08a2351b10bd4c078d513e98c8a9db180b964b877d7f8ab0a5a27f2851b5eed0e48f6aaf6522fe443e7c57d43e1fb2fc8a160c904a417c965e74cb5694927db1
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
# 1.1.1
|
2
|
+
|
3
|
+
- fix: Load timeout module before using it
|
4
|
+
- pass locked file to block provided to Filelock
|
5
|
+
|
1
6
|
# 1.1.0
|
2
7
|
|
3
8
|
- Add `:wait` flag for lock-acquiting timeout
|
4
|
-
- Add two new timeout
|
9
|
+
- Add two new timeout exceptions: `FileLock::ExecTimeout` and `FileLock::WaitTimeout`
|
5
10
|
|
6
11
|
# 1.0.3
|
7
12
|
|
data/README.md
CHANGED
@@ -43,6 +43,16 @@ You can detect this kind of timeout by catching `Filelock::WaitTimeout`.
|
|
43
43
|
|
44
44
|
Note that lock file directory must already exist, and lock file is not removed after unlock.
|
45
45
|
|
46
|
+
### Getting handle to locked file
|
47
|
+
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
Filelock '/tmp/path/to/lock' do |file|
|
51
|
+
file.truncate
|
52
|
+
file.write Process.pid
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
46
56
|
## FAQ
|
47
57
|
|
48
58
|
*Does it support NFS?*
|
data/lib/filelock.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
+
require 'timeout'
|
1
2
|
require 'filelock/version'
|
2
3
|
require 'filelock/exec_timeout'
|
3
4
|
require 'filelock/wait_timeout'
|
4
|
-
require 'timeout'
|
5
5
|
require 'tempfile'
|
6
6
|
|
7
7
|
if RUBY_PLATFORM == "java"
|
@@ -9,7 +9,7 @@ if RUBY_PLATFORM == "java"
|
|
9
9
|
lockname = lockname.path if lockname.is_a?(Tempfile)
|
10
10
|
File.open(lockname, File::RDWR|File::CREAT, 0644) do |file|
|
11
11
|
Thread.pass until Timeout::timeout(options.fetch(:wait, 60*60*24), Filelock::WaitTimeout) { file.flock(File::LOCK_EX) }
|
12
|
-
Timeout::timeout(options.fetch(:timeout, 60), Filelock::ExecTimeout) { yield }
|
12
|
+
Timeout::timeout(options.fetch(:timeout, 60), Filelock::ExecTimeout) { yield file }
|
13
13
|
end
|
14
14
|
end
|
15
15
|
else
|
@@ -17,7 +17,7 @@ else
|
|
17
17
|
lockname = lockname.path if lockname.is_a?(Tempfile)
|
18
18
|
File.open(lockname, File::RDWR|File::CREAT, 0644) do |file|
|
19
19
|
Timeout::timeout(options.fetch(:wait, 60*60*24), Filelock::WaitTimeout) { file.flock(File::LOCK_EX) }
|
20
|
-
Timeout::timeout(options.fetch(:timeout, 60), Filelock::ExecTimeout) { yield }
|
20
|
+
Timeout::timeout(options.fetch(:timeout, 60), Filelock::ExecTimeout) { yield file }
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/filelock/version.rb
CHANGED
data/spec/filelock_spec.rb
CHANGED
@@ -59,6 +59,17 @@ describe Filelock do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
it 'passes handle to block' do
|
63
|
+
Dir.mktmpdir do |dir|
|
64
|
+
lockpath = File.join(dir, 'sample.lock')
|
65
|
+
Filelock lockpath do |lock|
|
66
|
+
lock.write '42'
|
67
|
+
end
|
68
|
+
|
69
|
+
expect(File.read(File.join(dir,'sample.lock'))).to eq('42')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
62
73
|
it 'runs in parallel without race condition' do
|
63
74
|
answer = 0
|
64
75
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filelock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Stankiewicz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|