sys-filesystem 1.3.4 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/{CHANGES.rdoc → CHANGES.md} +33 -25
- data/Gemfile +9 -0
- data/{MANIFEST.rdoc → MANIFEST.md} +1 -0
- data/README.md +87 -0
- data/Rakefile +12 -22
- data/lib/sys/filesystem.rb +1 -1
- data/lib/sys/unix/sys/filesystem.rb +20 -0
- data/lib/sys/unix/sys/filesystem/structs.rb +15 -0
- data/lib/sys/windows/sys/filesystem.rb +16 -1
- data/spec/spec_helper.rb +6 -0
- data/spec/sys_filesystem_unix_spec.rb +389 -0
- data/spec/sys_filesystem_windows_spec.rb +344 -0
- data/sys-filesystem.gemspec +6 -8
- metadata +41 -55
- metadata.gz.sig +0 -0
- data/README.rdoc +0 -77
- data/test/test_sys_filesystem.rb +0 -7
- data/test/test_sys_filesystem_unix.rb +0 -329
- data/test/test_sys_filesystem_windows.rb +0 -303
metadata.gz.sig
CHANGED
Binary file
|
data/README.rdoc
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
== Description
|
2
|
-
A cross platform Ruby interface for getting file system information.
|
3
|
-
|
4
|
-
== Installation
|
5
|
-
gem install sys-filesystem
|
6
|
-
|
7
|
-
== Synopsis
|
8
|
-
require 'sys/filesystem'
|
9
|
-
include Sys
|
10
|
-
|
11
|
-
# Display information about a particular filesystem.
|
12
|
-
p Filesystem.stat('/')
|
13
|
-
|
14
|
-
# Sample output
|
15
|
-
|
16
|
-
#<Sys::Filesystem::Stat:0x517440
|
17
|
-
@base_type = "ufs",
|
18
|
-
@flags = 4,
|
19
|
-
@files_available = 3817457,
|
20
|
-
@block_size = 8192,
|
21
|
-
@blocks_available = 19957633,
|
22
|
-
@blocks = 34349612,
|
23
|
-
@name_max = 255,
|
24
|
-
@path = "/",
|
25
|
-
@filesystem_id = 35651592,
|
26
|
-
@files = 4135040,
|
27
|
-
@fragment_size = 1024,
|
28
|
-
@files_free = 3817457,
|
29
|
-
@blocks_free = 20301129
|
30
|
-
>
|
31
|
-
|
32
|
-
# Describe all mount points on the system
|
33
|
-
Filesystem.mounts{ |mount| p mount }
|
34
|
-
|
35
|
-
# Find the mount point of any particular file
|
36
|
-
puts Filesystem.mount_point('/home/djberge/some_file.txt') => '/home'
|
37
|
-
|
38
|
-
== Notes
|
39
|
-
This is a pure Ruby implementation that uses FFI. This means it should work
|
40
|
-
with JRuby, too.
|
41
|
-
|
42
|
-
== Sample code
|
43
|
-
Run 'rake example' if you want to see a basic sample run. The actual code
|
44
|
-
is 'example_stat.rb' in the 'examples' directory. Modify it as you see fit.
|
45
|
-
|
46
|
-
== Known Bugs
|
47
|
-
None that I'm aware of. Please report bugs on the project page at:
|
48
|
-
|
49
|
-
https://github.com/djberg96/sys-filesystem
|
50
|
-
|
51
|
-
== Future Plans
|
52
|
-
|
53
|
-
* Add better 64-bit support for Linux and BSD.
|
54
|
-
* Other suggestions welcome.
|
55
|
-
|
56
|
-
== Acknowledgements
|
57
|
-
Mike Hall, for ideas and code that I borrowed from his 'filesystem' library.
|
58
|
-
|
59
|
-
Park Heesob, for implementation and API ideas for the MS Windows version.
|
60
|
-
|
61
|
-
Nobuyoshi Miyokawa, for adding the original FreeBSD and OS X support.
|
62
|
-
|
63
|
-
== License
|
64
|
-
Apache-2.0
|
65
|
-
|
66
|
-
== Copyright
|
67
|
-
(C) 2003-2019 Daniel J. Berger
|
68
|
-
|
69
|
-
All Rights Reserved
|
70
|
-
|
71
|
-
== Warranty
|
72
|
-
This library is provided "as is" and without any express or
|
73
|
-
implied warranties, including, without limitation, the implied
|
74
|
-
warranties of merchantability and fitness for a particular purpose.
|
75
|
-
|
76
|
-
== Author
|
77
|
-
Daniel J. Berger
|
data/test/test_sys_filesystem.rb
DELETED
@@ -1,329 +0,0 @@
|
|
1
|
-
####################################################################
|
2
|
-
# test_sys_filesystem_unix.rb
|
3
|
-
#
|
4
|
-
# Test case for the Sys::Filesystem.stat method and related stuff.
|
5
|
-
# This test suite should be run via the 'rake test' task.
|
6
|
-
####################################################################
|
7
|
-
require 'test-unit'
|
8
|
-
require 'sys-filesystem'
|
9
|
-
require 'mkmf-lite'
|
10
|
-
include Sys
|
11
|
-
include Mkmf::Lite
|
12
|
-
|
13
|
-
class TC_Sys_Filesystem_Unix < Test::Unit::TestCase
|
14
|
-
def self.startup
|
15
|
-
@@solaris = RbConfig::CONFIG['host_os'] =~ /solaris/i
|
16
|
-
@@linux = RbConfig::CONFIG['host_os'] =~ /linux/i
|
17
|
-
@@freebsd = RbConfig::CONFIG['host_os'] =~ /freebsd/i
|
18
|
-
@@darwin = RbConfig::CONFIG['host_os'] =~ /darwin/i
|
19
|
-
end
|
20
|
-
|
21
|
-
def setup
|
22
|
-
@dir = "/"
|
23
|
-
@stat = Filesystem.stat(@dir)
|
24
|
-
@mnt = Filesystem.mounts[0]
|
25
|
-
@size = 58720256
|
26
|
-
@array = []
|
27
|
-
end
|
28
|
-
|
29
|
-
test "version number is set to the expected value" do
|
30
|
-
assert_equal('1.3.4', Filesystem::VERSION)
|
31
|
-
assert_true(Filesystem::VERSION.frozen?)
|
32
|
-
end
|
33
|
-
|
34
|
-
test "stat path works as expected" do
|
35
|
-
assert_respond_to(@stat, :path)
|
36
|
-
assert_equal("/", @stat.path)
|
37
|
-
end
|
38
|
-
|
39
|
-
test "stat block_size works as expected" do
|
40
|
-
assert_respond_to(@stat, :block_size)
|
41
|
-
assert_kind_of(Numeric, @stat.block_size)
|
42
|
-
end
|
43
|
-
|
44
|
-
test "stat fragment_size works as expected" do
|
45
|
-
assert_respond_to(@stat, :fragment_size)
|
46
|
-
assert_kind_of(Numeric, @stat.fragment_size)
|
47
|
-
end
|
48
|
-
|
49
|
-
test "stat fragment_size is a plausible value" do
|
50
|
-
assert_true(@stat.fragment_size >= 512)
|
51
|
-
assert_true(@stat.fragment_size <= 16384)
|
52
|
-
end
|
53
|
-
|
54
|
-
test "stat blocks works as expected" do
|
55
|
-
assert_respond_to(@stat, :blocks)
|
56
|
-
assert_kind_of(Numeric, @stat.blocks)
|
57
|
-
end
|
58
|
-
|
59
|
-
test "stat blocks_free works as expected" do
|
60
|
-
assert_respond_to(@stat, :blocks_free)
|
61
|
-
assert_kind_of(Numeric, @stat.blocks_free)
|
62
|
-
end
|
63
|
-
|
64
|
-
test "stat blocks_available works as expected" do
|
65
|
-
assert_respond_to(@stat, :blocks_available)
|
66
|
-
assert_kind_of(Numeric, @stat.blocks_available)
|
67
|
-
end
|
68
|
-
|
69
|
-
test "stat files works as expected" do
|
70
|
-
assert_respond_to(@stat, :files)
|
71
|
-
assert_kind_of(Numeric, @stat.files)
|
72
|
-
end
|
73
|
-
|
74
|
-
test "stat inodes is an alias for files" do
|
75
|
-
assert_respond_to(@stat, :inodes)
|
76
|
-
assert_true(@stat.method(:inodes) == @stat.method(:files))
|
77
|
-
end
|
78
|
-
|
79
|
-
test "stat files tree works as expected" do
|
80
|
-
assert_respond_to(@stat, :files_free)
|
81
|
-
assert_kind_of(Numeric, @stat.files_free)
|
82
|
-
end
|
83
|
-
|
84
|
-
test "stat inodes_free is an alias for files_free" do
|
85
|
-
assert_respond_to(@stat, :inodes_free)
|
86
|
-
assert_true(@stat.method(:inodes_free) == @stat.method(:files_free))
|
87
|
-
end
|
88
|
-
|
89
|
-
test "stat files_available works as expected" do
|
90
|
-
assert_respond_to(@stat, :files_available)
|
91
|
-
assert_kind_of(Numeric, @stat.files_available)
|
92
|
-
end
|
93
|
-
|
94
|
-
test "stat inodes_available is an alias for files_available" do
|
95
|
-
assert_respond_to(@stat, :inodes_available)
|
96
|
-
assert_true(@stat.method(:inodes_available) == @stat.method(:files_available))
|
97
|
-
end
|
98
|
-
|
99
|
-
test "stat filesystem_id works as expected" do
|
100
|
-
assert_respond_to(@stat, :filesystem_id)
|
101
|
-
assert_kind_of(Integer, @stat.filesystem_id)
|
102
|
-
end
|
103
|
-
|
104
|
-
test "stat flags works as expected" do
|
105
|
-
assert_respond_to(@stat, :flags)
|
106
|
-
assert_kind_of(Numeric, @stat.flags)
|
107
|
-
end
|
108
|
-
|
109
|
-
test "stat name_max works as expected" do
|
110
|
-
assert_respond_to(@stat, :name_max)
|
111
|
-
assert_kind_of(Numeric, @stat.name_max)
|
112
|
-
end
|
113
|
-
|
114
|
-
test "stat base_type works as expected" do
|
115
|
-
omit_unless(@@solaris, "base_type test skipped except on Solaris")
|
116
|
-
|
117
|
-
assert_respond_to(@stat, :base_type)
|
118
|
-
assert_kind_of(String, @stat.base_type)
|
119
|
-
end
|
120
|
-
|
121
|
-
test "stat constants are defined" do
|
122
|
-
assert_not_nil(Filesystem::Stat::RDONLY)
|
123
|
-
assert_not_nil(Filesystem::Stat::NOSUID)
|
124
|
-
|
125
|
-
omit_unless(@@solaris, "NOTRUNC test skipped except on Solaris")
|
126
|
-
|
127
|
-
assert_not_nil(Filesystem::Stat::NOTRUNC)
|
128
|
-
end
|
129
|
-
|
130
|
-
test "stat bytes_total works as expected" do
|
131
|
-
assert_respond_to(@stat, :bytes_total)
|
132
|
-
assert_kind_of(Numeric, @stat.bytes_total)
|
133
|
-
end
|
134
|
-
|
135
|
-
test "stat bytes_free works as expected" do
|
136
|
-
assert_respond_to(@stat, :bytes_free)
|
137
|
-
assert_kind_of(Numeric, @stat.bytes_free)
|
138
|
-
assert_equal(@stat.bytes_free, @stat.blocks_free * @stat.fragment_size)
|
139
|
-
end
|
140
|
-
|
141
|
-
test "stat bytes_available works as expected" do
|
142
|
-
assert_respond_to(@stat, :bytes_available)
|
143
|
-
assert_kind_of(Numeric, @stat.bytes_available)
|
144
|
-
assert_equal(@stat.bytes_available, @stat.blocks_available * @stat.fragment_size)
|
145
|
-
end
|
146
|
-
|
147
|
-
test "stat bytes works as expected" do
|
148
|
-
assert_respond_to(@stat, :bytes_used)
|
149
|
-
assert_kind_of(Numeric, @stat.bytes_used)
|
150
|
-
end
|
151
|
-
|
152
|
-
test "stat percent_used works as expected" do
|
153
|
-
assert_respond_to(@stat, :percent_used)
|
154
|
-
assert_kind_of(Float, @stat.percent_used)
|
155
|
-
end
|
156
|
-
|
157
|
-
test "stat singleton method requires an argument" do
|
158
|
-
assert_raises(ArgumentError){ Filesystem.stat }
|
159
|
-
end
|
160
|
-
|
161
|
-
test "stat case_insensitive method works as expected" do
|
162
|
-
expected = @@darwin ? true : false
|
163
|
-
assert_equal(expected, @stat.case_insensitive?)
|
164
|
-
assert_equal(expected, Filesystem.stat(Dir.home).case_insensitive?)
|
165
|
-
end
|
166
|
-
|
167
|
-
test "stat case_sensitive method works as expected" do
|
168
|
-
expected = @@darwin ? false : true
|
169
|
-
assert_equal(expected, @stat.case_sensitive?)
|
170
|
-
assert_equal(expected, Filesystem.stat(Dir.home).case_sensitive?)
|
171
|
-
end
|
172
|
-
|
173
|
-
test "numeric helper methods are defined" do
|
174
|
-
assert_respond_to(@size, :to_kb)
|
175
|
-
assert_respond_to(@size, :to_mb)
|
176
|
-
assert_respond_to(@size, :to_gb)
|
177
|
-
assert_respond_to(@size, :to_tb)
|
178
|
-
end
|
179
|
-
|
180
|
-
test "to_kb works as expected" do
|
181
|
-
assert_equal(57344, @size.to_kb)
|
182
|
-
end
|
183
|
-
|
184
|
-
test "to_mb works as expected" do
|
185
|
-
assert_equal(56, @size.to_mb)
|
186
|
-
end
|
187
|
-
|
188
|
-
test "to_gb works as expected" do
|
189
|
-
assert_equal(0, @size.to_gb)
|
190
|
-
end
|
191
|
-
|
192
|
-
# Filesystem::Mount tests
|
193
|
-
|
194
|
-
test "mounts singleton method works as expected without a block" do
|
195
|
-
assert_nothing_raised{ @array = Filesystem.mounts }
|
196
|
-
assert_kind_of(Filesystem::Mount, @array[0])
|
197
|
-
end
|
198
|
-
|
199
|
-
test "mounts singleton method works as expected with a block" do
|
200
|
-
assert_nothing_raised{ Filesystem.mounts{ |m| @array << m } }
|
201
|
-
assert_kind_of(Filesystem::Mount, @array[0])
|
202
|
-
end
|
203
|
-
|
204
|
-
test "calling the mounts singleton method a large number of times does not cause issues" do
|
205
|
-
assert_nothing_raised{ 1000.times{ @array = Filesystem.mounts } }
|
206
|
-
end
|
207
|
-
|
208
|
-
test "mount name method works as expected" do
|
209
|
-
assert_respond_to(@mnt, :name)
|
210
|
-
assert_kind_of(String, @mnt.name)
|
211
|
-
end
|
212
|
-
|
213
|
-
test "mount fsname is an alias for name" do
|
214
|
-
assert_respond_to(@mnt, :fsname)
|
215
|
-
assert_true(@mnt.method(:fsname) == @mnt.method(:name))
|
216
|
-
end
|
217
|
-
|
218
|
-
test "mount point method works as expected" do
|
219
|
-
assert_respond_to(@mnt, :mount_point)
|
220
|
-
assert_kind_of(String, @mnt.mount_point)
|
221
|
-
end
|
222
|
-
|
223
|
-
test "mount dir is an alias for mount_point" do
|
224
|
-
assert_respond_to(@mnt, :dir)
|
225
|
-
assert_true(@mnt.method(:dir) == @mnt.method(:mount_point))
|
226
|
-
end
|
227
|
-
|
228
|
-
test "mount mount_type works as expected" do
|
229
|
-
assert_respond_to(@mnt, :mount_type)
|
230
|
-
assert_kind_of(String, @mnt.mount_type)
|
231
|
-
end
|
232
|
-
|
233
|
-
test "mount options works as expected" do
|
234
|
-
assert_respond_to(@mnt, :options)
|
235
|
-
assert_kind_of(String, @mnt.options)
|
236
|
-
end
|
237
|
-
|
238
|
-
test "mount opts is an alias for options" do
|
239
|
-
assert_respond_to(@mnt, :opts)
|
240
|
-
assert_true(@mnt.method(:opts) == @mnt.method(:options))
|
241
|
-
end
|
242
|
-
|
243
|
-
test "mount time works as expected" do
|
244
|
-
assert_respond_to(@mnt, :mount_time)
|
245
|
-
|
246
|
-
if @@solaris
|
247
|
-
assert_kind_of(Time, @mnt.mount_time)
|
248
|
-
else
|
249
|
-
assert_nil(@mnt.mount_time)
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
test "mount dump_frequency works as expected" do
|
254
|
-
msg = 'dump_frequency test skipped on this platform'
|
255
|
-
omit_if(@@solaris || @@freebsd || @@darwin, msg)
|
256
|
-
assert_respond_to(@mnt, :dump_frequency)
|
257
|
-
assert_kind_of(Numeric, @mnt.dump_frequency)
|
258
|
-
end
|
259
|
-
|
260
|
-
test "mount freq is an alias for dump_frequency" do
|
261
|
-
assert_respond_to(@mnt, :freq)
|
262
|
-
assert_true(@mnt.method(:freq) == @mnt.method(:dump_frequency))
|
263
|
-
end
|
264
|
-
|
265
|
-
test "mount pass_number works as expected" do
|
266
|
-
msg = 'pass_number test skipped on this platform'
|
267
|
-
omit_if(@@solaris || @@freebsd || @@darwin, msg)
|
268
|
-
assert_respond_to(@mnt, :pass_number)
|
269
|
-
assert_kind_of(Numeric, @mnt.pass_number)
|
270
|
-
end
|
271
|
-
|
272
|
-
test "mount passno is an alias for pass_number" do
|
273
|
-
assert_respond_to(@mnt, :passno)
|
274
|
-
assert_true(@mnt.method(:passno) == @mnt.method(:pass_number))
|
275
|
-
end
|
276
|
-
|
277
|
-
test "mount_point singleton method works as expected" do
|
278
|
-
assert_respond_to(Filesystem, :mount_point)
|
279
|
-
assert_nothing_raised{ Filesystem.mount_point(Dir.pwd) }
|
280
|
-
assert_kind_of(String, Filesystem.mount_point(Dir.pwd))
|
281
|
-
end
|
282
|
-
|
283
|
-
test "mount singleton method is defined" do
|
284
|
-
assert_respond_to(Sys::Filesystem, :mount)
|
285
|
-
end
|
286
|
-
|
287
|
-
test "umount singleton method is defined" do
|
288
|
-
assert_respond_to(Sys::Filesystem, :umount)
|
289
|
-
end
|
290
|
-
|
291
|
-
# FFI
|
292
|
-
|
293
|
-
test "ffi functions are private" do
|
294
|
-
assert_false(Filesystem.methods.include?('statvfs'))
|
295
|
-
assert_false(Filesystem.methods.include?('strerror'))
|
296
|
-
end
|
297
|
-
|
298
|
-
test "statfs struct is expected size" do
|
299
|
-
header = @@freebsd || @@darwin ? 'sys/mount.h' : 'sys/statfs.h'
|
300
|
-
assert_equal(check_sizeof('struct statfs', header), Filesystem::Structs::Statfs.size)
|
301
|
-
end
|
302
|
-
|
303
|
-
test "statvfs struct is expected size" do
|
304
|
-
assert_equal(check_sizeof('struct statvfs', 'sys/statvfs.h'), Filesystem::Structs::Statvfs.size)
|
305
|
-
end
|
306
|
-
|
307
|
-
test "mnttab struct is expected size" do
|
308
|
-
omit_unless(@@solaris, "mnttab test skipped except on Solaris")
|
309
|
-
assert_equal(check_sizeof('struct mnttab', 'sys/mnttab.h'), Filesystem::Structs::Mnttab.size)
|
310
|
-
end
|
311
|
-
|
312
|
-
test "mntent struct is expected size" do
|
313
|
-
omit_unless(@@linux, "mnttab test skipped except on Linux")
|
314
|
-
assert_equal(check_sizeof('struct mntent', 'mntent.h'), Filesystem::Structs::Mntent.size)
|
315
|
-
end
|
316
|
-
|
317
|
-
def teardown
|
318
|
-
@dir = nil
|
319
|
-
@stat = nil
|
320
|
-
@array = nil
|
321
|
-
end
|
322
|
-
|
323
|
-
def self.shutdown
|
324
|
-
@@solaris = nil
|
325
|
-
@@linux = nil
|
326
|
-
@@freebsd = nil
|
327
|
-
@@darwin = nil
|
328
|
-
end
|
329
|
-
end
|
@@ -1,303 +0,0 @@
|
|
1
|
-
####################################################################
|
2
|
-
# test_sys_filesystem_windows.rb
|
3
|
-
#
|
4
|
-
# Test case for the Sys::Filesystem.stat method and related stuff.
|
5
|
-
# This should be run via the 'rake test' task.
|
6
|
-
####################################################################
|
7
|
-
require 'test-unit'
|
8
|
-
require 'sys/filesystem'
|
9
|
-
require 'rbconfig'
|
10
|
-
require 'pathname'
|
11
|
-
include Sys
|
12
|
-
|
13
|
-
class TC_Sys_Filesystem_Windows < Test::Unit::TestCase
|
14
|
-
def setup
|
15
|
-
@dir = 'C:/'
|
16
|
-
@stat = Filesystem.stat(@dir)
|
17
|
-
@mount = Filesystem.mounts[0]
|
18
|
-
@size = 58720256
|
19
|
-
@array = []
|
20
|
-
end
|
21
|
-
|
22
|
-
test "version number is set to the expected value" do
|
23
|
-
assert_equal('1.3.4', Filesystem::VERSION)
|
24
|
-
assert_true(Filesystem::VERSION.frozen?)
|
25
|
-
end
|
26
|
-
|
27
|
-
test "stat path works as expected" do
|
28
|
-
assert_respond_to(@stat, :path)
|
29
|
-
assert_equal("C:/", @stat.path)
|
30
|
-
end
|
31
|
-
|
32
|
-
test "stat block_size works as expected" do
|
33
|
-
assert_respond_to(@stat, :block_size)
|
34
|
-
assert_kind_of(Numeric, @stat.block_size)
|
35
|
-
end
|
36
|
-
|
37
|
-
test "stat works with or without trailing slash on standard paths" do
|
38
|
-
assert_equal("C:/", Filesystem.stat("C:/").path)
|
39
|
-
assert_equal("C:/Users", Filesystem.stat("C:/Users").path)
|
40
|
-
assert_equal("C:/Users/", Filesystem.stat("C:/Users/").path)
|
41
|
-
assert_equal("C:/Users/", Filesystem.stat("C:/Users/").path)
|
42
|
-
end
|
43
|
-
|
44
|
-
test "stat works with or without trailing slash on UNC paths" do
|
45
|
-
assert_equal("//127.0.0.1/C$", Filesystem.stat("//127.0.0.1/C$").path)
|
46
|
-
assert_equal("//127.0.0.1/C$/", Filesystem.stat("//127.0.0.1/C$/").path)
|
47
|
-
assert_equal("\\\\127.0.0.1\\C$", Filesystem.stat("\\\\127.0.0.1\\C$").path)
|
48
|
-
assert_equal("\\\\127.0.0.1\\C$\\", Filesystem.stat("\\\\127.0.0.1\\C$\\").path)
|
49
|
-
end
|
50
|
-
|
51
|
-
test "stat fragment_size works as expected" do
|
52
|
-
assert_respond_to(@stat, :fragment_size)
|
53
|
-
assert_nil(@stat.fragment_size)
|
54
|
-
end
|
55
|
-
|
56
|
-
test "stat blocks works as expected" do
|
57
|
-
assert_respond_to(@stat, :blocks)
|
58
|
-
assert_kind_of(Numeric, @stat.blocks)
|
59
|
-
end
|
60
|
-
|
61
|
-
test "stat blocks_free works as expected" do
|
62
|
-
assert_respond_to(@stat, :blocks_free)
|
63
|
-
assert_kind_of(Numeric, @stat.blocks_free)
|
64
|
-
end
|
65
|
-
|
66
|
-
test "stat blocks_available works as expected" do
|
67
|
-
assert_respond_to(@stat, :blocks_available)
|
68
|
-
assert_kind_of(Numeric, @stat.blocks_available)
|
69
|
-
end
|
70
|
-
|
71
|
-
test "block stats return expected relative values" do
|
72
|
-
assert_true(@stat.blocks >= @stat.blocks_free)
|
73
|
-
assert_true(@stat.blocks_free >= @stat.blocks_available)
|
74
|
-
end
|
75
|
-
|
76
|
-
test "stat files works as expected" do
|
77
|
-
assert_respond_to(@stat, :files)
|
78
|
-
assert_nil(@stat.files)
|
79
|
-
end
|
80
|
-
|
81
|
-
test "stat inodes is an alias for files" do
|
82
|
-
assert_alias_method(@stat, :inodes, :files)
|
83
|
-
end
|
84
|
-
|
85
|
-
test "stat files_free works as expected" do
|
86
|
-
assert_respond_to(@stat, :files_free)
|
87
|
-
assert_nil(@stat.files_free)
|
88
|
-
end
|
89
|
-
|
90
|
-
test "stat inodes_free is an alias for files_free" do
|
91
|
-
assert_respond_to(@stat, :inodes_free)
|
92
|
-
end
|
93
|
-
|
94
|
-
test "stat files available works as expected" do
|
95
|
-
assert_respond_to(@stat, :files_available)
|
96
|
-
assert_nil(@stat.files_available)
|
97
|
-
end
|
98
|
-
|
99
|
-
test "stat inodes_available is an alias for files_available" do
|
100
|
-
assert_alias_method(@stat, :inodes_available, :files_available)
|
101
|
-
end
|
102
|
-
|
103
|
-
test "stat filesystem_id works as expected" do
|
104
|
-
assert_respond_to(@stat, :filesystem_id)
|
105
|
-
assert_kind_of(Integer, @stat.filesystem_id)
|
106
|
-
end
|
107
|
-
|
108
|
-
test "stat flags works as expected" do
|
109
|
-
assert_respond_to(@stat, :flags)
|
110
|
-
assert_kind_of(Numeric, @stat.flags)
|
111
|
-
end
|
112
|
-
|
113
|
-
test "stat name_max works as expected" do
|
114
|
-
assert_respond_to(@stat, :name_max)
|
115
|
-
assert_kind_of(Numeric, @stat.name_max)
|
116
|
-
end
|
117
|
-
|
118
|
-
test "stat base_type works as expected" do
|
119
|
-
assert_respond_to(@stat, :base_type)
|
120
|
-
assert_kind_of(String, @stat.base_type)
|
121
|
-
end
|
122
|
-
|
123
|
-
test "stat bytes_total basic functionality" do
|
124
|
-
assert_respond_to(@stat, :bytes_total)
|
125
|
-
assert_kind_of(Numeric, @stat.bytes_total)
|
126
|
-
end
|
127
|
-
|
128
|
-
test "stat bytes_free basic functionality" do
|
129
|
-
assert_respond_to(@stat, :bytes_free)
|
130
|
-
assert_kind_of(Numeric, @stat.bytes_free)
|
131
|
-
assert_equal(@stat.bytes_free, @stat.blocks_free * @stat.block_size)
|
132
|
-
end
|
133
|
-
|
134
|
-
test "stat bytes_available basic functionality" do
|
135
|
-
assert_respond_to(@stat, :bytes_available)
|
136
|
-
assert_kind_of(Numeric, @stat.bytes_available)
|
137
|
-
assert_equal(@stat.bytes_available, @stat.blocks_available * @stat.block_size)
|
138
|
-
end
|
139
|
-
|
140
|
-
test "stat bytes_used basic functionality" do
|
141
|
-
assert_respond_to(@stat, :bytes_used)
|
142
|
-
assert_kind_of(Numeric, @stat.bytes_used)
|
143
|
-
end
|
144
|
-
|
145
|
-
test "stat percent_used basic functionality" do
|
146
|
-
assert_respond_to(@stat, :percent_used)
|
147
|
-
assert_kind_of(Float, @stat.percent_used)
|
148
|
-
end
|
149
|
-
|
150
|
-
test "case_insensitive returns expected result" do
|
151
|
-
assert_respond_to(@stat, :case_insensitive?)
|
152
|
-
assert_true(@stat.case_insensitive?)
|
153
|
-
end
|
154
|
-
|
155
|
-
test "mount_point singleton method basic functionality" do
|
156
|
-
assert_respond_to(Filesystem, :mount_point)
|
157
|
-
assert_nothing_raised{ Filesystem.mount_point(Dir.pwd) }
|
158
|
-
assert_kind_of(String, Filesystem.mount_point(Dir.pwd))
|
159
|
-
end
|
160
|
-
|
161
|
-
test "mount_point singleton method returns expected value" do
|
162
|
-
assert_equal("C:\\", Filesystem.mount_point("C:\\Users\\foo"))
|
163
|
-
assert_equal("\\\\foo\\bar", Filesystem.mount_point("//foo/bar/baz"))
|
164
|
-
end
|
165
|
-
|
166
|
-
test "mount_point works with Pathname object" do
|
167
|
-
assert_nothing_raised{ Filesystem.mount_point(Pathname.new("C:/Users/foo")) }
|
168
|
-
assert_equal("C:\\", Filesystem.mount_point("C:\\Users\\foo"))
|
169
|
-
assert_equal("\\\\foo\\bar", Filesystem.mount_point("//foo/bar/baz"))
|
170
|
-
end
|
171
|
-
|
172
|
-
test "filesystem constants are defined" do
|
173
|
-
assert_not_nil(Filesystem::CASE_SENSITIVE_SEARCH)
|
174
|
-
assert_not_nil(Filesystem::CASE_PRESERVED_NAMES)
|
175
|
-
assert_not_nil(Filesystem::UNICODE_ON_DISK)
|
176
|
-
assert_not_nil(Filesystem::PERSISTENT_ACLS)
|
177
|
-
assert_not_nil(Filesystem::FILE_COMPRESSION)
|
178
|
-
assert_not_nil(Filesystem::VOLUME_QUOTAS)
|
179
|
-
assert_not_nil(Filesystem::SUPPORTS_SPARSE_FILES)
|
180
|
-
assert_not_nil(Filesystem::SUPPORTS_REPARSE_POINTS)
|
181
|
-
assert_not_nil(Filesystem::SUPPORTS_REMOTE_STORAGE)
|
182
|
-
assert_not_nil(Filesystem::VOLUME_IS_COMPRESSED)
|
183
|
-
assert_not_nil(Filesystem::SUPPORTS_OBJECT_IDS)
|
184
|
-
assert_not_nil(Filesystem::SUPPORTS_ENCRYPTION)
|
185
|
-
assert_not_nil(Filesystem::NAMED_STREAMS)
|
186
|
-
assert_not_nil(Filesystem::READ_ONLY_VOLUME)
|
187
|
-
end
|
188
|
-
|
189
|
-
test "stat singleton method defaults to root path if proviced" do
|
190
|
-
assert_nothing_raised{ Filesystem.stat("C://Program Files") }
|
191
|
-
end
|
192
|
-
|
193
|
-
test "stat singleton method accepts a Pathname object" do
|
194
|
-
assert_nothing_raised{ Filesystem.stat(Pathname.new("C://Program Files")) }
|
195
|
-
end
|
196
|
-
|
197
|
-
test "stat singleton method requires a single argument" do
|
198
|
-
assert_raise(ArgumentError){ Filesystem.stat }
|
199
|
-
assert_raise(ArgumentError){ Filesystem.stat(Dir.pwd, Dir.pwd) }
|
200
|
-
end
|
201
|
-
|
202
|
-
test "stat singleton method raises an error if path is not found" do
|
203
|
-
assert_raise(Errno::ESRCH){ Filesystem.stat("C://Bogus//Dir") }
|
204
|
-
end
|
205
|
-
|
206
|
-
# Filesystem.mounts
|
207
|
-
|
208
|
-
test "mounts singleton method basic functionality" do
|
209
|
-
assert_respond_to(Filesystem, :mounts)
|
210
|
-
assert_nothing_raised{ Filesystem.mounts }
|
211
|
-
assert_nothing_raised{ Filesystem.mounts{} }
|
212
|
-
end
|
213
|
-
|
214
|
-
test "mounts singleton method returns the expected value" do
|
215
|
-
assert_kind_of(Array, Filesystem.mounts)
|
216
|
-
assert_kind_of(Filesystem::Mount, Filesystem.mounts[0])
|
217
|
-
end
|
218
|
-
|
219
|
-
test "mounts singleton method works as expected when a block is provided" do
|
220
|
-
assert_nil(Filesystem.mounts{})
|
221
|
-
assert_nothing_raised{ Filesystem.mounts{ |mt| @array << mt }}
|
222
|
-
assert_kind_of(Filesystem::Mount, @array[0])
|
223
|
-
end
|
224
|
-
|
225
|
-
test "mount name works as expected" do
|
226
|
-
assert_respond_to(@mount, :name)
|
227
|
-
assert_kind_of(String, @mount.name)
|
228
|
-
end
|
229
|
-
|
230
|
-
test "mount time works as expected" do
|
231
|
-
assert_respond_to(@mount, :mount_time)
|
232
|
-
assert_kind_of(Time, @mount.mount_time)
|
233
|
-
end
|
234
|
-
|
235
|
-
test "mount type works as expected" do
|
236
|
-
assert_respond_to(@mount, :mount_type)
|
237
|
-
assert_kind_of(String, @mount.mount_type)
|
238
|
-
end
|
239
|
-
|
240
|
-
test "mount point works as expected" do
|
241
|
-
assert_respond_to(@mount, :mount_point)
|
242
|
-
assert_kind_of(String, @mount.mount_point)
|
243
|
-
end
|
244
|
-
|
245
|
-
test "mount options works as expected" do
|
246
|
-
assert_respond_to(@mount, :options)
|
247
|
-
assert_kind_of(String, @mount.options)
|
248
|
-
end
|
249
|
-
|
250
|
-
test "mount pass_number works as expected" do
|
251
|
-
assert_respond_to(@mount, :pass_number)
|
252
|
-
assert_nil(@mount.pass_number)
|
253
|
-
end
|
254
|
-
|
255
|
-
test "mount frequency works as expected" do
|
256
|
-
assert_respond_to(@mount, :frequency)
|
257
|
-
assert_nil(@mount.frequency)
|
258
|
-
end
|
259
|
-
|
260
|
-
test "mounts singleton method does not accept any arguments" do
|
261
|
-
assert_raise(ArgumentError){ Filesystem.mounts("C:\\") }
|
262
|
-
end
|
263
|
-
|
264
|
-
test "custom Numeric#to_kb method works as expected" do
|
265
|
-
assert_respond_to(@size, :to_kb)
|
266
|
-
assert_equal(57344, @size.to_kb)
|
267
|
-
end
|
268
|
-
|
269
|
-
test "custom Numeric#to_mb method works as expected" do
|
270
|
-
assert_respond_to(@size, :to_mb)
|
271
|
-
assert_equal(56, @size.to_mb)
|
272
|
-
end
|
273
|
-
|
274
|
-
test "custom Numeric#to_gb method works as expected" do
|
275
|
-
assert_respond_to(@size, :to_gb)
|
276
|
-
assert_equal(0, @size.to_gb)
|
277
|
-
end
|
278
|
-
|
279
|
-
# Mount and Unmount
|
280
|
-
|
281
|
-
test "mount singleton method exists" do
|
282
|
-
assert_respond_to(Sys::Filesystem, :mount)
|
283
|
-
end
|
284
|
-
|
285
|
-
test "umount singleton method exists" do
|
286
|
-
assert_respond_to(Sys::Filesystem, :umount)
|
287
|
-
end
|
288
|
-
|
289
|
-
# FFI
|
290
|
-
|
291
|
-
test "internal ffi functions are not public" do
|
292
|
-
assert_false(Filesystem.methods.include?(:GetVolumeInformationA))
|
293
|
-
assert_false(Filesystem.instance_methods.include?(:GetVolumeInformationA))
|
294
|
-
end
|
295
|
-
|
296
|
-
def teardown
|
297
|
-
@array = nil
|
298
|
-
@dir = nil
|
299
|
-
@stat = nil
|
300
|
-
@size = nil
|
301
|
-
@mount = nil
|
302
|
-
end
|
303
|
-
end
|