rio 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. data/ChangeLog +140 -0
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/doc/ANNOUNCE +87 -0
  5. data/doc/RELEASE_NOTES +7 -0
  6. data/doc/rdoc/classes/Kernel.html +9 -9
  7. data/doc/rdoc/classes/Kernel.src/{M000183.html → M000182.html} +0 -0
  8. data/doc/rdoc/classes/RIO.html +35 -0
  9. data/doc/rdoc/classes/RIO.src/M000001.html +4 -4
  10. data/doc/rdoc/classes/RIO.src/M000002.html +4 -4
  11. data/doc/rdoc/classes/RIO.src/M000003.html +4 -4
  12. data/doc/rdoc/classes/RIO/Doc/HOWTO.html +11 -7
  13. data/doc/rdoc/classes/RIO/Doc/INTRO.html +255 -36
  14. data/doc/rdoc/classes/RIO/Doc/SYNOPSIS.html +47 -17
  15. data/doc/rdoc/classes/RIO/Rio.html +1032 -1007
  16. data/doc/rdoc/classes/RIO/Rio.src/M000011.html +3 -3
  17. data/doc/rdoc/classes/RIO/Rio.src/M000012.html +3 -3
  18. data/doc/rdoc/classes/RIO/Rio.src/M000013.html +3 -3
  19. data/doc/rdoc/classes/RIO/Rio.src/M000014.html +3 -3
  20. data/doc/rdoc/classes/RIO/Rio.src/M000015.html +3 -3
  21. data/doc/rdoc/classes/RIO/Rio.src/M000016.html +3 -3
  22. data/doc/rdoc/classes/RIO/Rio.src/M000017.html +3 -3
  23. data/doc/rdoc/classes/RIO/Rio.src/M000018.html +3 -3
  24. data/doc/rdoc/classes/RIO/Rio.src/M000019.html +3 -3
  25. data/doc/rdoc/classes/RIO/Rio.src/M000020.html +3 -3
  26. data/doc/rdoc/classes/RIO/Rio.src/M000021.html +3 -3
  27. data/doc/rdoc/classes/RIO/Rio.src/M000022.html +3 -3
  28. data/doc/rdoc/classes/RIO/Rio.src/M000023.html +3 -3
  29. data/doc/rdoc/classes/RIO/Rio.src/M000024.html +3 -3
  30. data/doc/rdoc/classes/RIO/Rio.src/M000025.html +3 -3
  31. data/doc/rdoc/classes/RIO/Rio.src/M000026.html +3 -3
  32. data/doc/rdoc/classes/RIO/Rio.src/M000027.html +3 -3
  33. data/doc/rdoc/classes/RIO/Rio.src/M000028.html +3 -3
  34. data/doc/rdoc/classes/RIO/Rio.src/M000029.html +3 -3
  35. data/doc/rdoc/classes/RIO/Rio.src/M000030.html +3 -3
  36. data/doc/rdoc/classes/RIO/Rio.src/M000031.html +3 -3
  37. data/doc/rdoc/classes/RIO/Rio.src/M000032.html +3 -3
  38. data/doc/rdoc/classes/RIO/Rio.src/M000033.html +3 -3
  39. data/doc/rdoc/classes/RIO/Rio.src/M000034.html +3 -3
  40. data/doc/rdoc/classes/RIO/Rio.src/M000035.html +3 -3
  41. data/doc/rdoc/classes/RIO/Rio.src/M000036.html +3 -3
  42. data/doc/rdoc/classes/RIO/Rio.src/M000037.html +3 -3
  43. data/doc/rdoc/classes/RIO/Rio.src/M000038.html +3 -3
  44. data/doc/rdoc/classes/RIO/Rio.src/M000039.html +3 -3
  45. data/doc/rdoc/classes/RIO/Rio.src/M000040.html +3 -3
  46. data/doc/rdoc/classes/RIO/Rio.src/M000041.html +3 -3
  47. data/doc/rdoc/classes/RIO/Rio.src/M000042.html +3 -3
  48. data/doc/rdoc/classes/RIO/Rio.src/M000043.html +3 -3
  49. data/doc/rdoc/classes/RIO/Rio.src/M000044.html +3 -3
  50. data/doc/rdoc/classes/RIO/Rio.src/M000045.html +3 -3
  51. data/doc/rdoc/classes/RIO/Rio.src/M000046.html +3 -3
  52. data/doc/rdoc/classes/RIO/Rio.src/M000047.html +3 -3
  53. data/doc/rdoc/classes/RIO/Rio.src/M000048.html +3 -3
  54. data/doc/rdoc/classes/RIO/Rio.src/M000049.html +3 -3
  55. data/doc/rdoc/classes/RIO/Rio.src/M000050.html +3 -3
  56. data/doc/rdoc/classes/RIO/Rio.src/M000051.html +3 -3
  57. data/doc/rdoc/classes/RIO/Rio.src/M000052.html +3 -3
  58. data/doc/rdoc/classes/RIO/Rio.src/M000053.html +3 -3
  59. data/doc/rdoc/classes/RIO/Rio.src/M000054.html +3 -3
  60. data/doc/rdoc/classes/RIO/Rio.src/M000055.html +3 -3
  61. data/doc/rdoc/classes/RIO/Rio.src/M000056.html +3 -3
  62. data/doc/rdoc/classes/RIO/Rio.src/M000057.html +3 -3
  63. data/doc/rdoc/classes/RIO/Rio.src/M000058.html +3 -3
  64. data/doc/rdoc/classes/RIO/Rio.src/M000059.html +3 -3
  65. data/doc/rdoc/classes/RIO/Rio.src/M000060.html +3 -3
  66. data/doc/rdoc/classes/RIO/Rio.src/M000061.html +3 -3
  67. data/doc/rdoc/classes/RIO/Rio.src/M000062.html +3 -3
  68. data/doc/rdoc/classes/RIO/Rio.src/M000063.html +3 -3
  69. data/doc/rdoc/classes/RIO/Rio.src/M000064.html +3 -3
  70. data/doc/rdoc/classes/RIO/Rio.src/M000065.html +3 -3
  71. data/doc/rdoc/classes/RIO/Rio.src/M000066.html +3 -3
  72. data/doc/rdoc/classes/RIO/Rio.src/M000067.html +3 -3
  73. data/doc/rdoc/classes/RIO/Rio.src/M000068.html +3 -3
  74. data/doc/rdoc/classes/RIO/Rio.src/M000069.html +3 -3
  75. data/doc/rdoc/classes/RIO/Rio.src/M000070.html +3 -3
  76. data/doc/rdoc/classes/RIO/Rio.src/M000071.html +3 -3
  77. data/doc/rdoc/classes/RIO/Rio.src/M000072.html +3 -3
  78. data/doc/rdoc/classes/RIO/Rio.src/M000073.html +3 -3
  79. data/doc/rdoc/classes/RIO/Rio.src/M000074.html +3 -3
  80. data/doc/rdoc/classes/RIO/Rio.src/M000075.html +3 -3
  81. data/doc/rdoc/classes/RIO/Rio.src/M000076.html +3 -3
  82. data/doc/rdoc/classes/RIO/Rio.src/M000077.html +3 -3
  83. data/doc/rdoc/classes/RIO/Rio.src/M000078.html +3 -3
  84. data/doc/rdoc/classes/RIO/Rio.src/M000079.html +3 -3
  85. data/doc/rdoc/classes/RIO/Rio.src/M000080.html +3 -3
  86. data/doc/rdoc/classes/RIO/Rio.src/M000081.html +3 -3
  87. data/doc/rdoc/classes/RIO/Rio.src/M000082.html +3 -3
  88. data/doc/rdoc/classes/RIO/Rio.src/M000083.html +3 -3
  89. data/doc/rdoc/classes/RIO/Rio.src/M000084.html +3 -3
  90. data/doc/rdoc/classes/RIO/Rio.src/M000085.html +3 -3
  91. data/doc/rdoc/classes/RIO/Rio.src/M000086.html +3 -3
  92. data/doc/rdoc/classes/RIO/Rio.src/M000087.html +3 -3
  93. data/doc/rdoc/classes/RIO/Rio.src/M000088.html +3 -3
  94. data/doc/rdoc/classes/RIO/Rio.src/M000089.html +2 -2
  95. data/doc/rdoc/classes/RIO/Rio.src/M000090.html +2 -2
  96. data/doc/rdoc/classes/RIO/Rio.src/M000091.html +2 -2
  97. data/doc/rdoc/classes/RIO/Rio.src/M000092.html +2 -2
  98. data/doc/rdoc/classes/RIO/Rio.src/M000093.html +2 -2
  99. data/doc/rdoc/classes/RIO/Rio.src/M000094.html +2 -2
  100. data/doc/rdoc/classes/RIO/Rio.src/M000095.html +2 -2
  101. data/doc/rdoc/classes/RIO/Rio.src/M000096.html +2 -2
  102. data/doc/rdoc/classes/RIO/Rio.src/M000097.html +2 -2
  103. data/doc/rdoc/classes/RIO/Rio.src/M000098.html +2 -2
  104. data/doc/rdoc/classes/RIO/Rio.src/M000099.html +2 -2
  105. data/doc/rdoc/classes/RIO/Rio.src/M000100.html +2 -2
  106. data/doc/rdoc/classes/RIO/Rio.src/M000101.html +2 -2
  107. data/doc/rdoc/classes/RIO/Rio.src/M000102.html +2 -2
  108. data/doc/rdoc/classes/RIO/Rio.src/M000103.html +2 -2
  109. data/doc/rdoc/classes/RIO/Rio.src/M000104.html +2 -2
  110. data/doc/rdoc/classes/RIO/Rio.src/M000105.html +2 -2
  111. data/doc/rdoc/classes/RIO/Rio.src/M000106.html +2 -2
  112. data/doc/rdoc/classes/RIO/Rio.src/M000107.html +2 -2
  113. data/doc/rdoc/classes/RIO/Rio.src/M000108.html +3 -3
  114. data/doc/rdoc/classes/RIO/Rio.src/M000109.html +3 -3
  115. data/doc/rdoc/classes/RIO/Rio.src/M000110.html +3 -3
  116. data/doc/rdoc/classes/RIO/Rio.src/M000111.html +3 -3
  117. data/doc/rdoc/classes/RIO/Rio.src/M000112.html +3 -3
  118. data/doc/rdoc/classes/RIO/Rio.src/M000113.html +3 -3
  119. data/doc/rdoc/classes/RIO/Rio.src/M000114.html +3 -3
  120. data/doc/rdoc/classes/RIO/Rio.src/M000115.html +3 -3
  121. data/doc/rdoc/classes/RIO/Rio.src/M000116.html +3 -3
  122. data/doc/rdoc/classes/RIO/Rio.src/M000117.html +3 -3
  123. data/doc/rdoc/classes/RIO/Rio.src/M000118.html +3 -3
  124. data/doc/rdoc/classes/RIO/Rio.src/M000119.html +3 -3
  125. data/doc/rdoc/classes/RIO/Rio.src/M000120.html +3 -3
  126. data/doc/rdoc/classes/RIO/Rio.src/M000121.html +3 -3
  127. data/doc/rdoc/classes/RIO/Rio.src/M000122.html +3 -3
  128. data/doc/rdoc/classes/RIO/Rio.src/M000123.html +3 -3
  129. data/doc/rdoc/classes/RIO/Rio.src/M000124.html +3 -3
  130. data/doc/rdoc/classes/RIO/Rio.src/M000125.html +3 -3
  131. data/doc/rdoc/classes/RIO/Rio.src/M000126.html +3 -3
  132. data/doc/rdoc/classes/RIO/Rio.src/M000127.html +3 -3
  133. data/doc/rdoc/classes/RIO/Rio.src/M000128.html +3 -3
  134. data/doc/rdoc/classes/RIO/Rio.src/M000129.html +3 -3
  135. data/doc/rdoc/classes/RIO/Rio.src/M000130.html +3 -3
  136. data/doc/rdoc/classes/RIO/Rio.src/M000131.html +3 -3
  137. data/doc/rdoc/classes/RIO/Rio.src/M000132.html +3 -3
  138. data/doc/rdoc/classes/RIO/Rio.src/M000133.html +3 -3
  139. data/doc/rdoc/classes/RIO/Rio.src/M000134.html +3 -3
  140. data/doc/rdoc/classes/RIO/Rio.src/M000135.html +3 -3
  141. data/doc/rdoc/classes/RIO/Rio.src/M000136.html +3 -3
  142. data/doc/rdoc/classes/RIO/Rio.src/M000137.html +3 -3
  143. data/doc/rdoc/classes/RIO/Rio.src/M000138.html +3 -3
  144. data/doc/rdoc/classes/RIO/Rio.src/M000139.html +3 -3
  145. data/doc/rdoc/classes/RIO/Rio.src/M000140.html +3 -3
  146. data/doc/rdoc/classes/RIO/Rio.src/M000141.html +3 -3
  147. data/doc/rdoc/classes/RIO/Rio.src/M000142.html +3 -3
  148. data/doc/rdoc/classes/RIO/Rio.src/M000143.html +3 -3
  149. data/doc/rdoc/classes/RIO/Rio.src/M000144.html +3 -3
  150. data/doc/rdoc/classes/RIO/Rio.src/M000145.html +3 -3
  151. data/doc/rdoc/classes/RIO/Rio.src/M000146.html +3 -3
  152. data/doc/rdoc/classes/RIO/Rio.src/M000147.html +3 -3
  153. data/doc/rdoc/classes/RIO/Rio.src/M000148.html +3 -3
  154. data/doc/rdoc/classes/RIO/Rio.src/M000149.html +3 -3
  155. data/doc/rdoc/classes/RIO/Rio.src/M000150.html +3 -3
  156. data/doc/rdoc/classes/RIO/Rio.src/M000151.html +3 -3
  157. data/doc/rdoc/classes/RIO/Rio.src/M000152.html +3 -3
  158. data/doc/rdoc/classes/RIO/Rio.src/M000153.html +3 -3
  159. data/doc/rdoc/classes/RIO/Rio.src/M000154.html +3 -3
  160. data/doc/rdoc/classes/RIO/Rio.src/M000155.html +3 -3
  161. data/doc/rdoc/classes/RIO/Rio.src/M000156.html +3 -3
  162. data/doc/rdoc/classes/RIO/Rio.src/M000157.html +3 -3
  163. data/doc/rdoc/classes/RIO/Rio.src/M000158.html +3 -3
  164. data/doc/rdoc/classes/RIO/Rio.src/M000159.html +3 -3
  165. data/doc/rdoc/classes/RIO/Rio.src/M000160.html +3 -3
  166. data/doc/rdoc/classes/RIO/Rio.src/M000161.html +3 -3
  167. data/doc/rdoc/classes/RIO/Rio.src/M000162.html +3 -3
  168. data/doc/rdoc/classes/RIO/Rio.src/M000163.html +3 -3
  169. data/doc/rdoc/classes/RIO/Rio.src/M000164.html +3 -3
  170. data/doc/rdoc/classes/RIO/Rio.src/M000165.html +3 -3
  171. data/doc/rdoc/classes/RIO/Rio.src/M000166.html +3 -3
  172. data/doc/rdoc/classes/RIO/Rio.src/M000167.html +3 -3
  173. data/doc/rdoc/classes/RIO/Rio.src/M000168.html +3 -3
  174. data/doc/rdoc/classes/RIO/Rio.src/M000169.html +3 -3
  175. data/doc/rdoc/classes/RIO/Rio.src/M000170.html +3 -3
  176. data/doc/rdoc/classes/RIO/Rio.src/M000171.html +3 -3
  177. data/doc/rdoc/classes/RIO/Rio.src/M000172.html +3 -3
  178. data/doc/rdoc/classes/RIO/Rio.src/M000173.html +3 -3
  179. data/doc/rdoc/classes/RIO/Rio.src/M000174.html +3 -3
  180. data/doc/rdoc/classes/RIO/Rio.src/M000175.html +3 -3
  181. data/doc/rdoc/classes/RIO/Rio.src/M000176.html +3 -3
  182. data/doc/rdoc/classes/RIO/Rio.src/M000177.html +3 -3
  183. data/doc/rdoc/classes/RIO/Rio.src/M000178.html +3 -3
  184. data/doc/rdoc/classes/RIO/Rio.src/M000179.html +3 -3
  185. data/doc/rdoc/classes/RIO/Rio.src/M000180.html +3 -3
  186. data/doc/rdoc/classes/RIO/Rio.src/M000181.html +3 -3
  187. data/doc/rdoc/created.rid +1 -1
  188. data/doc/rdoc/files/lib/rio/constructor_rb.html +1 -1
  189. data/doc/rdoc/files/lib/rio/doc/HOWTO_rb.html +1 -1
  190. data/doc/rdoc/files/lib/rio/doc/INTRO_rb.html +1 -1
  191. data/doc/rdoc/files/lib/rio/doc/SYNOPSIS_rb.html +1 -1
  192. data/doc/rdoc/files/lib/rio/if/basic_rb.html +1 -1
  193. data/doc/rdoc/files/lib/rio/if/path_rb.html +1 -1
  194. data/doc/rdoc/files/lib/rio_rb.html +1 -1
  195. data/doc/rdoc/fr_method_index.html +154 -155
  196. data/ex/findinruby +7 -3
  197. data/ex/findruby +6 -2
  198. data/lib/rio.rb +1 -1
  199. data/lib/rio/argv.rb +4 -0
  200. data/lib/rio/constructor.rb +17 -0
  201. data/lib/rio/context.rb +1 -1
  202. data/lib/rio/context/dir.rb +1 -0
  203. data/lib/rio/context/methods.rb +3 -3
  204. data/lib/rio/dir.rb +2 -2
  205. data/lib/rio/doc/HOWTO.rb +11 -6
  206. data/lib/rio/doc/INTRO.rb +149 -12
  207. data/lib/rio/doc/SYNOPSIS.rb +26 -13
  208. data/lib/rio/factory.rb +13 -2
  209. data/lib/rio/grande.rb +25 -0
  210. data/lib/rio/if/basic.rb +1 -1
  211. data/lib/rio/if/path.rb +61 -35
  212. data/lib/rio/matchrecord.rb +20 -1
  213. data/lib/rio/ops/dir.rb +2 -3
  214. data/lib/rio/ops/path.rb +25 -11
  215. data/lib/rio/ops/stream/input.rb +6 -3
  216. data/lib/rio/rl/base.rb +3 -2
  217. data/lib/rio/rl/ioi.rb +2 -1
  218. data/lib/rio/rl/path.rb +18 -3
  219. data/lib/rio/rl/uri.rb +8 -4
  220. data/lib/rio/scheme/cmdio.rb +1 -1
  221. data/lib/rio/scheme/path.rb +1 -0
  222. data/lib/rio/scheme/stdio.rb +1 -1
  223. data/lib/rio/scheme/strio.rb +1 -1
  224. data/lib/rio/scheme/sysio.rb +1 -1
  225. data/lib/rio/scheme/tcp.rb +1 -0
  226. data/lib/rio/scheme/temp.rb +184 -0
  227. data/lib/rio/state.rb +17 -6
  228. data/lib/rio/stream.rb +1 -1
  229. data/lib/rio/stream/open.rb +1 -1
  230. data/lib/rio/tempdir.rb +132 -0
  231. data/lib/rio/version.rb +1 -1
  232. data/test/tc/all.rb +4 -0
  233. data/test/tc/copylines.rb +38 -32
  234. data/test/tc/riorl.rb +104 -0
  235. data/test/tc/temp.rb +155 -0
  236. data/test/tc/tempdir.rb +63 -0
  237. data/test/tc/tempfile.rb +38 -0
  238. metadata +10 -5
  239. data/doc/rdoc/classes/RIO/Rio.src/M000182.html +0 -16
  240. data/lib/rio/scheme/tempfile.rb +0 -104
