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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc7a6787621983c5bcea9dc35a899eb064d8d09f20d905b90b8391e8fc018f64
4
- data.tar.gz: e32dcc7d52786b2c1c2acdb652264b450506debd976583a2ff8f46a367b2efe9
3
+ metadata.gz: 07acab1cbd6394d179fafd3fed888bdb56f7bc52868a8557a6b2114500a409ca
4
+ data.tar.gz: '0178e4e393991e7b3ab099ba2491aa7888fb30e1f096d785d4797f6bbb30a048'
5
5
  SHA512:
6
- metadata.gz: b275ee5e97c06f6dfcfbf32074139b1514b3fe4795ab1669bdbb188336f0039aee368846146b6e4b6ef15fc41d0077816844cfcf772e52039584b5816d5e8cbb
7
- data.tar.gz: ffab08187b049fd42ad5549e060c0ba5da31228212c1e5419c3c9640a8842c96617a20cd54ee6f14edc265a5b28ddf50bc00e8dc343493fce0ec6a96a388a3cb
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 is a C extension that provides a Ruby interface to
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 be used to synchronize access to a file between multiple
12
- processes, or be used more generally to synchronize access to a shared
13
- resource being accessed by multiple processes at the same time. When used
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
- lock.rb can also be installed via rubygems.org.
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
@@ -1,3 +1,4 @@
1
+ require "bundler/setup"
1
2
  require "rake/extensiontask"
2
3
  require "rake/testtask"
3
4
 
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 == -1) {
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, mFcntl;
26
+ VALUE cLockf;
27
27
 
28
- rb_require("fcntl");
29
28
  cLockf = rb_define_class("LockFile", rb_cObject);
30
- mFcntl = rb_const_get(rb_cObject, rb_intern("Fcntl"));
31
- rb_define_const(mFcntl, "F_LOCK", INT2NUM(F_LOCK));
32
- rb_define_const(mFcntl, "F_TLOCK", INT2NUM(F_TLOCK));
33
- rb_define_const(mFcntl, "F_ULOCK", INT2NUM(F_ULOCK));
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
@@ -1,3 +1,3 @@
1
1
  class LockFile
2
- VERSION = "0.12.0"
2
+ VERSION = "0.13.0"
3
3
  end
data/lib/lockf.rb CHANGED
@@ -6,7 +6,6 @@
6
6
  class LockFile
7
7
  require "tmpdir"
8
8
  require_relative "lockf.rb.so"
9
- include Fcntl
10
9
 
11
10
  ##
12
11
  # @!method self.lockf(fd, cmd, len)
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 = "A Ruby interface for lockf(3)"
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"
@@ -1,10 +1,10 @@
1
1
  require_relative "setup"
2
2
  class LockFile::Test < Test::Unit::TestCase
3
- include Timeout
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 tests
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
- Process.wait fork {
25
- lockf.lock
26
- Process.kill("SIGINT", Process.ppid)
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 tests
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
- Process.wait fork {
45
- lockf.lock_nonblock
46
- Process.kill("SIGINT", Process.ppid)
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? tests
50
+ # Lock::File#locked?
57
51
  def test_locked?
58
- lockf.lock
59
- Process.wait fork { lockf.locked? ? exit(0) : exit(1) }
60
- assert_equal 0, $?.exitstatus
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#initialize
67
- def test_initialize_with_str_path
68
- path = File.join(Dir.getwd, "test", "tmp.txt")
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 file
90
- @file ||= Tempfile.new("lockf-test").tap(&:unlink)
72
+ def fork_sleep
73
+ fork do
74
+ yield
75
+ sleep
76
+ end
91
77
  end
92
78
  end
data/test/setup.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  require "bundler/setup"
2
2
  require "test/unit"
3
3
  require "lockf"
4
- require "timeout"
5
- require "fileutils"
6
4
  require "tempfile"
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.12.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-01-06 00:00:00.000000000 Z
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: A Ruby interface for lockf(3)
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: A Ruby interface for lockf(3)
193
+ summary: Ruby bindings for lockf(3)
194
194
  test_files: []