lockf.rb 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -24
- data/Rakefile.rb +1 -0
- data/ext/lockf.rb/lockf.c +8 -10
- data/lib/lockf/version.rb +1 -1
- data/lib/lockf.rb +0 -1
- data/lockf.rb.gemspec +1 -1
- data/test/lock_file_test.rb +25 -39
- data/test/setup.rb +0 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07acab1cbd6394d179fafd3fed888bdb56f7bc52868a8557a6b2114500a409ca
|
4
|
+
data.tar.gz: '0178e4e393991e7b3ab099ba2491aa7888fb30e1f096d785d4797f6bbb30a048'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80e87c4f223f90db7ffb518dcf969342125c546b8d3a839af8a36086caeca67a7155b90953c883dab3f598c5f17d5d827b8fe72c2e53b841b6260a789fc6deeb
|
7
|
+
data.tar.gz: ad79f9b41adb8ea5fd4a891eabd0f8488bfe5a5afd80a27ccacc81f2e06eae1bd7530fd74edb985f988aad559f59176ed61392e87829fb7d9e65395d23f99e7c
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
## About
|
2
2
|
|
3
|
-
lockf.rb
|
3
|
+
lockf.rb provides Ruby bindings for
|
4
4
|
[lockf(3)](https://man.freebsd.org/cgi/man.cgi?query=lockf&sektion=3).
|
5
5
|
The
|
6
6
|
[lockf(3)](https://man.freebsd.org/cgi/man.cgi?query=lockf&sektion=3)
|
@@ -8,10 +8,9 @@ function implements an advisory-mode lock that can be placed on select
|
|
8
8
|
regions of a file, or on the entire contents of a file.
|
9
9
|
|
10
10
|
[lockf(3)](https://man.freebsd.org/cgi/man.cgi?query=lockf&sektion=3)
|
11
|
-
can
|
12
|
-
|
13
|
-
|
14
|
-
generally,
|
11
|
+
can synchronize access to a file between multiple processes, or
|
12
|
+
synchronize access to a shared resource being accessed by multiple
|
13
|
+
processes at the same time. When used with a shared resource,
|
15
14
|
[lockf(3)](https://man.freebsd.org/cgi/man.cgi?query=lockf&sektion=3)
|
16
15
|
can provide something similar to a mutex that works across multiple
|
17
16
|
processes rather than multiple threads.
|
@@ -131,32 +130,19 @@ file.close
|
|
131
130
|
# Lock released
|
132
131
|
```
|
133
132
|
|
134
|
-
## Sources
|
135
|
-
|
136
|
-
* [Source code (GitHub)](https://github.com/0x1eef/lockf.rb#readme)
|
137
|
-
* [Source code (GitLab)](https://gitlab.com/0x1eef/lockf.rb#about)
|
138
|
-
|
139
133
|
## Install
|
140
134
|
|
141
|
-
**Git**
|
142
|
-
|
143
|
-
lockf.rb is distributed as a RubyGem through its git repositories. <br>
|
144
|
-
[GitHub](https://github.com/0x1eef/lockf.rb),
|
145
|
-
and
|
146
|
-
[GitLab](https://gitlab.com/0x1eef/lockf.rb)
|
147
|
-
are available as sources.
|
148
|
-
|
149
|
-
``` ruby
|
150
|
-
# Gemfile
|
151
|
-
gem "lock.fb", github: "0x1eef/lockf.rb", tag: "v0.12.0"
|
152
|
-
```
|
153
|
-
|
154
135
|
**Rubygems.org**
|
155
136
|
|
156
|
-
|
137
|
+
lockf.rb can be installed via rubygems.org.
|
157
138
|
|
158
139
|
gem install lockf.rb
|
159
140
|
|
141
|
+
## Sources
|
142
|
+
|
143
|
+
* [GitHub](https://github.com/0x1eef/lockf.rb#readme)
|
144
|
+
* [GitLab](https://gitlab.com/0x1eef/lockf.rb#about)
|
145
|
+
|
160
146
|
## License
|
161
147
|
|
162
148
|
[BSD Zero Clause](https://choosealicense.com/licenses/0bsd/).
|
data/Rakefile.rb
CHANGED
data/ext/lockf.rb/lockf.c
CHANGED
@@ -13,24 +13,22 @@ lockf_lock(VALUE self, VALUE fd, VALUE cmd, VALUE len)
|
|
13
13
|
Check_Type(len, T_FIXNUM);
|
14
14
|
errno = 0;
|
15
15
|
result = lockf(NUM2INT(fd), NUM2INT(cmd), NUM2INT(len));
|
16
|
-
if (result ==
|
17
|
-
rb_syserr_fail(errno, "lockf");
|
18
|
-
} else {
|
16
|
+
if (result == 0) {
|
19
17
|
return INT2NUM(result);
|
18
|
+
} else {
|
19
|
+
rb_syserr_fail(errno, "lockf");
|
20
20
|
}
|
21
21
|
}
|
22
22
|
|
23
23
|
void
|
24
24
|
Init_lockf(void)
|
25
25
|
{
|
26
|
-
VALUE cLockf
|
26
|
+
VALUE cLockf;
|
27
27
|
|
28
|
-
rb_require("fcntl");
|
29
28
|
cLockf = rb_define_class("LockFile", rb_cObject);
|
30
|
-
|
31
|
-
rb_define_const(
|
32
|
-
rb_define_const(
|
33
|
-
rb_define_const(
|
34
|
-
rb_define_const(mFcntl, "F_TEST", INT2NUM(F_TEST));
|
29
|
+
rb_define_const(cLockf, "F_LOCK", INT2NUM(F_LOCK));
|
30
|
+
rb_define_const(cLockf, "F_TLOCK", INT2NUM(F_TLOCK));
|
31
|
+
rb_define_const(cLockf, "F_ULOCK", INT2NUM(F_ULOCK));
|
32
|
+
rb_define_const(cLockf, "F_TEST", INT2NUM(F_TEST));
|
35
33
|
rb_define_singleton_method(cLockf, "lockf", lockf_lock, 3);
|
36
34
|
}
|
data/lib/lockf/version.rb
CHANGED
data/lib/lockf.rb
CHANGED
data/lockf.rb.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.files = `git ls-files`.split($/)
|
11
11
|
gem.require_paths = ["lib"]
|
12
12
|
gem.extensions = %w[ext/lockf.rb/extconf.rb]
|
13
|
-
gem.summary = "
|
13
|
+
gem.summary = "Ruby bindings for lockf(3)"
|
14
14
|
gem.description = gem.summary
|
15
15
|
gem.add_development_dependency "yard", "~> 0.9"
|
16
16
|
gem.add_development_dependency "redcarpet", "~> 3.5"
|
data/test/lock_file_test.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require_relative "setup"
|
2
2
|
class LockFile::Test < Test::Unit::TestCase
|
3
|
-
|
4
|
-
include FileUtils
|
3
|
+
attr_reader :file
|
5
4
|
attr_reader :lockf
|
6
5
|
|
7
6
|
def setup
|
7
|
+
@file = Tempfile.new("lockf-test").tap(&:unlink)
|
8
8
|
@lockf = LockFile.new(file)
|
9
9
|
end
|
10
10
|
|
@@ -13,7 +13,7 @@ class LockFile::Test < Test::Unit::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
##
|
16
|
-
# Lock::File#lock
|
16
|
+
# Lock::File#lock
|
17
17
|
def test_lock
|
18
18
|
assert_equal 0, lockf.lock
|
19
19
|
ensure
|
@@ -21,19 +21,16 @@ class LockFile::Test < Test::Unit::TestCase
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_lock_in_fork
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
sleep(1)
|
28
|
-
}
|
29
|
-
rescue Interrupt
|
30
|
-
assert_raises(Timeout::Error) { timeout(0.5) { lockf.lock } }
|
24
|
+
pid = fork_sleep { lockf.lock }
|
25
|
+
sleep(0.1)
|
26
|
+
assert_raises(Errno::EWOULDBLOCK) { lockf.lock_nonblock }
|
31
27
|
ensure
|
28
|
+
Process.kill("KILL", pid)
|
32
29
|
lockf.release
|
33
30
|
end
|
34
31
|
|
35
32
|
##
|
36
|
-
# Lock::File#lock_nonblock
|
33
|
+
# Lock::File#lock_nonblock
|
37
34
|
def test_lock_nonblock
|
38
35
|
assert_equal 0, lockf.lock_nonblock
|
39
36
|
ensure
|
@@ -41,52 +38,41 @@ class LockFile::Test < Test::Unit::TestCase
|
|
41
38
|
end
|
42
39
|
|
43
40
|
def test_lock_nonblock_in_fork
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
sleep(1)
|
48
|
-
}
|
49
|
-
rescue Interrupt
|
50
|
-
assert_raises(Errno::EAGAIN) { lockf.lock_nonblock }
|
41
|
+
pid = fork_sleep { lockf.lock_nonblock }
|
42
|
+
sleep(0.1)
|
43
|
+
assert_raises(Errno::EWOULDBLOCK) { lockf.lock_nonblock }
|
51
44
|
ensure
|
45
|
+
Process.kill("KILL", pid)
|
52
46
|
lockf.release
|
53
47
|
end
|
54
48
|
|
55
49
|
##
|
56
|
-
# Lock::File#locked?
|
50
|
+
# Lock::File#locked?
|
57
51
|
def test_locked?
|
58
|
-
lockf.lock
|
59
|
-
|
60
|
-
assert_equal
|
52
|
+
pid = fork_sleep { lockf.lock }
|
53
|
+
sleep(0.1)
|
54
|
+
assert_equal true, lockf.locked?
|
61
55
|
ensure
|
56
|
+
Process.kill("KILL", pid)
|
62
57
|
lockf.release
|
63
58
|
end
|
64
59
|
|
65
60
|
##
|
66
|
-
# LockFile
|
67
|
-
def
|
68
|
-
|
69
|
-
touch(path)
|
70
|
-
lockf = LockFile.new(path)
|
61
|
+
# LockFile.temporary_file
|
62
|
+
def test_temporary_file
|
63
|
+
lockf = LockFile.temporary_file
|
71
64
|
assert_equal 0, lockf.lock
|
72
65
|
assert_equal 0, lockf.release
|
73
66
|
ensure
|
74
67
|
lockf.file.close
|
75
|
-
rm(path)
|
76
|
-
end
|
77
|
-
|
78
|
-
##
|
79
|
-
# LockFile.from_temporary_file
|
80
|
-
def test_from_temporary_file
|
81
|
-
lockf = LockFile.from_temporary_file
|
82
|
-
assert_equal 0, lockf.lock
|
83
|
-
assert_equal 0, lockf.release
|
84
|
-
lockf.file.close
|
85
68
|
end
|
86
69
|
|
87
70
|
private
|
88
71
|
|
89
|
-
def
|
90
|
-
|
72
|
+
def fork_sleep
|
73
|
+
fork do
|
74
|
+
yield
|
75
|
+
sleep
|
76
|
+
end
|
91
77
|
end
|
92
78
|
end
|
data/test/setup.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lockf.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '0x1eef'
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
@@ -136,7 +136,7 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0.4'
|
139
|
-
description:
|
139
|
+
description: Ruby bindings for lockf(3)
|
140
140
|
email:
|
141
141
|
- 0x1eef@protonmail.com
|
142
142
|
executables: []
|
@@ -190,5 +190,5 @@ requirements: []
|
|
190
190
|
rubygems_version: 3.5.3
|
191
191
|
signing_key:
|
192
192
|
specification_version: 4
|
193
|
-
summary:
|
193
|
+
summary: Ruby bindings for lockf(3)
|
194
194
|
test_files: []
|