diff -ur tar2rubyscript-0.3.4.tar.gz/tar2rubyscript/ev/oldandnewlocation.rb tar2rubyscript-0.3.5.tar.gz/tar2rubyscript/ev/oldandnewlocation.rb --- tar2rubyscript-0.3.4.tar.gz/tar2rubyscript/ev/oldandnewlocation.rb 2003-10-23 23:15:17.000000000 +0200 +++ tar2rubyscript-0.3.5.tar.gz/tar2rubyscript/ev/oldandnewlocation.rb 2003-10-29 16:44:50.000000000 +0100 @@ -1,39 +1,42 @@ -def oldlocation(file="") - if ENV.include?("OLDDIR") +ENV["OLDDIR"] = Dir.pwd if not ENV.include?("OLDDIR") +ENV["NEWDIR"] = Dir.pwd if not ENV.include?("NEWDIR") + +begin + oldlocation +rescue NameError + def oldlocation(file="") dir = ENV["OLDDIR"] - else - dir = "." - end - if block_given? - pdir = Dir.pwd + if block_given? + pdir = Dir.pwd - Dir.chdir(dir) - res = yield - Dir.chdir(pdir) - else - res = File.expand_path(file, dir) if not file.nil? - end + Dir.chdir(dir) + res = yield + Dir.chdir(pdir) + else + res = File.expand_path(file, dir) if not file.nil? + end - res + res + end end -def newlocation(file="") - if ENV.include?("NEWDIR") +begin + newlocation +rescue NameError + def newlocation(file="") dir = ENV["NEWDIR"] - else - dir = "." - end - if block_given? - pdir = Dir.pwd + if block_given? + pdir = Dir.pwd - Dir.chdir(dir) - res = yield - Dir.chdir(pdir) - else - res = File.expand_path(file, dir) if not file.nil? - end + Dir.chdir(dir) + res = yield + Dir.chdir(pdir) + else + res = File.expand_path(file, dir) if not file.nil? + end - res + res + end end diff -ur tar2rubyscript-0.3.4.tar.gz/tar2rubyscript/init.rb tar2rubyscript-0.3.5.tar.gz/tar2rubyscript/init.rb --- tar2rubyscript-0.3.4.tar.gz/tar2rubyscript/init.rb 2003-10-19 19:16:01.000000000 +0200 +++ tar2rubyscript-0.3.5.tar.gz/tar2rubyscript/init.rb 2003-10-29 15:06:30.000000000 +0100 @@ -12,12 +12,12 @@ tarfile.dup.gsub!(/[\/\\]$/, "") if not FileTest.exist?(tarfile) - puts "#{tarfile} doesn´t exist." + $stderr.puts "#{tarfile} doesn´t exist." exit end if not licensefile.nil? and not FileTest.file?(licensefile) - puts "#{licensefile} doesn´t exist." + $stderr.puts "#{licensefile} doesn´t exist." exit end @@ -36,12 +36,12 @@ Dir.chdir(tarfile) if FileTest.file?("tar2rubyscript.bat") - puts "\".\\tar2rubyscript.bat\"" + $stderr.puts "\".\\tar2rubyscript.bat\"" system(".\\tar2rubyscript.bat") end if FileTest.file?("tar2rubyscript.sh") - puts "\". ./tar2rubyscript.sh\"" + $stderr.puts "\". ./tar2rubyscript.sh\"" system("sh -c \". ./tar2rubyscript.sh\"") end diff -ur tar2rubyscript-0.3.4.tar.gz/tar2rubyscript/tarrubyscript.rb tar2rubyscript-0.3.5.tar.gz/tar2rubyscript/tarrubyscript.rb --- tar2rubyscript-0.3.4.tar.gz/tar2rubyscript/tarrubyscript.rb 2003-10-22 18:52:06.000000000 +0200 +++ tar2rubyscript-0.3.5.tar.gz/tar2rubyscript/tarrubyscript.rb 2003-10-28 22:47:30.000000000 +0100 @@ -19,6 +19,7 @@ # Tar2RubyScript constants JustExtract = ARGV.include?("--tar2rubyscript-justextract") +ToTar = ARGV.include?("--tar2rubyscript-totar") ARGV.concat [] @@ -41,8 +42,12 @@ UNAMELEN = 32 GNAMELEN = 32 DEVLEN = 8 + TMAGIC = ´ustar´ GNU_TMAGIC = ´ustar ´ +SOLARIS_TMAGIC = ´ustar00´ + +MAGICS = [TMAGIC, GNU_TMAGIC, SOLARIS_TMAGIC] LF_OLDFILE = ´\0´ LF_FILE = ´0´ @@ -157,7 +162,7 @@ raise "Couldn´t determine a real value for a field (#{field})" end - raise "Magic header value ´#{@magic}´ is invalid." if @magic != TMAGIC and @magic != GNU_TMAGIC + raise "Magic header value ´#{@magic}´ is invalid." if not MAGICS.include?(@magic) @linkflag = LF_FILE if @linkflag == LF_OLDFILE or @linkflag == LF_CONTIG @linkflag = LF_DIR if @name[-1] == ´/´ and @linkflag == LF_FILE @@ -184,10 +189,12 @@ @tempdir = "#{temp}/tar2rubyscript.d.#{Process.pid}" @tempfile = "#{temp}/tar2rubyscript.f.#{Process.pid}" + @@tempspace = self + @newdir=@tempdir end - def run + def extract Dir.mkdir(@tempdir) if not FileTest.exists?(@tempdir) newlocation do @@ -233,14 +240,6 @@ recursivedelete(@tempfile) recursivedelete(@tempdir) end - - # Execute init.rb . - - newlocation do - File.open("init.rb") do |f| - instance_eval(f.read) - end - end end def recursivedelete(entry) @@ -288,6 +287,22 @@ res end + + def self.oldlocation(file="") + if block_given? + @@tempspace.oldlocation { yield } + else + @@tempspace.oldlocation(file) + end + end + + def self.newlocation(file="") + if block_given? + @@tempspace.newlocation { yield } + else + @@tempspace.newlocation(file) + end + end end class Extract @@ -300,24 +315,51 @@ def extract begin - - # Create the temp environment. - File.open(@tempfile, "wb") {|f| f.write @archive} File.open(@tempfile, "rb") {|f| Reader.new(f).extract} - ensure + File.delete(@tempfile) + end + end +end - # Remove the temp environment. +class MakeTar + def initialize + @archive = File.new($0, "rb").read.gsub(/\r/, "").split(/\n\n/)[-1].split("\n").collect{|s| s[2..-1]}.join("\n").unpack("m").shift + @tarfile = $0.gsub(/\.rb$/, ".tar") + end - File.delete(@tempfile) + def extract + File.open(@tarfile, "wb") {|f| f.write @archive} + end +end - end +def oldlocation(file="") + if block_given? + TempSpace.oldlocation { yield } + else + TempSpace.oldlocation(file) + end +end + +def newlocation(file="") + if block_given? + TempSpace.newlocation { yield } + else + TempSpace.newlocation(file) end end if JustExtract Extract.new.extract else - TempSpace.new.run + if ToTar + MakeTar.new.extract + else + TempSpace.new.extract + + newlocation do + load "init.rb" + end + end end