train 0.29.1 → 0.29.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f08c1d5dc97551bd522b203489d60896b2d12a3
4
- data.tar.gz: dc98c76bf9a16796e8ff4873ca6976fbfdb8a2fe
3
+ metadata.gz: 91f83eccb563ed719ca19fd8be06d9616afc4eae
4
+ data.tar.gz: 740ba4a80a9b4690b36dec69dd2e752659032033
5
5
  SHA512:
6
- metadata.gz: d5c09fc411b4359394bb34e875f8db1e9255b8e86e61db758254f1d748d060a2b2adefb9b40968ed0b5ed348fbf9eb738b830eafbdd83f8619402c6003be80bc
7
- data.tar.gz: b5fbd002908a670d9352782d5455feffb3595816cce1fb86d0e41e118f7fcd3702a1379c93534dba7608b1d68e99b132d71f67dc85efffeaabda28045a7019b8
6
+ metadata.gz: 96eda4528ad55102f10ff705b13a639dec7405f693f67f72d6d8d1b11c35439210ca92ee172d3f18ae564097271de3aa88671f2c8528a8a5b84604dd1ec0344d
7
+ data.tar.gz: b4260ea407f3cf12614d222d5304a85091830972aade03e10491f1b897f5e01c99e3dc7ff45a7314cdd30e7224d46cd0b460538d34a0454f0601136ff8343db8
@@ -54,6 +54,16 @@ module Train
54
54
  group == sth
55
55
  end
56
56
 
57
+ def unix_mode_mask(owner, type)
58
+ o = UNIX_MODE_OWNERS[owner.to_sym]
59
+ return nil if o.nil?
60
+
61
+ t = UNIX_MODE_TYPES[type.to_sym]
62
+ return nil if t.nil?
63
+
64
+ t & o
65
+ end
66
+
57
67
  private
58
68
 
59
69
  def pw_username(uid)
@@ -67,6 +77,19 @@ module Train
67
77
  rescue ArgumentError => _
68
78
  nil
69
79
  end
80
+
81
+ UNIX_MODE_OWNERS = {
82
+ all: 00777,
83
+ owner: 00700,
84
+ group: 00070,
85
+ other: 00007,
86
+ }.freeze
87
+
88
+ UNIX_MODE_TYPES = {
89
+ r: 00444,
90
+ w: 00222,
91
+ x: 00111,
92
+ }.freeze
70
93
  end
71
94
  end
72
95
  end
@@ -8,7 +8,7 @@ module Train
8
8
  class Linux < Train::File::Remote::Unix
9
9
  def content
10
10
  return @content if defined?(@content)
11
- @content = @backend.run_command("cat #{@path} || echo -n").stdout
11
+ @content = @backend.run_command("cat #{@spath} || echo -n").stdout
12
12
  return @content unless @content.empty?
13
13
  @content = nil if directory? or size.nil? or size > 0
14
14
  @content
data/lib/train/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  # Author:: Dominik Richter (<dominik.richter@gmail.com>)
4
4
 
5
5
  module Train
6
- VERSION = '0.29.1'.freeze
6
+ VERSION = '0.29.2'.freeze
7
7
  end
@@ -12,6 +12,8 @@ chmod 0765 /tmp/file
12
12
  echo -n 'hello suid/sgid/sticky' > /tmp/sfile
13
13
  chmod 7765 /tmp/sfile
14
14
 
15
+ echo -n 'hello space' > /tmp/spaced\ file
16
+
15
17
  test ! -e /tmp/pipe && \
16
18
  mkfifo /tmp/pipe
17
19
 
@@ -21,6 +21,10 @@ file '/tmp/sfile' do
21
21
  content 'hello suid/sgid/sticky'
22
22
  end
23
23
 
24
+ file '/tmp/spaced file' do
25
+ content 'hello space'
26
+ end
27
+
24
28
  directory '/tmp/folder' do
25
29
  mode '0567'
26
30
  owner 'root'
@@ -89,4 +89,11 @@ describe 'file interface' do
89
89
  file.mode.must_equal(07765)
90
90
  end
91
91
  end
92
+
93
+ describe 'regular file' do
94
+ let(:file) { backend.file('/tmp/spaced file') }
95
+ it 'has content' do
96
+ file.content.must_equal('hello space')
97
+ end
98
+ end
92
99
  end
@@ -5,7 +5,7 @@ require 'train/transports/local'
5
5
 
6
6
  describe Train::File::Local::Unix do
7
7
  let(:cls) { Train::File::Local::Unix }
8
-
8
+
9
9
  let(:backend) {
10
10
  backend = Train::Transports::Mock.new.connection
11
11
  backend.mock_os({ family: 'linux' })
@@ -86,8 +86,8 @@ describe Train::File::Local::Unix do
86
86
  it 'grouped_into' do
87
87
  meta_stub :stat, statres do
88
88
  connection.file(rand.to_s).grouped_into?('group').must_equal true
89
- end
90
- end
89
+ end
90
+ end
91
91
 
92
92
  it 'recognizes selinux label' do
93
93
  meta_stub :stat, statres do
@@ -109,4 +109,38 @@ describe Train::File::Local::Unix do
109
109
  end
110
110
  end
111
111
  end
112
+
113
+ describe '#unix_mode_mask' do
114
+ let(:file_tester) do
115
+ Class.new(cls) do
116
+ define_method :type do
117
+ :file
118
+ end
119
+ end.new(nil, nil, false)
120
+ end
121
+
122
+ it 'check owner mode calculation' do
123
+ file_tester.unix_mode_mask('owner', 'x').must_equal 0100
124
+ file_tester.unix_mode_mask('owner', 'w').must_equal 0200
125
+ file_tester.unix_mode_mask('owner', 'r').must_equal 0400
126
+ end
127
+
128
+ it 'check group mode calculation' do
129
+ file_tester.unix_mode_mask('group', 'x').must_equal 0010
130
+ file_tester.unix_mode_mask('group', 'w').must_equal 0020
131
+ file_tester.unix_mode_mask('group', 'r').must_equal 0040
132
+ end
133
+
134
+ it 'check other mode calculation' do
135
+ file_tester.unix_mode_mask('other', 'x').must_equal 0001
136
+ file_tester.unix_mode_mask('other', 'w').must_equal 0002
137
+ file_tester.unix_mode_mask('other', 'r').must_equal 0004
138
+ end
139
+
140
+ it 'check all mode calculation' do
141
+ file_tester.unix_mode_mask('all', 'x').must_equal 0111
142
+ file_tester.unix_mode_mask('all', 'w').must_equal 0222
143
+ file_tester.unix_mode_mask('all', 'r').must_equal 0444
144
+ end
145
+ end
112
146
  end
@@ -42,6 +42,12 @@ describe Train::File::Remote::Linux do
42
42
  cls.new(backend, 'path').content.must_be_nil
43
43
  end
44
44
 
45
+ it 'reads file contents' do
46
+ out = rand.to_s
47
+ backend.mock_command('cat /spaced\\ path || echo -n', out)
48
+ cls.new(backend, '/spaced path').content.must_equal out
49
+ end
50
+
45
51
  it 'checks for file existance' do
46
52
  backend.mock_command('test -e path', true)
47
53
  cls.new(backend, 'path').exist?.must_equal true
@@ -164,4 +170,4 @@ describe Train::File::Remote::Linux do
164
170
  f.selinux_label.must_equal 'labels'
165
171
  end
166
172
  end
167
- end
173
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: train
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.1
4
+ version: 0.29.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Richter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-13 00:00:00.000000000 Z
11
+ date: 2017-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json