data/lib/rio/rl/uri.rb CHANGED
@@ -45,7 +45,7 @@ module RIO
45
45
  #p callstr('initialize',u,*args)
46
46
  # u should be a ::URI or something that can be parsed to one
47
47
  args = get_base(*args)
48
- @uri = ( u.kind_of?(::URI) ? u.dup : parse_url(u.to_s) )
48
+ @uri = _mkuri(u)
49
49
  self.join(*args)
50
50
  @uri.path = '/' if @uri.absolute? and @uri.path == ''
51
51
  end
@@ -56,6 +56,13 @@ module RIO
56
56
  @uri = @uri.clone unless @uri.nil?
57
57
  @base = @base.clone unless @base.nil?
58
58
  end
59
+ def _mkuri(arg)
60
+ (arg.kind_of?(::URI) ? arg.dup : parse_url(arg.to_s))
61
+ end
62
+ def base(arg=nil)
63
+ @base = _mkuri(arg) unless arg.nil? or @uri.absolute?
64
+ (@base.nil? ? @uri : @base)
65
+ end
59
66
  def join(*args)
60
67
  # self.class.joinuri(self.uri,*args)
61
68
  return @uri if args.empty?
@@ -83,9 +90,6 @@ module RIO
83
90
  def merge(other)
84
91
  self.class.new(@uri.merge(other.uri))
