lockf.rb 2.0.0 → 2.1.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: 2a49042a4d79251c0a85dbe626fefaa323862ea30a45426012a1d8bab08f63fb
4
- data.tar.gz: 57f2c700f963a299ce4502e3a7856cc75283ceb80d1c27864ea08438950047d5
3
+ metadata.gz: b0f68d54d3ad30fc3c9c6316910adebcd74645876546aec01c86402261275ff6
4
+ data.tar.gz: ed9cbe6b94840dd3987d16825737b3e98c42efb4904f15fd2ef206ebd0ab431a
5
5
  SHA512:
6
- metadata.gz: 7d5c94dbaa6ad0b2eff1fe114e902d7c49014f2bb0ce69b2c5512ae0d107274d7c3c8b6a2d688672faeb85c7b48510689952efd9c64dc4cc78616e3e566f2e8e
7
- data.tar.gz: 27c55d59bbab2f8e76b5370b010b3541d65a346b88279361e7f64110b3e6a1fe3f1ddaf4677fbefcec7f2e6409d70483937298f47cda1e3d729c209122d821df
6
+ metadata.gz: 663fb2919e2560b75307ce6ea01291582e61fca0fa14f9c86f54dfd7ab598a2301b361be09952800a93089a5010f53dcd8ee76870ba1cc44ff7470ef1295abb0
7
+ data.tar.gz: a249a8c95037378796bbc8cb4fd3224da60137117902ac189546860791bfa9b1256a26636895762ffbcd3a74037e4bb38c26d6aefe57721ca6d603a0022f1128
@@ -11,8 +11,8 @@ jobs:
11
11
  strategy:
12
12
  fail-fast: false
13
13
  matrix:
14
- os: [ubuntu-latest]
15
- ruby: [3.2]
14
+ os: [ubuntu-latest, macos-latest]
15
+ ruby: [3.2, 3.3]
16
16
  runs-on: ${{ matrix.os }}
17
17
  steps:
18
18
  - uses: actions/checkout@v2
@@ -20,4 +20,4 @@ jobs:
20
20
  with:
21
21
  ruby-version: ${{ matrix.ruby }}
22
22
  - run: bundle install
23
- - run: bundle exec rake
23
+ - run: ruby -S rake ci
data/.gitignore CHANGED
@@ -1,10 +1,4 @@
1
- *.so
2
- *.o
3
- *.lock
4
- Makefile
5
- tmp/
6
- pkg/
7
- *~
8
- .yardoc/
9
- .gems/
10
- doc/
1
+ /*.lock
2
+ /.yardoc/
3
+ /.gems/
4
+ /doc/
data/.rubocop.yml CHANGED
@@ -14,6 +14,14 @@ Layout/MultilineMethodCallIndentation:
14
14
  Enabled: false
15
15
  Layout/ArgumentAlignment:
16
16
  Enabled: false
17
+ Layout/MultilineArrayBraceLayout:
18
+ Enabled: false
19
+ Layout/ExtraSpacing:
20
+ Enabled: false
21
+ Style/MultilineIfModifier:
22
+ Enabled: false
23
+ Layout/ArrayAlignment:
24
+ Enabled: false
17
25
 
18
26
  ##
19
27
  # Options for all cops.
@@ -23,3 +31,4 @@ AllCops:
23
31
  - lib/*.rb
24
32
  - lib/**/*.rb
