Skip to content

Commit 73c4d15

Browse files
author
root
committed
Temporary patch for Grack with Ruby 1.9.3
1 parent 20198b1 commit 73c4d15

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

Diff for: lib/grack/server.rb

+46
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,52 @@
11
module Grack
22
class Server
33

4+
#
5+
# Override original *service_rpc* method to fix compatibility with Ruby 1.9.3 IO.popen.
6+
#
7+
# Between Ruby 1.9 and Ruby 2.0 the method signature has changed :
8+
# Ruby 1.9.x : popen(cmd, mode="r" [, opt])
9+
# Ruby 2.x : popen([env,] cmd, mode="r" [, opt])
10+
#
11+
# Hence we need to remove the *popen_env* hash from IO.popen args.
12+
#
13+
# See :
14+
# - https://github.com/jbox-web/redmine_git_hosting/issues/345
15+
# - http://ruby-doc.org//core-1.9.3/IO.html#method-c-popen
16+
# - http://ruby-doc.org//core-2.1.0/IO.html#method-c-popen
17+
#
18+
# Notes :
19+
# Given that some people use the Debian package to install Redmine which depends on Ruby 1.9.3
20+
# this patch will stay until the release of Debian Jessie which will provide Ruby 2.1 .
21+
# You're still strongly encouraged to move to Ruby 2.x .
22+
#
23+
if RUBY_VERSION.split('.')[0] == '1'
24+
def service_rpc
25+
return render_no_access if !has_access(@rpc, true)
26+
input = read_body
27+
28+
@res = Rack::Response.new
29+
@res.status = 200
30+
@res["Content-Type"] = "application/x-git-%s-result" % @rpc
31+
@res["Transfer-Encoding"] = "chunked"
32+
@res["Cache-Control"] = "no-cache"
33+
34+
@res.finish do
35+
command = git_command(%W(#{@rpc} --stateless-rpc #{@dir}))
36+
IO.popen(command, File::RDWR, popen_options) do |pipe|
37+
pipe.write(input)
38+
pipe.close_write
39+
while !pipe.eof?
40+
block = pipe.read(8192) # 8KB at a time
41+
@res.write encode_chunk(block) # stream it to the client
42+
end
43+
@res.write terminating_chunk
44+
end
45+
end
46+
end
47+
end
48+
49+
450
#
551
# Override original *get_git_dir* method because the path is relative
652
# and accessed via Sudo.

0 commit comments

Comments
 (0)