85
92
  end
86
- def base()
87
- (@base.nil? ? @uri : @base)
88
- end
89
93
  def get_base(*args)
90
94
  # args.each { |a| p "get_base len=#{args.length} #{a.class}##{a.to_s}" }
91
95
  @base = nil
@@ -42,7 +42,7 @@ module RIO
42
42
 
43
43
  class RL < RL::SysIOBase
44
44
  RIOSCHEME = 'cmdio'
45
- RIOPATH = RIO::RL::CHMAP.invert[RIOSCHEME].freeze
45
+ RIOPATH = RIO::RL::CHMAP.invert[RIOSCHEME].to_s.freeze
46
46
  def initialize(cmd="")
47
47
  @cmd = cmd
48
48
  end
@@ -77,6 +77,7 @@ module RIO
77
77
  end
78
78
  def input() stream_state('Path::Stream::Input') end
79
79
  def output() stream_state('Path::Stream::Output') end
80
+
80
81
  def inout() stream_state('Path::Stream::InOut') end
81
82
  end
82
83
 
@@ -42,7 +42,7 @@ module RIO
42
42
 
43
43
  class RL < RL::SysIOBase
44
44
  RIOSCHEME = 'stdio'
45
- RIOPATH = RIO::RL::CHMAP.invert[RIOSCHEME].freeze
45
+ RIOPATH = RIO::RL::CHMAP.invert[RIOSCHEME].to_s.freeze
46
46
  attr_reader :scheme
