geminabox 0.13.7 → 0.13.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of geminabox might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f1cc2305f829d0ff68bf003b811a607d82855e7
4
- data.tar.gz: 7ec369626b576f2691ccf9cf3693def204371326
3
+ metadata.gz: 3eaa4ca96116f65f67fbd223581a5172bc96cc19
4
+ data.tar.gz: da0a1c599120be2e2ed36e157202df0e8ebacf24
5
5
  SHA512:
6
- metadata.gz: 30452dbbb9099d7e306f4f67dd61ce38a8dd8c7a2df955735eaae20547dcd1d2834a55e753e666f68db2f54256d14d27a75cbd6917dc22f5f67768e47aca570d
7
- data.tar.gz: b347f233d5ee2b9fd09fcda61a7d6950617bcc9e793aad27391f1a18964eaeb4a9099e2b9c32165adef0e02b407200e9b8a5c56ee84c67a2ba752d056e962d2d
6
+ metadata.gz: d101371f803f98e6571bccf297758d8516dc22a2077f3c0875b344141ce9490c3282f9e130afc6eb858486314cfa3a426c6ad9b9f8da6dbd434227a4ce6a8226
7
+ data.tar.gz: c9fd1589eacc2d1f81c461dc10cfce27ffda756295c01a54879cb8dc2f847ca353a274920ad03eaf86d8acb149ec228c0578cccadd1f0ac84e2098fc8ff1b87e
data/lib/geminabox.rb CHANGED
@@ -14,7 +14,6 @@ require 'rack/protection'
14
14
  module Geminabox
15
15
 
16
16
  class Error < StandardError ; end
17
- class AlreadyLocked < Error ; end
18
17
 
19
18
  require_relative 'geminabox/version'
20
19
  require_relative 'geminabox/proxy'
@@ -1,3 +1,5 @@
1
+ require 'reentrant_flock'
2
+
1
3
  module Geminabox
2
4
 
3
5
  class Server < Sinatra::Base
@@ -65,11 +67,11 @@ module Geminabox
65
67
  indexer.update_index
66
68
  updated_gemspecs.each { |gem| dependency_cache.flush_key(gem.name) }
67
69
  rescue Errno::ENOENT
68
- reindex(:force_rebuild)
70
+ with_rlock { reindex(:force_rebuild) }
69
71
  rescue => e
70
72
  puts "#{e.class}:#{e.message}"
71
73
  puts e.backtrace.join("\n")
72
- reindex(:force_rebuild)
74
+ with_rlock { reindex(:force_rebuild) }
73
75
  end
74
76
  end
75
77
  rescue Gem::SystemExitException
@@ -82,8 +84,22 @@ module Geminabox
82
84
  def dependency_cache
83
85
  @dependency_cache ||= Geminabox::DiskCache.new(File.join(data, "_cache"))
84
86
  end
85
- end
86
87
 
88
+ def with_rlock(&block)
89
+ file_class.open(settings.lockfile, File::RDWR | File::CREAT) do |f|
90
+ ReentrantFlock.synchronize(f, File::LOCK_EX | File::LOCK_NB, &block)
91
+ end
92
+ end
93
+
94
+ # This method provides a test hook, as stubbing File is painful...
95
+ def file_class
96
+ @file_class ||= File
97
+ end
98
+
99
+ def file_class=(klass)
100
+ @file_class = klass
101
+ end
102
+ end
87
103
 
88
104
 
89
105
  before do
@@ -185,21 +201,13 @@ module Geminabox
185
201
  private
186
202
 
187
203
  def serialize_update(&block)
188
- with_lock(&block)
189
- rescue AlreadyLocked
204
+ with_rlock(&block)
205
+ rescue ReentrantFlock::AlreadyLocked
190
206
  halt 503, { 'Retry-After' => settings.retry_interval }, 'Repository lock is held by another process'
191
207
  end
192
208
 
193
- def with_lock
194
- file_class.open(settings.lockfile, File::RDWR | File::CREAT) do |f|
195
- raise AlreadyLocked unless f.flock(File::LOCK_EX | File::LOCK_NB)
196
- yield
197
- end
198
- end
199
-
200
- # This method provides a test hook, as stubbing File is painful...
201
- def file_class
202
- File
209
+ def with_rlock(&block)
210
+ self.class.with_rlock(&block)
203
211
  end
204
212
 
205
213
  def handle_incoming_gem(gem)
@@ -1,3 +1,3 @@
1
1
  module Geminabox
2
- VERSION = '0.13.7' unless defined? VERSION
2
+ VERSION = '0.13.8' unless defined? VERSION
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'uri'
2
+ require 'cgi'
2
3
  require 'geminabox'
3
4
 
4
5
  class GeminaboxClient
@@ -12,7 +13,8 @@ class GeminaboxClient
12
13
 
13
14
  def extract_username_and_password_from_url!(url)
14
15
  uri = URI.parse(url.to_s)
15
- @username, @password = uri.user, uri.password
16
+ @username = CGI.unescape(uri.user) if uri.user
17
+ @password = CGI.unescape(uri.password) if uri.password
16
18
  uri.user = uri.password = nil
17
19
  uri.path = uri.path + "/" unless uri.path.end_with?("/")
18
20
  @url = uri.to_s
@@ -39,7 +41,9 @@ end
39
41
 
40
42
  module GeminaboxClient::GemLocator
41
43
  def find_gem(dir)
42
- gemname = File.split(dir).last
44
+ gemspec_path = Dir.glob(File.join(dir, "*.gemspec")).first
45
+ gemspec = Gem::Specification::load(gemspec_path)
46
+ gemname = gemspec.name
43
47
  glob_matcher = "{pkg/,}#{gemname}-*.gem"
44
48
  latest_gem_for(gemname, Dir.glob(glob_matcher)) or raise Gem::CommandLineError, NO_GEM_PROVIDED_ERROR_MESSAGE
45
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geminabox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.7
4
+ version: 0.13.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lea
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-09-22 00:00:00.000000000 Z
14
+ date: 2017-09-23 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: sinatra
@@ -83,6 +83,20 @@ dependencies:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
+ - !ruby/object:Gem::Dependency
87
+ name: reentrant_flock
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :runtime
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
86
100
  description: A sinatra based gem hosting app, with client side gem push style functionality.
87
101
  email:
88
102
  - contrib@tomlea.co.uk