[Xfce4-commits] <eatmonkey:aria2-xml-rpc> Add backward compatibility for Ruby 1.8

Mike Massonnet noreply at xfce.org
Sat Feb 6 19:16:01 CET 2010


Updating branch refs/heads/aria2-xml-rpc
         to 7f672e1e19dfed24056a92be0492225f38e7c776 (commit)
       from 8697a249f0795e1e83fac26e621b28aa694f628d (commit)

commit 7f672e1e19dfed24056a92be0492225f38e7c776
Author: Mike Massonnet <mmassonnet at gmail.com>
Date:   Sat Feb 6 15:02:03 2010 +0100

    Add backward compatibility for Ruby 1.8
    
    The two last "Replace" commits are reverted by this commit. The new file
    compat18.rb adds methods that only exist in Ruby 1.9.

 src/Makefile.am    |    1 +
 src/compat18.rb    |   22 ++++++++++++++++++++++
 src/eataria2.rb    |   14 +++-----------
 src/eatsettings.rb |    3 ++-
 4 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index b1a0820..2796773 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -36,6 +36,7 @@
 
 eatmonkeydir = $(datadir)/eatmonkey
 dist_eatmonkey_SCRIPTS =						\
+	compat18.rb							\
 	config.rb							\
 	eat.rb								\
 	eataria2.rb							\
diff --git a/src/compat18.rb b/src/compat18.rb
new file mode 100644
index 0000000..6a2b1c7
--- /dev/null
+++ b/src/compat18.rb
@@ -0,0 +1,22 @@
+class Array
+	def find_index(idx)
+		index(idx)
+	end
+end
+
+class Dir
+	def exists?(path)
+		File.directory?(path)
+	end
+end
+
+def Process::spawn(command, *)
+	pid = fork do
+		FileUtils.chdir(ENV['HOME'])
+		STDOUT.reopen('/dev/null')
+		STDIN.reopen('/dev/null')
+		Process.setpgid(0, 0)
+		exec command
+	end
+	pid
+end
diff --git a/src/eataria2.rb b/src/eataria2.rb
index 22eede6..0682f46 100644
--- a/src/eataria2.rb
+++ b/src/eataria2.rb
@@ -8,6 +8,7 @@ require "thread"
 require "pp"
 
 require "config"
+require "compat18"
 require "glib2"
 
 def debug(*args)
@@ -127,17 +128,8 @@ class Eat::Aria2 < GLib::Object
 					"--enable-xml-rpc --xml-rpc-listen-port=#{@port} " \
 					"--conf-path=#{@confdir}/aria2.conf --log=#{@confdir}/aria2.log --log-level=notice " \
 					"--dht-file-path=#{@confdir}/dht.dat"
-				##Ruby 1.8.x
-				@@pid = fork do
-					FileUtils.chdir(ENV['HOME'])
-					STDOUT.reopen('/dev/null')
-					STDIN.reopen('/dev/null')
-					Process.setpgid(0, 0)
-					exec command
-				end
-				##Ruby 1.9.x
-				#@@pid = Process.spawn(command, :pgroup=>true, :chdir=>ENV['HOME'],
-				#		STDOUT=>"/dev/null", STDIN=>"/dev/null")
+				@@pid = Process.spawn(command, :pgroup=>true, :chdir=>ENV['HOME'],
+						STDOUT=>"/dev/null", STDIN=>"/dev/null")
 				Process.detach(@@pid)
 				debug("started server", command, @@pid)
 				# Wait for the server to respond properly to requests
diff --git a/src/eatsettings.rb b/src/eatsettings.rb
index 08c3c1f..1e38d93 100644
--- a/src/eatsettings.rb
+++ b/src/eatsettings.rb
@@ -4,6 +4,7 @@ require "gtk2"
 require "singleton"
 
 require "config"
+require "compat18"
 require "eataria2"
 
 include Gtk
@@ -48,7 +49,7 @@ class Eat::Settings
 
 				if dir != nil
 					@aria2["dir"] = dir
-				elsif File.directory?(ENV["HOME"]+"/Downloads")
+				elsif Dir.exists?(ENV["HOME"]+"/Downloads")
 					@aria2["dir"] = ENV["HOME"]+"/Downloads"
 				else
 					@aria2["dir"] = ENV["HOME"]



More information about the Xfce4-commits mailing list