47
47
  def initialize(sch=RIOSCHEME)
48
48
  @scheme = sch
@@ -46,7 +46,7 @@ module RIO
46
46
 
47
47
  class RL < RL::IOIBase
48
48
  RIOSCHEME = 'strio'
49
- RIOPATH = RIO::RL::CHMAP.invert[RIOSCHEME].freeze
49
+ RIOPATH = RIO::RL::CHMAP.invert[RIOSCHEME].to_s.freeze
50
50
  def initialize(str="")
51
51
  @str = str
52
52
  end
@@ -42,7 +42,7 @@ module RIO
42
42
 
43
43
  class RL < RL::SysIOBase
44
44
  RIOSCHEME = 'sysio'
45
- RIOPATH = RIO::RL::CHMAP.invert[RIOSCHEME].freeze
45
+ RIOPATH = RIO::RL::CHMAP.invert[RIOSCHEME].to_s.freeze
46
46
  def opaque() sprintf('0x%08x',self.ios.object_id) end
47
47
  # must be able to process both
48
48
  # parse('rio:sysio',ios)
@@ -42,6 +42,7 @@ module RIO
42
42
  require 'rio/rl/ioi'
43
43
  class RL < RL::IOIBase
44
44
  RIOSCHEME = 'tcp'.freeze