25
33
  - test/*.rb
34
+ - share/lockf.rb/examples/*.rb
data/Rakefile.rb CHANGED
@@ -1,12 +1,20 @@
1
1
  require "bundler/setup"
2
2
 
3
3
  namespace :format do
4
- desc "Run rubocop"
5
- task :ruby do
4
+ desc "Apply rubocop fixes"
5
+ task :apply do
6
6
  sh "bundle exec rubocop -A"
7
7
  end
8
+
9
+ desc "Run rubocop"
10
+ task :check do
11
+ sh "bundle exec rubocop"
12
+ end
8
13
  end
9
- task format: %w[format:ruby]
14
+ task format: %w[format:apply]
15
+
16
+ desc "Run CI tasks"
17
+ task ci: %i[format:check test]
10
18
 
11
19
  desc "Run tests"
12
20
  task :test do
data/lib/lock/file/ffi.rb CHANGED
@@ -27,10 +27,18 @@ class Lock::File
27
27
  .zero? || raise(SystemCallError.new("lockf", Fiddle.last_error))
28
28
  end
29
29
 
30
- private
31
-
30
+ ##
31
+ # @return [Fiddle::Handle]
32
32
  def libc
33
- @libc ||= Fiddle.dlopen Dir["/lib/libc.*"].first
33
+ @libc ||= begin
34
+ globs = %w[
35
+ /lib/libc.so.*
36
+ /usr/lib/libc.so.*
37
+ /lib/x86_64-linux-gnu/libc.so.*
38
+ /lib/i386-linux-gnu/libc.so.*
39
+ ]
40
+ Fiddle.dlopen(Dir[*globs].first)
41
+ end
34
42
  end
35
43
  end
36
44
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Lock::File
4
- VERSION = "2.0.0"
4
+ VERSION = "2.1.0"
5
5
  end
data/lib/lock/file.rb CHANGED
@@ -6,7 +6,6 @@ end unless defined?(Lock)
6
6
  # [lockf(3)](https://man.freebsd.org/cgi/man.cgi?query=lockf&sektion=3)
7
7
  # interface
8
8
  class Lock::File
9
- require "tmpdir"
10
9
  require_relative "file/version"
11
10
  require_relative "file/ffi"
12
11
  require_relative "file/constants"
@@ -15,23 +14,19 @@ class Lock::File
15
14
  include Constants
16
15
 
17
16
  ##
17
+ # Accepts the same parameters as Tempfile.new
18
+ #
18
19
  # @example
19
20
  # lockf = Lock::File.temporary_file
20
21
  # lockf.lock
21
22
  # # ...
22
23
  #
23
- # @param [String] basename
24
- # @param [String] tmpdir
25
24
  # @return [Lock::File]
26
25
  # Returns a {Lock::File Lock::File} for a random,
27
26
  # unlinked temporary file
28
- def self.from_temporary_file(basename: "lockf", tmpdir: Dir.tmpdir)
27
+ def self.temporary_file(...)
29
28
  require "tempfile" unless defined?(Tempfile)
30
- file = Tempfile.new(basename, tmpdir:).tap(&:unlink)
31
- Lock::File.new(file)
32
- end
33
- class << self
34
- alias_method :temporary_file, :from_temporary_file
29
+ Lock::File.new Tempfile.new(...).tap(&:unlink)
35
30
  end
36
31
 
37
32
  ##
@@ -62,7 +57,7 @@ class Lock::File
62
57
  lockf(@file, F_LOCK, @size)
63
58
  rescue Errno::EINTR => ex
64
59
  tries += 1
65
- tries == 3 ? raise(ex) : retry
60
+ (tries == 3) ? raise(ex) : retry
66
61
  end
67
62
 
68
63
  ##
data/lockf.rb.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
14
14
 
15
15
  gem.add_runtime_dependency "fiddle", "~> 1.1"
16
16
  gem.add_development_dependency "yard", "~> 0.9"
17
- gem.add_development_dependency "standard", "~> 1.12"
17
+ gem.add_development_dependency "standard", "~> 1.39"
18
18
  gem.add_development_dependency "rubocop", "~> 1.29"
19
19
  gem.add_development_dependency "test-unit", "~> 3.5"
20
20
  gem.add_development_dependency "test-cmd.rb", "~> 0.12"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative "setup"
3
4
 
4
5
  class Lock::File::Test < Test::Unit::TestCase
data/test/readme_test.rb CHANGED
@@ -5,29 +5,29 @@ require "test/cmd"
5
5
 
6
6
  class Lock::File::ReadmeTest < Test::Unit::TestCase
7
7
  def test_lockfile_blocking_variant
8
- r = ruby(readme_example("1_lockfile_blocking_variant.rb"))
9
- ["Lock acquired by parent process \(.+\)\n",
10
- "Child process waiting on lock \(.+\)\n",
11
- "Lock acquired by child process \(.+\)\n"
8
+ r = ruby(readme_example("1_lock_file_blocking_variant.rb"))
9
+ ["Lock acquired by parent process (.+)\n",
10
+ "Child process waiting on lock (.+)\n",
11
+ "Lock acquired by child process (.+)\n"
12
12
  ].each { assert_match Regexp.new(_1), r.stdout }
13
13
  end
14
14
 
15
15
  def test_lockfile_nonblocking_variant
16
- r = ruby(readme_example("2_lockfile_nonblocking_variant.rb"))
17
- ["Lock acquired by parent process \(.+\)\n",
16
+ r = ruby(readme_example("2_lock_file_nonblocking_variant.rb"))
17
+ ["Lock acquired by parent process (.+)\n",
18
18
  "(Lock would block\n){3,4}",
19
- "Lock acquired by child process \(.+\)\n"
19
+ "Lock acquired by child process (.+)\n"
20
20
  ].each { assert_match Regexp.new(_1), r.stdout }
21
21
  end
22
22
 
23
23
  def test_ffi_lockf_blocking_variant
24
24
  assert_equal "Lock acquired\nLock released\n",
25
- ruby(readme_example("3_ffilockf_blocking_variant.rb")).stdout
25
+ ruby(readme_example("3_ffi_lockf_blocking_variant.rb")).stdout
26
26
  end
27
27
 
28
28
  def test_ffi_lockf_nonblocking_variant
29
29
  assert_equal "Lock acquired\nLock released\n",
30
- ruby(readme_example("4_ffilockf_nonblocking_variant.rb")).stdout
30
+ ruby(readme_example("4_ffi_lockf_nonblocking_variant.rb")).stdout
31
31
  end
32
32
 
33
33
  private
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: 2.0.0
4
+ version: 2.1.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-06-28 00:00:00.000000000 Z
11
+ date: 2024-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fiddle
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.12'
47
+ version: '1.39'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.12'
54
+ version: '1.39'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -102,12 +102,10 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - ".bundle/config"
105
- - ".clang-format"
106
105
  - ".github/workflows/tests.yml"
107
106
  - ".gitignore"
108
107
  - ".projectile"
109
108
  - ".rubocop.yml"
110
- - ".uncrustify.cfg"
111
109
  - ".yardopts"
112
110
  - Gemfile
113
111
  - LICENSE
@@ -121,10 +119,10 @@ files:
121
119
  - lib/lockf.rb
122
120
  - lib/lockfile.rb
123
121
  - lockf.rb.gemspec
124
- - share/lockf.rb/examples/1_lockfile_blocking_variant.rb
125
- - share/lockf.rb/examples/2_lockfile_nonblocking_variant.rb
126
- - share/lockf.rb/examples/3_ffilockf_blocking_variant.rb
127
- - share/lockf.rb/examples/4_ffilockf_nonblocking_variant.rb
122
+ - share/lockf.rb/examples/1_lock_file_blocking_variant.rb
123
+ - share/lockf.rb/examples/2_lock_file_nonblocking_variant.rb
124
+ - share/lockf.rb/examples/3_ffi_lockf_blocking_variant.rb
125
+ - share/lockf.rb/examples/4_ffi_lockf_nonblocking_variant.rb
128
126
  - test/lock_file_test.rb
129
127
  - test/readme_test.rb
130
128
  - test/setup.rb
data/.clang-format DELETED
@@ -1,11 +0,0 @@
1
- BasedOnStyle: LLVM
2
- IndentWidth: 2
3
- SortIncludes: false
4
- UseTab: Never
5
- BreakBeforeBraces: Allman
6
- AllowShortFunctionsOnASingleLine: Inline
7
- AlwaysBreakAfterDefinitionReturnType: TopLevel
8
- BreakBeforeBinaryOperators: All
9
- BinPackArguments: false
10
- AlignConsecutiveAssignments: true
11
- AlwaysBreakAfterReturnType: None
data/.uncrustify.cfg DELETED
@@ -1,2 +0,0 @@
1
- indent_with_tabs = 0
2
- indent_columns = 4