Skip to content

Commit

Permalink
Fix .gem file permissions problem.
Browse files Browse the repository at this point in the history
Tempfile.new makes files with permissions of 0600[1]. This means that if
the webserver is running as a different user, the newly uploaded .gem
file won't be readable. This patch adds a chmod to the atomicwrite
function.

1: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/tempfile/rdoc/Tempfile.html#method-c-new
  • Loading branch information
sw17ch authored and tomlea committed Oct 26, 2012
1 parent 3039992 commit 8701560
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/geminabox.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Geminabox < Sinatra::Base
set :incremental_updates, false set :incremental_updates, false
set :views, File.join(File.dirname(__FILE__), *%w[.. views]) set :views, File.join(File.dirname(__FILE__), *%w[.. views])
set :allow_replace, false set :allow_replace, false
set :gem_permissions, 0644
use Hostess use Hostess


class << self class << self
Expand Down Expand Up @@ -215,6 +216,7 @@ def atomic_write(file_name)
yield temp_file yield temp_file
temp_file.close temp_file.close
File.rename(temp_file.path, file_name) File.rename(temp_file.path, file_name)
File.chmod(settings.gem_permissions, file_name)
end end


helpers do helpers do
Expand Down
8 changes: 7 additions & 1 deletion test/test_support/geminabox_test_case.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def data(data = nil)
@data ||= data || "/tmp/geminabox-test-data" @data ||= data || "/tmp/geminabox-test-data"
end end


def gem_permissions
0644
end

def app(&block) def app(&block)
@app = block || @app || lambda{|builder| run Geminabox } @app = block || @app || lambda{|builder| run Geminabox }
end end
Expand All @@ -41,7 +45,9 @@ def to_app
def should_push_gem(gemname = :example, *args) def should_push_gem(gemname = :example, *args)
test("can push #{gemname}") do test("can push #{gemname}") do
assert_can_push(gemname, *args) assert_can_push(gemname, *args)
assert File.exists?( File.join(config.data, "gems", File.basename(gem_file(gemname, *args)) ) ), "Gemfile not in data dir." gem_path = File.join(config.data, "gems", File.basename(gem_file(gemname, *args)) )
assert File.exists?( gem_path ), "Gemfile not in data dir."
assert File.stat(gem_path).mode.to_s(8).match(/#{config.gem_permissions.to_s(8)}$/), "Gemfile has incorrect permissions."
end end
end end


Expand Down

0 comments on commit 8701560

Please sign in to comment.