45
+ attr_reader :host
45
46
  def initialize(host,port)
46
47
  @host = host
47
48
  @port = port
@@ -0,0 +1,184 @@
1
+ #--
2
+ # ===============================================================================
3
+ # Copyright (c) 2005, Christopher Kleckner
4
+ # All rights reserved
5
+ #
6
+ # This file is part of the Rio library for ruby.
7
+ #
8
+ # Rio is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # Rio is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with Rio; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ # ===============================================================================
22
+ #++
23
+ #
24
+ # To create the documentation for Rio run the command
25
+ # rake rdoc
26
+ # from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
27
+ #
28
+ # Suggested Reading
29
+ # * RIO::Doc::SYNOPSIS
30
+ # * RIO::Doc::INTRO
31
+ # * RIO::Doc::HOWTO
32
+ # * RIO::Rio
33
+ #
34
+ # <b>Rio is pre-alpha software.
35
+ # The documented interface and behavior is subject to change without notice.</b>
36
+ #
37
+ require 'tmpdir'
38
+ module RIO
39
+ module Temp
40
+ RESET_STATE = 'Temp::Reset'
41
+
42
+ require 'rio/rl/base'
43
+ class RL < RL::Base
44
+ RIOSCHEME = 'temp'
45
+ RIOPATH = RIO::RL::CHMAP.invert[RIOSCHEME].to_s.freeze
46
+ DFLT_PREFIX = 'rio'
47
+ DFLT_TMPDIR = ::Dir::tmpdir
48
+ attr_reader :prefix,:tmpdir
49
+ def initialize(file_prefix=DFLT_PREFIX,temp_dir=DFLT_TMPDIR)
50
+ #puts "initialize(#{file_prefix.inspect},#{temp_dir.inspect})"
51
+ @prefix = file_prefix || DFLT_PREFIX
52
+ @tmpdir = temp_dir || DFLT_TMPDIR
53
+ end
54
+ #def path() nil end
55
+ def scheme() self.class.const_get(:RIOSCHEME) end
56
+ def opaque()
57
+ td = @tmpdir.to_s
58
+ td += '/' unless td.nil? or td.empty? or (td.ends_with?('/') and td != '/')
59
+ td+@prefix
60
+ end
61
+
62
+ SPLIT_RE = %r|(?:(.*)/)?([^/]*)$|.freeze
63
+ def self.splitrl(s)
64
+ sub,opq,whole = split_riorl(s)
65
+ if opq.nil? or opq.empty?
66
+ []
67
+ elsif bm = SPLIT_RE.match(opq)
68
+ tdir = bm[1] unless bm[1].nil? or bm[1].empty?
69
+ tpfx = bm[2] unless bm[2].nil? or bm[2].empty?
70
+ [tpfx,tdir]
71
+ else
72
+ []
73
+ end
74
+ end
75
+ end
76
+ module Dir
77
+ require 'rio/rl/path'
78
+ RESET_STATE = RIO::RL::PathBase::RESET_STATE
79
+ require 'tmpdir'
80
+ class RL < RIO::RL::PathBase
81
+ RIOSCHEME = 'tempdir'
82
+ DFLT_PREFIX = Temp::RL::DFLT_PREFIX
83
+ DFLT_TMPDIR = Temp::RL::DFLT_TMPDIR
84
+ attr_reader :prefix,:tmpdir,:tmprl
85
+ def initialize(file_prefix=DFLT_PREFIX,temp_dir=DFLT_TMPDIR)
86
+ #puts "initialize(#{file_prefix.inspect},#{temp_dir.inspect})"
87
+ @prefix = file_prefix || DFLT_PREFIX
88
+ @tmpdir = temp_dir || DFLT_TMPDIR
89
+ require 'rio/tempdir'
90
+ @td = ::Tempdir.new( @prefix.to_s, @tmpdir.to_s)
91
+ super(@td.to_s)
92
+ end
93
+ SPLIT_RE = Temp::RL::SPLIT_RE
94
+ def self.splitrl(s)
95
+ Temp::RL.splitrl(s)
96
+ end
97
+ end
98
+ end
99
+ module File
100
+ require 'rio/rl/path'
101
+ RESET_STATE = 'Temp::Stream::Open'
102
+ class RL < RIO::RL::PathBase
103
+ RIOSCHEME = 'tempfile'
104
+ DFLT_PREFIX = Temp::RL::DFLT_PREFIX
105
+ DFLT_TMPDIR = Temp::RL::DFLT_TMPDIR
106
+ attr_reader :prefix,:tmpdir,:tmprl
107
+ def initialize(file_prefix=DFLT_PREFIX,temp_dir=DFLT_TMPDIR)
108
+ #puts "initialize(#{file_prefix.inspect},#{temp_dir.inspect})"
109
+ @prefix = file_prefix || DFLT_PREFIX
110
+ @tmpdir = temp_dir || DFLT_TMPDIR
111
+ require 'tempfile'
112
+ @tf = ::Tempfile.new( @prefix.to_s, @tmpdir.to_s)
113
+ super(@tf.path)
114
+ end
115
+ def open(mode='ignored',tf=nil,td=nil)
116
+ @tf
117
+ end
118
+ def close
119
+ super
120
+ @tf = nil
121
+ end
122
+ SPLIT_RE = Temp::RL::SPLIT_RE
123
+ def self.splitrl(s)
124
+ Temp::RL.splitrl(s)
125
+ end
126
+ end
127
+ end
128
+ require 'rio/state'
129
+ class Reset < State::Base
130
+ def initialize(*args)
131
+ super
132
+ @tempobj = nil
133
+ end
134
+ def check?() true end
135
+ def dir(prefix=rl.prefix,tmpdir=rl.tmpdir)
136
+ self.rl = RIO::Temp::Dir::RL.new(prefix, tmpdir)
137
+ become 'Dir::Existing'
138
+ end
139
+ def mkdir()
140
+ dir()
141
+ end
142
+ def chdir(&block)
143
+ dir.chdir(&block)
144
+ end
145
+ def file(prefix=rl.prefix,tmpdir=rl.tmpdir)
146
+ self.rl = RIO::Temp::File::RL.new(prefix, tmpdir)
147
+ become 'Temp::Stream::Open'
148
+ end
149
+ def scheme() rl.scheme() end
150
+ def host() rl.host() end
151
+ def opaque() rl.opaque() end
152
+ def to_s() rl.url() end
153
+ def exist?() false end
154
+ def file?() false end
155
+ def dir?() false end
156
+ def open?() false end
157
+ def closed?() true end
158
+ def when_missing(sym,*args)
159
+ if @tempobj.nil?
160
+ file()
161
+ else
162
+ gofigure(sym,*args)
163
+ end
164
+ end
165
+ end
166
+ require 'rio/stream/open'
167
+ module Stream
168
+ class Open < RIO::Stream::Open
169
+ def iostate(sym)
170
+ mode('w+').noautoclose_.open_.inout()
171
+ end
172
+ # def inout() stream_state('Temp::Stream::InOut') end
173
+ end
174
+ # require 'rio/stream'
175
+ # class InOut < RIO::Stream::InOut
176
+ # def base_state() 'Temp::Stream::Close' end
177
+ # end
178
+ # class Close < RIO::Stream::Close
179
+ # def base_state() 'Temp::Reset' end
180
+ # end
181
+
182
+ end
183
+ end
184
+ end
data/lib/rio/state.rb CHANGED
@@ -40,6 +40,7 @@ require 'rio/context'
40
40
  require 'rio/context/methods'
