joumae 0.2.4 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c697de02d12f82cff623f3c5b32529e4e3f98507
4
- data.tar.gz: 93872db6a95f5070a74a05c237b3123307616513
3
+ metadata.gz: 23733726cd6b1593664ad3f5d45a4feddf9ddb76
4
+ data.tar.gz: 0d83a648e087441e265f42e7848a11c65a0fe9d9
5
5
  SHA512:
6
- metadata.gz: f30e70813a4ba74f99b930e9854768ed1d3c0545d32d2fcccb33f5334e3da8f5740445362a0b47f65973dcc2d9cb8b207019926673e4b935df83be6d69d0af08
7
- data.tar.gz: 47846145224e929adf014e08b6d5641fceeb9e371144f2d8793c07e7ffb3494e1e63c52921a4949f0f51e3816fccdc0883e5623d570d2d09ebc29b63853f379f
6
+ metadata.gz: 9a137e7ae4d8af192ed4aa1e8c9ca5814e0352fb9189cf53c7f0ffd5ff0c40e949782e69a154f52f317ce707f53900600d8eae7fc6b8cd06932ea70e8ab83e44
7
+ data.tar.gz: 7b97fda2118205053ea627e2bbabde5990c465a745a472806aaa9cad15414dc846ee4c678f71205ae973dc87443b66a8e3b7e2fb49ce5738c648f3dd49d12f79
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- joumae (0.2.3)
4
+ joumae (0.2.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -29,12 +29,7 @@ module Joumae
29
29
  def run!
30
30
  status = Joumae::Transaction.run!(resource_name: @resource_name, client: @client) do
31
31
  Open3.popen3(cmd) do |i, o, e, w|
32
- unless STDIN.tty?
33
- redirect(STDIN => i)
34
- end
35
- i.close
36
-
37
- redirect(o => STDOUT, e => STDERR)
32
+ redirect(STDIN => i, o => STDOUT, e => STDERR)
38
33
 
39
34
  debug w.value
40
35
 
@@ -47,25 +42,61 @@ module Joumae
47
42
  private
48
43
 
49
44
  def redirect(mapping)
50
- files = mapping.keys
51
-
52
- until files.all?(&:eof) do
53
- ready = IO.select(files)
54
-
55
- continue unless ready
45
+ inputs = mapping.keys
46
+ ios_ready_for_eof_check = []
47
+
48
+ debug "Joumae::Command#redirect: mapping: " + mapping.inspect
49
+
50
+ # Calling IO#eof against an IO which is not `select`ed previous blocks the current thread.
51
+ # So you can't do something like :
52
+ # until inputs.all?(&:eof) do
53
+ # Or:
54
+ # until (inputs - [STDIN]).all?(&:eof) do
55
+ until inputs.empty? || (inputs.size == 1 && inputs.first == STDIN) do
56
+ debug 'starting `select`'
57
+
58
+ readable_inputs, = IO.select(inputs, [], [])
59
+ ios_ready_for_eof_check = readable_inputs
60
+
61
+ debug 'finished `select`'
62
+
63
+ # We can safely call `eof` without blocking against previously selected IOs.
64
+ debug 'starting eof check'
65
+ ios_ready_for_eof_check.select(&:eof).each do |src|
66
+ debug "Stopping redirection from an IO in EOF: " + src.inspect
67
+ # `select`ing an IO which has reached EOF blocks forever.
68
+ # So you have to delete such IO from the array of IOs to `select`.
69
+ inputs.delete src
70
+
71
+ # You must close the child process' STDIN immeditely after the parent's STDIN reached EOF,
72
+ # or some kinds of child processes never exit.
73
+ # e.g.) echo foobar | joumae run -- cat
74
+ # After the `echo` finished outputting `foobar`, you have to tell `cat` about that or `cat` will wait for more inputs forever.
75
+ mapping[src].close if src == STDIN
76
+ end
56
77
 
57
- readable = ready[0]
78
+ break if inputs.empty? || (inputs.size == 1 && inputs.first == STDIN)
58
79
 
59
- readable.each do |f|
80
+ readable_inputs.each do |input|
60
81
  begin
61
- data = f.read_nonblock(1024)
62
-
63
- mapping[f].write(data)
64
- mapping[f].flush
82
+ data = input.read_nonblock(1024)
83
+ output = mapping[input]
84
+ output.write(data)
85
+ output.flush
65
86
  rescue EOFError => e
66
- debug e.to_s;
87
+ debug "Reached EOF: #{e}"
88
+ inputs.delete input
89
+ rescue Errno::EPIPE => e
90
+ # How to produce this error:
91
+ # 1. Run the command:
92
+ # cat | bin/joumae run --resource-name test -- bundle exec ruby -v
93
+ # 2. Press Enter several times
94
+ debug "Handled error: #{e}: io: #{input.inspect}"
95
+ inputs.delete input
67
96
  end
68
97
  end
98
+
99
+ ios_ready_for_eof_check = inputs & readable_inputs
69
100
  end
70
101
  end
71
102
 
@@ -1,3 +1,3 @@
1
1
  module Joumae
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joumae
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke KUOKA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-16 00:00:00.000000000 Z
11
+ date: 2015-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler