lib/rio/scheme/temp.rb in rio-0.5.1 vs lib/rio/scheme/temp.rb in rio-0.6.0

- old
+ new

@@ -1,8 +1,8 @@ #-- # =========================================================================== -# Copyright (c) 2005-2012 Christopher Kleckner +# Copyright (c) 2005-2017 Christopher Kleckner # All rights reserved # # This file is part of the Rio library for ruby. # # Rio is free software; you can redistribute it and/or modify @@ -32,32 +32,27 @@ class RRL < ::RIO::RRL::Base RIOSCHEME = 'temp' RIOPATH = RIO::RRL::CHMAP.invert[RIOSCHEME].to_s.freeze DFLT_PREFIX = 'rio' DFLT_TMPDIR = ::Dir::tmpdir - # p 'DFLT_TMPDIR=' + DFLT_TMPDIR def initialize(u,file_prefix=DFLT_PREFIX,temp_dir=DFLT_TMPDIR) - # p "Temp::RRL::initialize u=#{u} file_prefix=#{file_prefix} temp_dir=#{temp_dir}" - # puts "Temp::RRL CALLER: ",caller[0..8] alturi = case u when ::Alt::URI::Base then u else ::Alt::URI.parse(u.to_s) end prefix = alturi.query || file_prefix.to_s tmpdir = (alturi.path.nil? || alturi.path.empty?) ? temp_dir.to_s : alturi.path - #alturi = ::Alt::URI.create(:scheme => 'temp', :path => temp_dir, - # :query => file_prefix) - # p 'HERE' super(alturi) - # p "alturi=#{alturi}" self.path = tmpdir self.query = prefix end - extend Forwardable - def_delegators :uri, :path=, :path, :query, :query=, :scheme + extend RIO::Fwd + fwd :uri, :path, :query + fwd_reader :uri, :scheme + alias :prefix :query alias :tmpdir :path end module Dir @@ -69,29 +64,23 @@ DFLT_PREFIX = Temp::RRL::DFLT_PREFIX DFLT_TMPDIR = Temp::RRL::DFLT_TMPDIR def initialize(u,file_prefix=DFLT_PREFIX,temp_dir=DFLT_TMPDIR) require 'rio/tempdir' - # p "Temp::Dir u=#{u.inspect} file_prefix=#{file_prefix} temp_dir=#{temp_dir}" alturi = case u when ::Alt::URI::Base then u else ::Alt::URI.parse(u.to_s) end prefix = alturi.query || file_prefix.to_s tmpdir = (alturi.path.nil? || alturi.path.empty?) ? temp_dir.to_s : alturi.path - #p "Temp::Dir prefix=#{prefix} tmpdir=#{tmpdir}" td = ::Tempdir.new( prefix, tmpdir) - #td = "file:///" + td if td.to_s =~ /^[a-zA-Z]:/ - #p "Temp::Dir td=#{td.to_s.inspect}" td = "file:///" + td.to_s if td.to_s =~ /^[a-zA-Z]:/ super(td.to_s) - #self.query = file_prefix.to_s - #self.path = temp_dir.to_s end - extend Forwardable - def_delegators :uri, :path=, :path, :query, :query= + extend RIO::Fwd + fwd :uri, :path, :query alias :prefix :query alias :tmpdir :path def dir_rl() RIO::Dir::RRL.new(self.uri, {:fs => self.fs}) @@ -106,43 +95,31 @@ DFLT_PREFIX = Temp::RRL::DFLT_PREFIX DFLT_TMPDIR = Temp::RRL::DFLT_TMPDIR def initialize(u,file_prefix=DFLT_PREFIX,temp_dir=DFLT_TMPDIR) require 'tempfile' - #p "Temp::File::initialize u=#{u.inspect} file_prefix=#{file_prefix.inspect} temp_dir=#{temp_dir.inspect}" - # puts "Temp::File CALLER: ",caller[0..8] # FIXME: Temporary fix for jruby 1.4 - make tmpdir absolute #tmpdir_rio = rio(@tmpdir).abs alturi = case u when ::Alt::URI::Base then u else ::Alt::URI.parse(u.to_s) end prefix = alturi.query || file_prefix.to_s tmpdir = (alturi.path.nil? || alturi.path.empty?) ? temp_dir.to_s : alturi.path - # p "Temp::File::initialize alturi=#{alturi} prefix=#{prefix} tmpdir=#{tmpdir}" @tf = ::Tempfile.new( prefix, tmpdir) - #puts "TF=#{@tf.inspect}" - # @tf = ::Tempfile.new( @prefix.to_s, @tmpdir.to_s) - # FIXME: Temporary fix for jruby 1.4 - fix slashes pth = @tf.path pth.gsub!("\\","/") pth = "file:///" + pth if pth =~ /^[a-zA-Z]:/ - #p "PTH=#{pth}" - # @tf = "file:///" + @tf if @tf.to_s =~ /^[a-zA-Z]:/ - # - #p "Temp::File pth=#{pth.inspect}" super(::Alt::URI.parse(pth)) - #self.query = file_prefix - #self.path = temp_dir end - extend Forwardable - def_delegators :uri, :path=, :path, :query, :query= + extend RIO::Fwd + fwd :uri, :path, :query def file_rl() RIO::File::RRL.new(self.uri,{:fs => self.fs}) end def open(mode='ignored') @tf @@ -155,26 +132,21 @@ end require 'rio/state' class Reset < State::Base def initialize(*args) super - #p args @tempobj = nil end def self.default_cx Cx::Vars.new( { 'closeoneof' => false, 'closeoncopy' => false } ) end def check?() true end def mkdir(prefix=rl.prefix,tmpdir=rl.tmpdir) - # p "scheme/temp.rb mkdir(): prefix="+prefix+" tmpdir="+tmpdir self.rl = RIO::Temp::Dir::RRL.new("",prefix, tmpdir) become 'Dir::Existing' end -# def mkdir() -# dir() -# end def chdir(&block) self.mkdir.chdir(&block) end def file(prefix=rl.prefix,tmpdir=rl.tmpdir) # p "scheme/temp.rb file(): prefix="+prefix+" tmpdir="+tmpdir @@ -203,9 +175,8 @@ class Open < RIO::Stream::Open def iostate(sym) mode_('w+').open_.inout() end end - end end end