41
41
  require 'rio/ext'
42
42
  require 'rio/symantics'
43
+ $trace_states = false
43
44
  module RIO
44
45
 
45
46
 
@@ -109,7 +110,7 @@ module RIO
109
110
  # it's job is create an instance of the next state
110
111
  # and change the value in the handle that is shared with the fs object
111
112
  def become(new_class,*args)
112
- #p "become : #{self.class.to_s} => #{new_class.to_s} (#{self.mode?})" if $trace_states
113
+ p "become : #{self.class.to_s} => #{new_class.to_s} (#{self.mode?})" if $trace_states
113
114
  #
114
115
  return self if new_class == self.class
115
116
 
@@ -124,7 +125,7 @@ module RIO
124
125
  "missing: "+self.class.to_s+'['+self.to_url+']'+'.'+sym.to_s+'('+args.join(',')+')'
125
126
  end
126
127
  def method_missing(sym,*args,&block)
127
- #p method_missing_trace_str(sym,*args) if $trace_states
128
+ p method_missing_trace_str(sym,*args) if $trace_states
128
129
 
129
130
  obj = when_missing(sym,*args)
130
131
  raise RuntimeError,"when_missing returns nil" if obj.nil?
@@ -163,15 +164,25 @@ module RIO
163
164
 
164
165
  def to_rl() self.rl.rl end
