sys-filesystem 1.1.6 → 1.4.3
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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data/CHANGES.md +162 -0
- data/Gemfile +2 -0
- data/LICENSE +177 -0
- data/{MANIFEST → MANIFEST.md} +9 -6
- data/README.md +92 -0
- data/Rakefile +14 -24
- data/certs/djberg96_pub.pem +22 -17
- data/examples/example_mount.rb +73 -0
- data/examples/example_stat.rb +2 -0
- data/lib/sys/filesystem.rb +72 -1
- data/lib/sys/unix/sys/filesystem/constants.rb +32 -3
- data/lib/sys/unix/sys/filesystem/functions.rb +36 -9
- data/lib/sys/unix/sys/filesystem/structs.rb +77 -11
- data/lib/sys/unix/sys/filesystem.rb +105 -58
- data/lib/sys/windows/sys/filesystem/functions.rb +11 -8
- data/lib/sys/windows/sys/filesystem/helper.rb +1 -1
- data/lib/sys/windows/sys/filesystem.rb +100 -81
- data/spec/spec_helper.rb +6 -0
- data/spec/sys_filesystem_unix_spec.rb +396 -0
- data/spec/sys_filesystem_windows_spec.rb +348 -0
- data/sys-filesystem.gemspec +15 -7
- data.tar.gz.sig +0 -0
- metadata +75 -61
- metadata.gz.sig +0 -0
- data/CHANGES +0 -89
- data/README +0 -80
- data/test/test_sys_filesystem.rb +0 -7
- data/test/test_sys_filesystem_unix.rb +0 -278
- data/test/test_sys_filesystem_windows.rb +0 -250
@@ -0,0 +1,396 @@
|
|
1
|
+
####################################################################
|
2
|
+
# sys_filesystem_unix_spec.rb
|
3
|
+
#
|
4
|
+
# Specs for the Sys::Filesystem.stat method and related stuff.
|
5
|
+
# This test suite should be run via the 'rake spec' task.
|
6
|
+
####################################################################
|
7
|
+
require 'spec_helper'
|
8
|
+
require 'sys-filesystem'
|
9
|
+
require 'pathname'
|
10
|
+
|
11
|
+
RSpec.describe Sys::Filesystem, :unix => true do
|
12
|
+
let(:solaris) { RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i }
|
13
|
+
let(:linux) { RbConfig::CONFIG['host_os'] =~ /linux/i }
|
14
|
+
let(:bsd) { RbConfig::CONFIG['host_os'] =~ /bsd/i }
|
15
|
+
let(:darwin) { RbConfig::CONFIG['host_os'] =~ /mac|darwin/i }
|
16
|
+
let(:root) { '/' }
|
17
|
+
|
18
|
+
before do
|
19
|
+
@stat = Sys::Filesystem.stat(root)
|
20
|
+
@size = 58720256
|
21
|
+
end
|
22
|
+
|
23
|
+
example "version number is set to the expected value" do
|
24
|
+
expect(Sys::Filesystem::VERSION).to eq('1.4.3')
|
25
|
+
expect(Sys::Filesystem::VERSION).to be_frozen
|
26
|
+
end
|
27
|
+
|
28
|
+
example "you cannot instantiate an instance" do
|
29
|
+
expect{ described_class.new }.to raise_error(NoMethodError)
|
30
|
+
end
|
31
|
+
|
32
|
+
example "stat path works as expected" do
|
33
|
+
expect(@stat).to respond_to(:path)
|
34
|
+
expect(@stat.path).to eq(root)
|
35
|
+
end
|
36
|
+
|
37
|
+
example "stat block_size works as expected" do
|
38
|
+
expect(@stat).to respond_to(:block_size)
|
39
|
+
expect(@stat.block_size).to be_kind_of(Numeric)
|
40
|
+
end
|
41
|
+
|
42
|
+
example "stat fragment_size works as expected" do
|
43
|
+
expect(@stat).to respond_to(:fragment_size)
|
44
|
+
expect(@stat.fragment_size).to be_kind_of(Numeric)
|
45
|
+
end
|
46
|
+
|
47
|
+
example "stat fragment_size is a plausible value" do
|
48
|
+
expect(@stat.fragment_size).to be >= 512
|
49
|
+
expect(@stat.fragment_size).to be <= 16384
|
50
|
+
end
|
51
|
+
|
52
|
+
example "stat blocks works as expected" do
|
53
|
+
expect(@stat).to respond_to(:blocks)
|
54
|
+
expect(@stat.blocks).to be_kind_of(Numeric)
|
55
|
+
end
|
56
|
+
|
57
|
+
example "stat blocks_free works as expected" do
|
58
|
+
expect(@stat).to respond_to(:blocks_free)
|
59
|
+
expect(@stat.blocks_free).to be_kind_of(Numeric)
|
60
|
+
end
|
61
|
+
|
62
|
+
example "stat blocks_available works as expected" do
|
63
|
+
expect(@stat).to respond_to(:blocks_available)
|
64
|
+
expect(@stat.blocks_available).to be_kind_of(Numeric)
|
65
|
+
end
|
66
|
+
|
67
|
+
example "stat files works as expected" do
|
68
|
+
expect(@stat).to respond_to(:files)
|
69
|
+
expect(@stat.files).to be_kind_of(Numeric)
|
70
|
+
end
|
71
|
+
|
72
|
+
example "stat inodes is an alias for files" do
|
73
|
+
expect(@stat).to respond_to(:inodes)
|
74
|
+
expect(@stat.method(:inodes)).to eq(@stat.method(:files))
|
75
|
+
end
|
76
|
+
|
77
|
+
example "stat files tree works as expected" do
|
78
|
+
expect(@stat).to respond_to(:files_free)
|
79
|
+
expect(@stat.files_free).to be_kind_of(Numeric)
|
80
|
+
end
|
81
|
+
|
82
|
+
example "stat inodes_free is an alias for files_free" do
|
83
|
+
expect(@stat).to respond_to(:inodes_free)
|
84
|
+
expect(@stat.method(:inodes_free)).to eq(@stat.method(:files_free))
|
85
|
+
end
|
86
|
+
|
87
|
+
example "stat files_available works as expected" do
|
88
|
+
expect(@stat).to respond_to(:files_available)
|
89
|
+
expect(@stat.files_available).to be_kind_of(Numeric)
|
90
|
+
end
|
91
|
+
|
92
|
+
example "stat inodes_available is an alias for files_available" do
|
93
|
+
expect(@stat).to respond_to(:inodes_available)
|
94
|
+
expect(@stat.method(:inodes_available)).to eq(@stat.method(:files_available))
|
95
|
+
end
|
96
|
+
|
97
|
+
example "stat filesystem_id works as expected" do
|
98
|
+
expect(@stat).to respond_to(:filesystem_id)
|
99
|
+
expect(@stat.filesystem_id).to be_kind_of(Integer)
|
100
|
+
end
|
101
|
+
|
102
|
+
example "stat flags works as expected" do
|
103
|
+
expect(@stat).to respond_to(:flags)
|
104
|
+
expect(@stat.flags).to be_kind_of(Numeric)
|
105
|
+
end
|
106
|
+
|
107
|
+
example "stat name_max works as expected" do
|
108
|
+
expect(@stat).to respond_to(:name_max)
|
109
|
+
expect(@stat.name_max).to be_kind_of(Numeric)
|
110
|
+
end
|
111
|
+
|
112
|
+
example "stat base_type works as expected" do
|
113
|
+
skip "base_type test skipped except on Solaris" unless solaris
|
114
|
+
|
115
|
+
expect(@stat).to respond_to(:base_type)
|
116
|
+
expect(@stat.base_type).to be_kind_of(String)
|
117
|
+
end
|
118
|
+
|
119
|
+
example "stat constants are defined" do
|
120
|
+
expect(Sys::Filesystem::Stat::RDONLY).not_to be_nil
|
121
|
+
expect(Sys::Filesystem::Stat::NOSUID).not_to be_nil
|
122
|
+
end
|
123
|
+
|
124
|
+
example "stat constants for solaris are defined" do
|
125
|
+
skip "NOTRUNC test skipped except on Solaris" unless solaris
|
126
|
+
expect(Sys::Filesystem::Stat::NOTRUNC).not_to be_nil
|
127
|
+
end
|
128
|
+
|
129
|
+
example "stat bytes_total works as expected" do
|
130
|
+
expect(@stat).to respond_to(:bytes_total)
|
131
|
+
expect(@stat.bytes_total).to be_kind_of(Numeric)
|
132
|
+
end
|
133
|
+
|
134
|
+
example "stat bytes_free works as expected" do
|
135
|
+
expect(@stat).to respond_to(:bytes_free)
|
136
|
+
expect(@stat.bytes_free).to be_kind_of(Numeric)
|
137
|
+
expect(@stat.blocks_free * @stat.fragment_size).to eq(@stat.bytes_free)
|
138
|
+
end
|
139
|
+
|
140
|
+
example "stat bytes_available works as expected" do
|
141
|
+
expect(@stat).to respond_to(:bytes_available)
|
142
|
+
expect(@stat.bytes_available).to be_kind_of(Numeric)
|
143
|
+
expect(@stat.blocks_available * @stat.fragment_size).to eq(@stat.bytes_available)
|
144
|
+
end
|
145
|
+
|
146
|
+
example "stat bytes works as expected" do
|
147
|
+
expect(@stat).to respond_to(:bytes_used)
|
148
|
+
expect(@stat.bytes_used).to be_kind_of(Numeric)
|
149
|
+
end
|
150
|
+
|
151
|
+
example "stat percent_used works as expected" do
|
152
|
+
expect(@stat).to respond_to(:percent_used)
|
153
|
+
expect(@stat.percent_used).to be_kind_of(Float)
|
154
|
+
end
|
155
|
+
|
156
|
+
example "stat singleton method requires an argument" do
|
157
|
+
expect{ Sys::Filesystem.stat }.to raise_error(ArgumentError)
|
158
|
+
end
|
159
|
+
|
160
|
+
example "stat case_insensitive method works as expected" do
|
161
|
+
expected = darwin ? true : false
|
162
|
+
expect(@stat.case_insensitive?).to eq(expected)
|
163
|
+
expect(Sys::Filesystem.stat(Dir.home).case_insensitive?).to eq(expected)
|
164
|
+
end
|
165
|
+
|
166
|
+
example "stat case_sensitive method works as expected" do
|
167
|
+
expected = darwin ? false : true
|
168
|
+
expect(@stat.case_sensitive?).to eq(expected)
|
169
|
+
expect(Sys::Filesystem.stat(Dir.home).case_sensitive?).to eq(expected)
|
170
|
+
end
|
171
|
+
|
172
|
+
example "numeric helper methods are defined" do
|
173
|
+
expect(@size).to respond_to(:to_kb)
|
174
|
+
expect(@size).to respond_to(:to_mb)
|
175
|
+
expect(@size).to respond_to(:to_gb)
|
176
|
+
expect(@size).to respond_to(:to_tb)
|
177
|
+
end
|
178
|
+
|
179
|
+
example "to_kb works as expected" do
|
180
|
+
expect(@size.to_kb).to eq(57344)
|
181
|
+
end
|
182
|
+
|
183
|
+
example "to_mb works as expected" do
|
184
|
+
expect(@size.to_mb).to eq(56)
|
185
|
+
end
|
186
|
+
|
187
|
+
example "to_gb works as expected" do
|
188
|
+
expect(@size.to_gb).to eq(0)
|
189
|
+
end
|
190
|
+
|
191
|
+
context "Filesystem.stat(Pathname)" do
|
192
|
+
before do
|
193
|
+
@stat_pathname = Sys::Filesystem.stat(Pathname.new(root))
|
194
|
+
end
|
195
|
+
|
196
|
+
example "stat with Pathname argument works as expected" do
|
197
|
+
expect(@stat_pathname.class).to eq(@stat.class)
|
198
|
+
expect(@stat_pathname.path).to eq(@stat.path)
|
199
|
+
expect(@stat_pathname.block_size).to eq(@stat.block_size)
|
200
|
+
expect(@stat_pathname.fragment_size).to eq(@stat.fragment_size)
|
201
|
+
expect(@stat_pathname.blocks).to eq(@stat.blocks)
|
202
|
+
expect(@stat_pathname.blocks_free).to eq(@stat.blocks_free)
|
203
|
+
expect(@stat_pathname.blocks_available).to eq(@stat.blocks_available)
|
204
|
+
expect(@stat_pathname.files).to eq(@stat.files)
|
205
|
+
expect(@stat_pathname.files_free).to eq(@stat.files_free)
|
206
|
+
expect(@stat_pathname.files_available).to eq(@stat.files_available)
|
207
|
+
expect(@stat_pathname.filesystem_id).to eq(@stat.filesystem_id)
|
208
|
+
expect(@stat_pathname.flags).to eq(@stat.flags)
|
209
|
+
expect(@stat_pathname.name_max).to eq(@stat.name_max)
|
210
|
+
expect(@stat_pathname.base_type).to eq(@stat.base_type)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context "Filesystem.stat(File)" do
|
215
|
+
before do
|
216
|
+
@stat_file = File.open(root){ |file| Sys::Filesystem.stat(file) }
|
217
|
+
end
|
218
|
+
|
219
|
+
example "stat with File argument works as expected" do
|
220
|
+
expect(@stat_file.class).to eq(@stat.class)
|
221
|
+
expect(@stat_file.path).to eq(@stat.path)
|
222
|
+
expect(@stat_file.block_size).to eq(@stat.block_size)
|
223
|
+
expect(@stat_file.fragment_size).to eq(@stat.fragment_size)
|
224
|
+
expect(@stat_file.blocks).to eq(@stat.blocks)
|
225
|
+
expect(@stat_file.blocks_free).to eq(@stat.blocks_free)
|
226
|
+
expect(@stat_file.blocks_available).to eq(@stat.blocks_available)
|
227
|
+
expect(@stat_file.files).to eq(@stat.files)
|
228
|
+
expect(@stat_file.files_free).to eq(@stat.files_free)
|
229
|
+
expect(@stat_file.files_available).to eq(@stat.files_available)
|
230
|
+
expect(@stat_file.filesystem_id).to eq(@stat.filesystem_id)
|
231
|
+
expect(@stat_file.flags).to eq(@stat.flags)
|
232
|
+
expect(@stat_file.name_max).to eq(@stat.name_max)
|
233
|
+
expect(@stat_file.base_type).to eq(@stat.base_type)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
context "Filesystem.stat(Dir)" do
|
238
|
+
before do
|
239
|
+
@stat_dir = Dir.open(root){ |dir| Sys::Filesystem.stat(dir) }
|
240
|
+
end
|
241
|
+
|
242
|
+
example "stat with Dir argument works as expected" do
|
243
|
+
expect(@stat_dir.class).to eq(@stat.class)
|
244
|
+
expect(@stat_dir.path).to eq(@stat.path)
|
245
|
+
expect(@stat_dir.block_size).to eq(@stat.block_size)
|
246
|
+
expect(@stat_dir.fragment_size).to eq(@stat.fragment_size)
|
247
|
+
expect(@stat_dir.blocks).to eq(@stat.blocks)
|
248
|
+
expect(@stat_dir.blocks_free).to eq(@stat.blocks_free)
|
249
|
+
expect(@stat_dir.blocks_available).to eq(@stat.blocks_available)
|
250
|
+
expect(@stat_dir.files).to eq(@stat.files)
|
251
|
+
expect(@stat_dir.files_free).to eq(@stat.files_free)
|
252
|
+
expect(@stat_dir.files_available).to eq(@stat.files_available)
|
253
|
+
expect(@stat_dir.filesystem_id).to eq(@stat.filesystem_id)
|
254
|
+
expect(@stat_dir.flags).to eq(@stat.flags)
|
255
|
+
expect(@stat_dir.name_max).to eq(@stat.name_max)
|
256
|
+
expect(@stat_dir.base_type).to eq(@stat.base_type)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
context "Filesystem::Mount" do
|
261
|
+
let(:mount){ Sys::Filesystem.mounts[0] }
|
262
|
+
|
263
|
+
before do
|
264
|
+
@array = []
|
265
|
+
end
|
266
|
+
|
267
|
+
example "mounts singleton method works as expected without a block" do
|
268
|
+
expect{ @array = Sys::Filesystem.mounts }.not_to raise_error
|
269
|
+
expect(@array[0]).to be_kind_of(Sys::Filesystem::Mount)
|
270
|
+
end
|
271
|
+
|
272
|
+
example "mounts singleton method works as expected with a block" do
|
273
|
+
expect{ Sys::Filesystem.mounts{ |m| @array << m } }.not_to raise_error
|
274
|
+
expect(@array[0]).to be_kind_of(Sys::Filesystem::Mount)
|
275
|
+
end
|
276
|
+
|
277
|
+
example "calling the mounts singleton method a large number of times does not cause issues" do
|
278
|
+
expect{ 1000.times{ @array = Sys::Filesystem.mounts } }.not_to raise_error
|
279
|
+
end
|
280
|
+
|
281
|
+
example "mount name method works as expected" do
|
282
|
+
expect(mount).to respond_to(:name)
|
283
|
+
expect(mount.name).to be_kind_of(String)
|
284
|
+
end
|
285
|
+
|
286
|
+
example "mount fsname is an alias for name" do
|
287
|
+
expect(mount).to respond_to(:fsname)
|
288
|
+
expect(mount.method(:fsname)).to eq(mount.method(:name))
|
289
|
+
end
|
290
|
+
|
291
|
+
example "mount point method works as expected" do
|
292
|
+
expect(mount).to respond_to(:mount_point)
|
293
|
+
expect(mount.mount_point).to be_kind_of(String)
|
294
|
+
end
|
295
|
+
|
296
|
+
example "mount dir is an alias for mount_point" do
|
297
|
+
expect(mount).to respond_to(:dir)
|
298
|
+
expect(mount.method(:dir)).to eq(mount.method(:mount_point))
|
299
|
+
end
|
300
|
+
|
301
|
+
example "mount mount_type works as expected" do
|
302
|
+
expect(mount).to respond_to(:mount_type)
|
303
|
+
expect(mount.mount_type).to be_kind_of(String)
|
304
|
+
end
|
305
|
+
|
306
|
+
example "mount options works as expected" do
|
307
|
+
expect(mount).to respond_to(:options)
|
308
|
+
expect(mount.options).to be_kind_of(String)
|
309
|
+
end
|
310
|
+
|
311
|
+
example "mount opts is an alias for options" do
|
312
|
+
expect(mount).to respond_to(:opts)
|
313
|
+
expect(mount.method(:opts)).to eq(mount.method(:options))
|
314
|
+
end
|
315
|
+
|
316
|
+
example "mount time works as expected" do
|
317
|
+
expect(mount).to respond_to(:mount_time)
|
318
|
+
|
319
|
+
if solaris
|
320
|
+
expect(mount.mount_time).to be_kind_of(Time)
|
321
|
+
else
|
322
|
+
expect(mount.mount_time).to be_nil
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
example "mount dump_frequency works as expected" do
|
327
|
+
msg = 'dump_frequency test skipped on this platform'
|
328
|
+
skip msg if solaris || bsd || darwin
|
329
|
+
expect(mount).to respond_to(:dump_frequency)
|
330
|
+
expect(mount.dump_frequency).to be_kind_of(Numeric)
|
331
|
+
end
|
332
|
+
|
333
|
+
example "mount freq is an alias for dump_frequency" do
|
334
|
+
expect(mount).to respond_to(:freq)
|
335
|
+
expect(mount.method(:freq)).to eq(mount.method(:dump_frequency))
|
336
|
+
end
|
337
|
+
|
338
|
+
example "mount pass_number works as expected" do
|
339
|
+
msg = 'pass_number test skipped on this platform'
|
340
|
+
skip msg if solaris || bsd || darwin
|
341
|
+
expect(mount).to respond_to(:pass_number)
|
342
|
+
expect(mount.pass_number).to be_kind_of(Numeric)
|
343
|
+
end
|
344
|
+
|
345
|
+
example "mount passno is an alias for pass_number" do
|
346
|
+
expect(mount).to respond_to(:passno)
|
347
|
+
expect(mount.method(:passno)).to eq(mount.method(:pass_number))
|
348
|
+
end
|
349
|
+
|
350
|
+
example "mount_point singleton method works as expected" do
|
351
|
+
expect(Sys::Filesystem).to respond_to(:mount_point)
|
352
|
+
expect{ Sys::Filesystem.mount_point(Dir.pwd) }.not_to raise_error
|
353
|
+
expect(Sys::Filesystem.mount_point(Dir.pwd)).to be_kind_of(String)
|
354
|
+
end
|
355
|
+
|
356
|
+
example "mount singleton method is defined" do
|
357
|
+
expect(Sys::Filesystem).to respond_to(:mount)
|
358
|
+
end
|
359
|
+
|
360
|
+
example "umount singleton method is defined" do
|
361
|
+
expect(Sys::Filesystem).to respond_to(:umount)
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
context "FFI" do
|
366
|
+
before(:context) do
|
367
|
+
require 'mkmf-lite'
|
368
|
+
end
|
369
|
+
|
370
|
+
let(:dummy) { Class.new { extend Mkmf::Lite } }
|
371
|
+
|
372
|
+
example "ffi functions are private" do
|
373
|
+
expect(Sys::Filesystem.methods.include?('statvfs')).to be false
|
374
|
+
expect(Sys::Filesystem.methods.include?('strerror')).to be false
|
375
|
+
end
|
376
|
+
|
377
|
+
example "statfs struct is expected size" do
|
378
|
+
header = bsd || darwin ? 'sys/mount.h' : 'sys/statfs.h'
|
379
|
+
expect(Sys::Filesystem::Structs::Statfs.size).to eq(dummy.check_sizeof('struct statfs', header))
|
380
|
+
end
|
381
|
+
|
382
|
+
example "statvfs struct is expected size" do
|
383
|
+
expect(Sys::Filesystem::Structs::Statvfs.size).to eq(dummy.check_sizeof('struct statvfs', 'sys/statvfs.h'))
|
384
|
+
end
|
385
|
+
|
386
|
+
example "mnttab struct is expected size" do
|
387
|
+
skip "mnttab test skipped except on Solaris" unless solaris
|
388
|
+
expect(Sys::Filesystem::Structs::Mnttab.size).to eq(dummy.check_sizeof('struct mnttab', 'sys/mnttab.h'))
|
389
|
+
end
|
390
|
+
|
391
|
+
example "mntent struct is expected size" do
|
392
|
+
skip "mnttab test skipped except on Linux" unless linux
|
393
|
+
expect(Sys::Filesystem::Structs::Mntent.size).to eq(dummy.check_sizeof('struct mntent', 'mntent.h'))
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|