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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/akabei/system.rb +12 -1
- data/lib/akabei/version.rb +1 -1
- data/spec/akabei/system_spec.rb +43 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ff61e094ee27a7589de8368cc62e21e1648f4ee
|
4
|
+
data.tar.gz: 5f990365218e0e03da0008e4cf4d50a1daf8fdaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bd26621baee54f6b5058c6428104b44f5220a4a7546533cc87c542155bbb9757ea651d8dd1142cbebffa00fbc517a9a4d3878bb10de9f3bc8fe17fc9322f7c6
|
7
|
+
data.tar.gz: 8afedf18973b1486c4175abedf436239d234b72edc01d4a18483abfb233af4de33e0d1e8577ab3ed9e936ab52cc3329ee8bda79aa768c3c9e675e2c986f7c87e
|
data/CHANGELOG.md
CHANGED
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
|
-
|
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
|
data/lib/akabei/version.rb
CHANGED
data/spec/akabei/system_spec.rb
CHANGED
@@ -38,7 +38,11 @@ describe Akabei::System do
|
|
38
38
|
|
39
39
|
context 'with command failure' do
|
40
40
|
before do
|
41
|
-
|
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(:
|
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
|
-
|
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
|
-
|
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
|