165
166
 
166
- def fspath() @rl.fspath end
167
- def path() @rl.path() end
168
- def to_s() @rl.to_s() end
167
+
168
+ extend Forwardable
169
+ # def_instance_delegators(:rl,:path,:to_s,:fspath,:opaque,:host,:length)
170
+ def_instance_delegators(:rl,:path,:to_s,:fspath,:length)
171
+
172
+ # def fspath() @rl.fspath end
173
+ # def path() @rl.path() end
174
+ # def opaque() @rl.opaque() end
175
+ # def scheme() @rl.scheme() end
176
+ # def host() @rl.host() end
177
+ # def to_s() @rl.to_s() end
178
+ # def length() @rl.length end
179
+
180
+
169
181
  def ==(other) @rl == other end
170
182
  def ===(other) self == other end
171
183
  def =~(other) other =~ self.to_s end
172
184
  def to_url() @rl.url end
173
185
  def to_uri() @rl.uri end
174
- def length() @rl.length end
175
186
  alias to_str to_s
176
187
 
177
188
  def hash() @rl.to_s.hash end
data/lib/rio/stream.rb CHANGED
@@ -61,7 +61,7 @@ module RIO
61
61
 
62
62
  class IOBase < Base
63
63
  # Mixin the appropriate ops
64
- #include Ops::Path::Str
64
+ include Ops::Path::Str
65
65
  include Ops::Stream::Status
66
66
  include Ops::Stream::Manip
67
67
 
@@ -66,7 +66,7 @@ module RIO
66
66
  #p callstr('open_',args.inspect)+" mode='#{mode?}' (#{mode?.class}) ioh=#{self.ioh} open?=#{open?}"
67
67
  unless open?
68
68
  ios = self.rl.open(mode?,*args)
69
- noclose_(false) if ios.tty?
69
+ noautoclose_(false) if ios.tty?
70
70
  self.ioh = IOH::Stream.new(ios)
71
71
  end
72
72
  self
@@ -0,0 +1,132 @@
1
+ =begin rdoc
2
+
3
+ == tempdir.rb - provides class Tempdir
4
+
5
+ === Synopsis
6
+ In order to
7
+
8
+ 1. create a temporary directory with a name starting with "hoge",
9
+ 2. show the name of that directory, and
10
+ 3. show its properties with the system "ls -dl" command:
11
+
12
+ require 'tempdir'
13
+
14
+ d = Tempdir.new("hoge")
15
+ p d.to_s
16
+ system("ls", "-dl", d.to_s)
17
+
18
+ After the run, the directory will appear to be removed. That is: if you
19
+ are not running inside it, which may provide you a means to create a
20
+ directory with a unique name that will be available after the run.
21
+
22
+ === Description
23
+ <i>tempdir.rb</i> provides the Tempdir class, which is analogous to the
24
+ Tempfile class, but manipulates temporary directories. Derived from a
25
+ proposal of nobu.nokada@softhome.net. He added the class to
26
+ tempfile.rb, but since it does not seem to appear in cvs, I'll keep
27
+ it apart in tempdir.rb.
28
+
29
+ =end
30
+
31
+ require 'tmpdir'
32
+
33
+ module AutoRemoval
34
+ MAX_TRY = 10
35
+ @@cleanlist = []
36
+
37
+ private
38
+
39
+ def make_tmpname(basename, n)
40
+ sprintf('%s%d.%d', basename, $$, n)
41
+ end
42
+ private :make_tmpname
43
+
44
+ def createtmp(basename, tmpdir=Dir::tmpdir) # :nodoc:
45
+ if $SAFE > 0 and tmpdir.tainted?
46
+ tmpdir = '/tmp'
47
+ end
48
+
49
+ lock = nil
50
+ n = failure = 0
51
+
52
+ begin
53
+ Thread.critical = true
54
+ begin
55
+ tmpname = File.join(tmpdir, make_tmpname(basename, n))
56
+ n += 1
57
+ end until !@@cleanlist.include?(tmpname) and yield(tmpname)
58
+ rescue
59
+ p $!
60
+ failure += 1
61
+ retry if failure < MAX_TRY
62
+ raise "cannot generate tempfile `%s'" % tmpname
63
+ ensure
64
+ Thread.critical = false
65
+ end
66
+
67
+ tmpname
68
+ end
69
+
70
+ def self.callback(path, clear) # :nodoc:
71
+ @@cleanlist << path
72
+ data = [path]
73
+ pid = $$
74
+ return Proc.new {
75
+ if pid == $$
76
+ path, tmpfile = *data
77
+
78
+ print "removing ", path, "..." if $DEBUG
79
+
80
+ tmpfile.close if tmpfile
81
+
82
+ # keep this order for thread safeness
83
+ if File.exist?(path)
84
+ clear.call(path)
85
+ end
86
+ @@cleanlist.delete(path)
87
+
88
+ print "done\n" if $DEBUG
89
+ end
90
+ }, data
91
+ end
92
+
93
+ def self.unregister(path)
94
+ @@cleanlist.delete(path)
95
+ end
96
+ end
97
+
98
+ require 'pathname'
99
+ class Tempdir < Pathname
100
+ include AutoRemoval
101
+
102
+ def initialize(*args)
103
+ require 'fileutils'
104
+
105
+ tmpname = createtmp(*args) do |tmpname|
106
+ unless File.exist?(tmpname)
107
+ Dir.mkdir(tmpname, 0700)
108
+ end
109
+ end
110
+
111
+ super(tmpname)
112
+ @clean_proc, = AutoRemoval.callback(tmpname, FileUtils.method(:rm_rf))
113
+ ObjectSpace.define_finalizer(self, @clean_proc) end
114
+
115
+ def open(basename, *modes, &block)
116
+ File.open(self+basename, *modes, &block)
117
+ end
118
+
119
+ def clear
120
+ FileUtils.rm_rf(@tmpname)
121
+ @clean_proc.call
122
+ ObjectSpace.undefine_finalizer(self)
123
+ end
124
+ end
125
+
126
+ if __FILE__ == $0
127
+ # $DEBUG = true
128
+ d = Tempdir.new("hoge")
129
+ p d.to_s
130
+ system("ls", "-dl", d.to_s)
131
+ p d
132
+ end