akabei 0.3.3 → 0.3.4

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: 4f24e73ac4a8f8c23310d5efca6ec404bd917304
4
- data.tar.gz: 899db05e8f86421ec1424df696f047880f8381f0
3
+ metadata.gz: 6ff61e094ee27a7589de8368cc62e21e1648f4ee
4
+ data.tar.gz: 5f990365218e0e03da0008e4cf4d50a1daf8fdaa
5
5
  SHA512:
6
- metadata.gz: 35242fb745b91cb11fc7f4be3522b42fc4f87cfe2e88d9607e312ee8980f5c8dbd1921f411da7e407fb7ec162424ee447ce22f7147adfaecf150a9005b099077
7
- data.tar.gz: 779a9bd2c6c594c41f94f2f4f0bcf229a043a7e7e8dca40a6dfbd4063cda34d86d2418b6e7a16ee3446a8ecc2016048e7d80f9ef79e2ecaa24599313f92c0406
6
+ metadata.gz: 7bd26621baee54f6b5058c6428104b44f5220a4a7546533cc87c542155bbb9757ea651d8dd1142cbebffa00fbc517a9a4d3878bb10de9f3bc8fe17fc9322f7c6
7
+ data.tar.gz: 8afedf18973b1486c4175abedf436239d234b72edc01d4a18483abfb233af4de33e0d1e8577ab3ed9e936ab52cc3329ee8bda79aa768c3c9e675e2c986f7c87e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 0.3.4 (2014-03-09)
2
+ - Improve signal handling
3
+
1
4
  # 0.3.3 (2014-03-07)
2
5
  - Fix gpg-agent check
3
6
 
data/lib/akabei/system.rb CHANGED
@@ -43,9 +43,20 @@ module Akabei
43
43
  args = args.dup
44
44
  args.unshift('setarch', a)
45
45
  end
46
- unless Kernel.system(env, *args.map(&:to_s), opts)
46
+
47
+ pid = Kernel.spawn(env, *args.map(&:to_s), opts)
48
+ begin
49
+ _, status = Process.waitpid2(pid)
50
+ unless status.success?
51
+ raise CommandFailed.new(env, args, opts)
52
+ end
53
+ rescue SignalException => e
54
+ # Always raise an error because mkarchroot exits with 0 even if it is
55
+ # interrupted.
56
+ Process.waitpid2(pid)
47
57
  raise CommandFailed.new(env, args, opts)
48
58
  end
59
+ status
49
60
  end
50
61
  end
51
62
  end
@@ -1,3 +1,3 @@
1
1
  module Akabei
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
@@ -38,7 +38,11 @@ describe Akabei::System do
38
38
 
39
39
  context 'with command failure' do
40
40
  before do
41
- allow(Kernel).to receive(:system).and_return(false)
41
+ status = double('Process::Status with failure')
42
+ allow(status).to receive(:success?).and_return(false)
43
+ pid = double('process id')
44
+ allow(Process).to receive(:waitpid2).with(pid).and_return([pid, status])
45
+ allow(Kernel).to receive(:spawn).and_return(pid, status)
42
46
  end
43
47
 
44
48
  it 'raises an error' do
@@ -53,13 +57,18 @@ describe Akabei::System do
53
57
  let(:arch) { 'armv7h' }
54
58
 
55
59
  it 'executes sudo and setarch' do
56
- expect(Kernel).to receive(:system) { |*args|
60
+ expect(Kernel).to receive(:spawn) { |*args|
57
61
  args = args.dup
58
62
  env = args.shift
59
63
  opts = args.pop
60
64
  expect(args).to eq(%W[setarch #{arch}] + command)
61
65
  expect(opts).to_not have_key(:arch)
62
- true
66
+
67
+ status = double('Process::Status with success')
68
+ allow(status).to receive(:success?).and_return(true)
69
+ pid = double('process id')
70
+ allow(Process).to receive(:waitpid2).with(pid).and_return([pid, status])
71
+ pid
63
72
  }
64
73
 
65
74
  options.merge!(arch: arch)
@@ -69,13 +78,43 @@ describe Akabei::System do
69
78
 
70
79
  context 'with command failure' do
71
80
  before do
72
- allow(Kernel).to receive(:system).and_return(false)
81
+ status = double('Process::Status with failure')
82
+ allow(status).to receive(:success?).and_return(false)
83
+ pid = double('process id')
84
+ allow(Process).to receive(:waitpid2).with(pid).and_return([pid, status])
85
+ allow(Kernel).to receive(:spawn).and_return(pid, status)
73
86
  end
74
87
 
75
88
  it 'raises an error' do
76
89
  expect { described_class.system(command, options) }.to raise_error(Akabei::System::CommandFailed)
77
90
  end
78
91
  end
92
+
93
+ context 'with signal' do
94
+ before do
95
+ status = double('Process::Status with success')
96
+ allow(status).to receive(:success?).and_return(true)
97
+ pid = double('process id')
98
+ allow(Kernel).to receive(:spawn).and_return(pid, status)
99
+
100
+ cnt = 0
101
+ allow(Process).to receive(:waitpid2).with(pid) {
102
+ cnt += 1
103
+ case cnt
104
+ when 1
105
+ raise SignalException.new(2)
106
+ when 2
107
+ [pid, status]
108
+ else
109
+ raise 'Process receives waitpid2 too many times'
110
+ end
111
+ }
112
+ end
113
+
114
+ it 'raises an error even if the process exit code is 0' do
115
+ expect { described_class.system(command, options) }.to raise_error(Akabei::System::CommandFailed)
116
+ end
117
+ end
79
118
  end
80
119
  end
81
120
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akabei
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki