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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf54720eed58f18d562942c0b1da0026bf0f814687de0fe5bab4cf49c90c39a3
|
4
|
+
data.tar.gz: 76baf71b511e2e36949d54b870f8f6d60d28fe0e735f4366cf69817e7359f09b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3052ebcc1437f04d4e798856553f5567d016789e6936ac494ac3bf7b327bc0386a212e73e1664c58c48c6ee79aba76986a4130678e00f572d359bd75020e3e94
|
7
|
+
data.tar.gz: ad1b00477d3a8afef57768689120203356ec636a5bab122879a2fa764a5eec3ade92d10b105eea00a6807c7c41445a2f8dc25711564970a250a491bcf06d606e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/{CHANGES.rdoc → CHANGES.md}
RENAMED
@@ -1,26 +1,34 @@
|
|
1
|
-
|
1
|
+
## 1.4.0 - 6-Sep-2020
|
2
|
+
* The Sys::Filesystem.stat method now accepts a Pathname and Dir object as
|
3
|
+
an argument. On most platforms it will also accept a File object. Thanks
|
4
|
+
go to hirura for the patch.
|
5
|
+
* Fixed the statvfs struct layout on i686 platforms. Thanks go to
|
6
|
+
Filipovici-Andrei for the patch.
|
7
|
+
* Switched from test-unit to rspec, and updated the tests.
|
8
|
+
|
9
|
+
## 1.3.4 - 17-Mar-2020
|
2
10
|
* Properly include a LICENSE file as per the Apache-2.0 license.
|
3
11
|
|
4
|
-
|
12
|
+
## 1.3.3 - 18-Feb-2020
|
5
13
|
* Linux now uses statvfs64 under the hood. This fixes a potential issue with
|
6
14
|
32 bit systems. Thanks go to Tom Smyth for the spot.
|
7
15
|
|
8
|
-
|
16
|
+
## 1.3.2 - 8-Dec-2019
|
9
17
|
* Renamed various text files to include .rdoc extension so that github renders
|
10
18
|
them nicely.
|
11
19
|
|
12
|
-
|
20
|
+
## 1.3.1 - 15-Oct-2019
|
13
21
|
* Fixed a bug where the Statvfs and Statfs structs were not allocated properly
|
14
22
|
on Linux, which could cause issues. Thanks go to Daniele Orlandi for the spot.
|
15
23
|
* Added specs to ensure that the FFI struct size matches the C struct size.
|
16
24
|
This required adding mkmf-lite as a development dependency.
|
17
25
|
* Added a slightly more pessimistic version requirement for test-unit.
|
18
26
|
|
19
|
-
|
27
|
+
## 1.3.0 - 3-Oct-2019
|
20
28
|
* Added the mount and umount singleton methods.
|
21
29
|
* Changed an internal class variable to a frozen constant.
|
22
30
|
|
23
|
-
|
31
|
+
## 1.2.0 - 1-Jan-2019
|
24
32
|
* Changed the license to Apache-2.0.
|
25
33
|
* Added the case_sensitive? and case_insensitive? instance methods to the
|
26
34
|
Filesystem::Stat class.
|
@@ -28,7 +36,7 @@
|
|
28
36
|
* Fixed the deprecation warnings when running the tests on Windows.
|
29
37
|
* Added metadata to the gemspec.
|
30
38
|
|
31
|
-
|
39
|
+
## 1.1.9 - 26-Jan-2018
|
32
40
|
* The bytes_free and bytes_total methods were updated to use the fragment size
|
33
41
|
instead of the block size. This fixes Macs using APFS, as well as Solaris 10.
|
34
42
|
Thanks go to Mikhail Vasin for the spot.
|
@@ -36,39 +44,39 @@
|
|
36
44
|
to address the issue now resolved by the above change.
|
37
45
|
* Updated the cert again.
|
38
46
|
|
39
|
-
|
47
|
+
## 1.1.8 - 2-Sep-2017
|
40
48
|
* The stat and mount_point methods now call to_s on the string argument
|
41
49
|
explicitly so that Pathname objects will now work with String#wincode.
|
42
50
|
* Updated some tests to avoid Fixnum warnings for Ruby 2.4.
|
43
51
|
* Updated the cert.
|
44
52
|
|
45
|
-
|
53
|
+
## 1.1.7 - 1-Aug-2016
|
46
54
|
* Fixed an issue in the stat method for MS Windows where the blocks_avail
|
47
55
|
value was not correct. Thanks go to Maxime Lapointe for the spot.
|
48
56
|
|
49
|
-
|
57
|
+
## 1.1.6 - 17-May-2016
|
50
58
|
* On versions that use setmntent or fopen, explicitly raise an error if
|
51
59
|
either of those calls return a null value.
|
52
60
|
|
53
|
-
|
61
|
+
## 1.1.5 - 5-Dec-2015
|
54
62
|
* This gem is now signed.
|
55
63
|
* The gem related tasks in the Rakefile now assume Rubygems 2.x.
|
56
64
|
* Updates to the gemspec, added cert_chain, removed rubyforge_project.
|
57
65
|
* Internal reorganization, and use of relative_require as appropriate.
|
58
66
|
* Added a sys-filesystem.rb file for convenience.
|
59
67
|
|
60
|
-
|
68
|
+
## 1.1.4 - 15-Mar-2015
|
61
69
|
* The File.mounts method no longer raises an error if a mount point
|
62
70
|
is not accessible. Thanks go to Michael Pope for the patch.
|
63
71
|
* Some internal code reorganization.
|
64
72
|
|
65
|
-
|
73
|
+
## 1.1.3 - 1-Oct-2014
|
66
74
|
* Now ignores EPERM errors when trying to find the mount point for a path.
|
67
75
|
Thanks go to petersen for the patch.
|
68
76
|
* The Filesystem.stat method now defaults to using the root path on Windows
|
69
77
|
for volume information.
|
70
78
|
|
71
|
-
|
79
|
+
## 1.1.2 - 9-May-2014
|
72
80
|
* Added the percent_used, bytes_total, bytes_free and bytes_used methods
|
73
81
|
to the Filesystem::Stat class. Thanks go to xanview for the suggestion.
|
74
82
|
* Changed File.exists? to File.exist? to avoid warnings in Ruby 2.1.x.
|
@@ -77,30 +85,30 @@
|
|
77
85
|
* Added the to_tb method for terabytes.
|
78
86
|
* Minor updates to the gem:create and gem:install Rake tasks.
|
79
87
|
|
80
|
-
|
88
|
+
## 1.1.1 - 3-Oct-2013
|
81
89
|
* Solaris now always uses statvfs64 on Solaris for better 64-bit support.
|
82
90
|
Thanks go to Jeff Shantz for the spot.
|
83
91
|
|
84
|
-
|
92
|
+
## 1.1.0 - 19-Jan-2013
|
85
93
|
* Converted the Windows source code to use FFI. Consequently, there is now
|
86
94
|
a single gem rather than separate gems for Windows and Unix.
|
87
95
|
* Revamped the Windows tests.
|
88
96
|
|
89
|
-
|
97
|
+
## 1.0.0 - 11-Jan-2012
|
90
98
|
* Converted everything from C to FFI for the Unix flavors. The Windows
|
91
99
|
source code remains untouched.
|
92
100
|
|
93
|
-
|
101
|
+
## 0.3.4 - 19-Nov-2010
|
94
102
|
* Fixed a bug where negative block counts were happening on very large
|
95
103
|
hard drives. Thanks go to Jonas Pfenniger for the spot.
|
96
104
|
* Refactored the clean task in the Rakefile.
|
97
105
|
* Some cosmetic source code changes.
|
98
106
|
|
99
|
-
|
107
|
+
## 0.3.3 - 21-May-2010
|
100
108
|
* Added a workaround for the Sys::Filesystem#block_size member to deal with
|
101
109
|
a bug in OS X. Thanks go to Josh Pasqualetto for the spot.
|
102
110
|
|
103
|
-
|
111
|
+
## 0.3.2 - 29-Dec-2009
|
104
112
|
* Source has been moved to github.
|
105
113
|
* Added the 'gem' task and removed build logic from the gemspec.
|
106
114
|
* Updated the install task.
|
@@ -108,23 +116,23 @@
|
|
108
116
|
* Removed some junk build files that were inadvertently included in
|
109
117
|
the last gem.
|
110
118
|
|
111
|
-
|
119
|
+
## 0.3.1 - 5-Aug-2009
|
112
120
|
* Now compatible with Ruby 1.9.x.
|
113
121
|
* Changed license to Artistic 2.0
|
114
122
|
* Updated the gemspec, including the explicit addition of a license and
|
115
123
|
test-unit as a development dependency, as well as an updated description.
|
116
124
|
|
117
|
-
|
125
|
+
## 0.3.0 - 26-Feb-2009
|
118
126
|
* Added support for OS X and FreeBSD thanks to an awesome patch by Nobuyoshi
|
119
127
|
Miyokawa.
|
120
128
|
* Added the Filesystem.mount_point method that takes a file and returns
|
121
129
|
the mount point it's sitting on.
|
122
130
|
|
123
|
-
|
131
|
+
## 0.2.0 - 30-Dec-2008
|
124
132
|
* Added the Filesystem.mounts method for iterating over mount or volume
|
125
133
|
information.
|
126
134
|
|
127
|
-
|
135
|
+
## 0.1.1 - 28-Mar-2007
|
128
136
|
* Bug fix for BSD flavors. Thanks go to Jeremy Kemper and Ole Christian
|
129
137
|
Rynning for the spot.
|
130
138
|
* Bug fix for OS X (along the same lines as the BSD fix). Thanks go to
|
@@ -133,5 +141,5 @@
|
|
133
141
|
* Tweaks to the gemspec.
|
134
142
|
* Added synopsis to the README.
|
135
143
|
|
136
|
-
|
144
|
+
## 0.1.0 - 17-Nov-2006
|
137
145
|
* Initial release. Alpha. Code is stable, but API is not.
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
## Description
|
2
|
+
|
3
|
+
A cross platform Ruby interface for getting file system information.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
`gem install sys-filesystem`
|
8
|
+
|
9
|
+
## Synopsis
|
10
|
+
|
11
|
+
```
|
12
|
+
require 'sys/filesystem'
|
13
|
+
include Sys
|
14
|
+
|
15
|
+
# Display information about a particular filesystem.
|
16
|
+
p Filesystem.stat('/')
|
17
|
+
|
18
|
+
# Sample output
|
19
|
+
|
20
|
+
#<Sys::Filesystem::Stat:0x517440
|
21
|
+
@base_type = "ufs",
|
22
|
+
@flags = 4,
|
23
|
+
@files_available = 3817457,
|
24
|
+
@block_size = 8192,
|
25
|
+
@blocks_available = 19957633,
|
26
|
+
@blocks = 34349612,
|
27
|
+
@name_max = 255,
|
28
|
+
@path = "/",
|
29
|
+
@filesystem_id = 35651592,
|
30
|
+
@files = 4135040,
|
31
|
+
@fragment_size = 1024,
|
32
|
+
@files_free = 3817457,
|
33
|
+
@blocks_free = 20301129
|
34
|
+
>
|
35
|
+
|
36
|
+
# Describe all mount points on the system
|
37
|
+
Filesystem.mounts{ |mount| p mount }
|
38
|
+
|
39
|
+
# Find the mount point of any particular file
|
40
|
+
puts Filesystem.mount_point('/home/djberge/some_file.txt') => '/home'
|
41
|
+
```
|
42
|
+
|
43
|
+
## Notes
|
44
|
+
|
45
|
+
This is a pure Ruby implementation that uses FFI. This means it should work
|
46
|
+
with JRuby, too.
|
47
|
+
|
48
|
+
## Sample code
|
49
|
+
|
50
|
+
Run 'rake example' if you want to see a basic sample run. The actual code
|
51
|
+
is 'example_stat.rb' in the 'examples' directory. Modify it as you see fit.
|
52
|
+
|
53
|
+
## Known Bugs
|
54
|
+
|
55
|
+
None that I'm aware of. Please report bugs on the project page at:
|
56
|
+
|
57
|
+
https://github.com/djberg96/sys-filesystem
|
58
|
+
|
59
|
+
## Future Plans
|
60
|
+
|
61
|
+
* Add better 64-bit support for Linux and BSD.
|
62
|
+
* Other suggestions welcome.
|
63
|
+
|
64
|
+
## Acknowledgements
|
65
|
+
|
66
|
+
* Mike Hall, for ideas and code that I borrowed from his 'filesystem' library.
|
67
|
+
* Park Heesob, for implementation and API ideas for the MS Windows version.
|
68
|
+
* Nobuyoshi Miyokawa, for adding the original FreeBSD and OS X support.
|
69
|
+
|
70
|
+
## License
|
71
|
+
|
72
|
+
Apache-2.0
|
73
|
+
|
74
|
+
## Copyright
|
75
|
+
|
76
|
+
(C) 2003-2020 Daniel J. Berger
|
77
|
+
All Rights Reserved
|
78
|
+
|
79
|
+
## Warranty
|
80
|
+
|
81
|
+
This library is provided "as is" and without any express or
|
82
|
+
implied warranties, including, without limitation, the implied
|
83
|
+
warranties of merchantability and fitness for a particular purpose.
|
84
|
+
|
85
|
+
## Author
|
86
|
+
|
87
|
+
Daniel J. Berger
|
data/Rakefile
CHANGED
@@ -1,26 +1,8 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rake/clean'
|
3
|
-
require '
|
3
|
+
require 'rspec/core/rake_task'
|
4
4
|
|
5
|
-
CLEAN.include('**/*.gem', '**/*.rbc', '**/*.rbx')
|
6
|
-
|
7
|
-
desc "Run the test suite"
|
8
|
-
Rake::TestTask.new("test") do |t|
|
9
|
-
if File::ALT_SEPARATOR
|
10
|
-
t.libs << 'lib/windows'
|
11
|
-
else
|
12
|
-
t.libs << 'lib/unix'
|
13
|
-
end
|
14
|
-
|
15
|
-
t.warning = true
|
16
|
-
t.verbose = true
|
17
|
-
t.test_files = FileList['test/test_sys_filesystem.rb']
|
18
|
-
end
|
19
|
-
|
20
|
-
desc "Run the example program"
|
21
|
-
task :example do |t|
|
22
|
-
sh "ruby -Ilib -Ilib/unix -Ilib/windows examples/example_stat.rb"
|
23
|
-
end
|
5
|
+
CLEAN.include('**/*.gem', '**/*.rbc', '**/*.rbx', '**/*.lock')
|
24
6
|
|
25
7
|
namespace :gem do
|
26
8
|
desc "Build the sys-filesystem gem"
|
@@ -28,7 +10,7 @@ namespace :gem do
|
|
28
10
|
require 'rubygems/package'
|
29
11
|
spec = eval(IO.read('sys-filesystem.gemspec'))
|
30
12
|
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
31
|
-
Gem::Package.build(spec
|
13
|
+
Gem::Package.build(spec)
|
32
14
|
end
|
33
15
|
|
34
16
|
desc "Install the sys-filesystem gem"
|
@@ -38,4 +20,12 @@ namespace :gem do
|
|
38
20
|
end
|
39
21
|
end
|
40
22
|
|
41
|
-
|
23
|
+
desc "Run the example program"
|
24
|
+
task :example do |t|
|
25
|
+
sh "ruby -Ilib -Ilib/unix -Ilib/windows examples/example_stat.rb"
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Run the test suite"
|
29
|
+
RSpec::Core::RakeTask.new(:spec)
|
30
|
+
|
31
|
+
task :default => :spec
|
data/lib/sys/filesystem.rb
CHANGED
@@ -198,7 +198,27 @@ module Sys
|
|
198
198
|
# Returns a Sys::Filesystem::Stat object containing information about the
|
199
199
|
# +path+ on the filesystem.
|
200
200
|
#
|
201
|
+
# Examples:
|
202
|
+
#
|
203
|
+
# # path
|
204
|
+
# Sys::Filesystem.stat("path")
|
205
|
+
#
|
206
|
+
# # Pathname
|
207
|
+
# pathname = Pathname.new("path")
|
208
|
+
# Sys::Filesystem.stat(pathname)
|
209
|
+
#
|
210
|
+
# # File
|
211
|
+
# file = File.open("file", "r")
|
212
|
+
# Sys::Filesystem.stat(file)
|
213
|
+
#
|
214
|
+
# # Dir
|
215
|
+
# dir = Dir.open("/")
|
216
|
+
# Sys::Filesystem.stat(dir)
|
217
|
+
#
|
201
218
|
def self.stat(path)
|
219
|
+
path = path.path if path.respond_to?(:path) # File, Dir
|
220
|
+
path = path.to_s if path.respond_to?(:to_s) # Pathname
|
221
|
+
|
202
222
|
fs = Statvfs.new
|
203
223
|
|
204
224
|
if statvfs(path, fs) < 0
|
@@ -123,6 +123,21 @@ module Sys
|
|
123
123
|
:f_fstr, [:char, 32],
|
124
124
|
:f_filler, [:ulong, 16]
|
125
125
|
)
|
126
|
+
elsif RbConfig::CONFIG['host'] =~ /i686/i
|
127
|
+
layout(
|
128
|
+
:f_bsize, :ulong,
|
129
|
+
:f_frsize, :ulong,
|
130
|
+
:f_blocks, :uint,
|
131
|
+
:f_bfree, :uint,
|
132
|
+
:f_bavail, :uint,
|
133
|
+
:f_files, :uint,
|
134
|
+
:f_ffree, :uint,
|
135
|
+
:f_favail, :uint,
|
136
|
+
:f_fsid, :ulong,
|
137
|
+
:f_flag, :ulong,
|
138
|
+
:f_namemax, :ulong,
|
139
|
+
:f_spare, [:int, 6]
|
140
|
+
)
|
126
141
|
else
|
127
142
|
layout(
|
128
143
|
:f_bsize, :ulong,
|
@@ -259,10 +259,25 @@ module Sys
|
|
259
259
|
#
|
260
260
|
# Examples:
|
261
261
|
#
|
262
|
+
# # Regular directory
|
262
263
|
# Sys::Filesystem.stat("C:\\")
|
263
264
|
# Sys::Filesystem.stat("C:\\Documents and Settings\\some_user")
|
264
265
|
#
|
266
|
+
# # Pathname
|
267
|
+
# pathname = Pathname.new("C:\\")
|
268
|
+
# Sys::Filesystem.stat(pathname)
|
269
|
+
#
|
270
|
+
# # Dir
|
271
|
+
# dir = Dir.open("C:\\")
|
272
|
+
# Sys::Filesystem.stat(dir)
|
273
|
+
#
|
274
|
+
# Note that on Windows you cannot stat a regular file because
|
275
|
+
# Windows won't like it. It must be a directory in some form.
|
276
|
+
#
|
265
277
|
def self.stat(path)
|
278
|
+
path = path.path if path.respond_to?(:path) # Dir
|
279
|
+
path = path.to_s if path.respond_to?(:to_s) # Pathname
|
280
|
+
|
266
281
|
bytes_avail = FFI::MemoryPointer.new(:ulong_long)
|
267
282
|
bytes_free = FFI::MemoryPointer.new(:ulong_long)
|
268
283
|
total_bytes = FFI::MemoryPointer.new(:ulong_long)
|
@@ -270,7 +285,7 @@ module Sys
|
|
270
285
|
mpoint = mount_point(path).to_s
|
271
286
|
mpoint << '/' unless mpoint.end_with?('/')
|
272
287
|
|
273
|
-
wpath
|
288
|
+
wpath = path.to_s.wincode
|
274
289
|
|
275
290
|
# We need this call for the 64 bit support
|
276
291
|
unless GetDiskFreeSpaceExW(wpath, bytes_avail, total_bytes, bytes_free)
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,389 @@
|
|
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.0')
|
25
|
+
expect(Sys::Filesystem::VERSION).to be_frozen
|
26
|
+
end
|
27
|
+
|
28
|
+
example "stat path works as expected" do
|
29
|
+
expect(@stat).to respond_to(:path)
|
30
|
+
expect(@stat.path).to eq(root)
|
31
|
+
end
|
32
|
+
|
33
|
+
example "stat block_size works as expected" do
|
34
|
+
expect(@stat).to respond_to(:block_size)
|
35
|
+
expect(@stat.block_size).to be_kind_of(Numeric)
|
36
|
+
end
|
37
|
+
|
38
|
+
example "stat fragment_size works as expected" do
|
39
|
+
expect(@stat).to respond_to(:fragment_size)
|
40
|
+
expect(@stat.fragment_size).to be_kind_of(Numeric)
|
41
|
+
end
|
42
|
+
|
43
|
+
example "stat fragment_size is a plausible value" do
|
44
|
+
expect(@stat.fragment_size).to be >= 512
|
45
|
+
expect(@stat.fragment_size).to be <= 16384
|
46
|
+
end
|
47
|
+
|
48
|
+
example "stat blocks works as expected" do
|
49
|
+
expect(@stat).to respond_to(:blocks)
|
50
|
+
expect(@stat.blocks).to be_kind_of(Numeric)
|
51
|
+
end
|
52
|
+
|
53
|
+
example "stat blocks_free works as expected" do
|
54
|
+
expect(@stat).to respond_to(:blocks_free)
|
55
|
+
expect(@stat.blocks_free).to be_kind_of(Numeric)
|
56
|
+
end
|
57
|
+
|
58
|
+
example "stat blocks_available works as expected" do
|
59
|
+
expect(@stat).to respond_to(:blocks_available)
|
60
|
+
expect(@stat.blocks_available).to be_kind_of(Numeric)
|
61
|
+
end
|
62
|
+
|
63
|
+
example "stat files works as expected" do
|
64
|
+
expect(@stat).to respond_to(:files)
|
65
|
+
expect(@stat.files).to be_kind_of(Numeric)
|
66
|
+
end
|
67
|
+
|
68
|
+
example "stat inodes is an alias for files" do
|
69
|
+
expect(@stat).to respond_to(:inodes)
|
70
|
+
expect(@stat.method(:inodes)).to eq(@stat.method(:files))
|
71
|
+
end
|
72
|
+
|
73
|
+
example "stat files tree works as expected" do
|
74
|
+
expect(@stat).to respond_to(:files_free)
|
75
|
+
expect(@stat.files_free).to be_kind_of(Numeric)
|
76
|
+
end
|
77
|
+
|
78
|
+
example "stat inodes_free is an alias for files_free" do
|
79
|
+
expect(@stat).to respond_to(:inodes_free)
|
80
|
+
expect(@stat.method(:inodes_free)).to eq(@stat.method(:files_free))
|
81
|
+
end
|
82
|
+
|
83
|
+
example "stat files_available works as expected" do
|
84
|
+
expect(@stat).to respond_to(:files_available)
|
85
|
+
expect(@stat.files_available).to be_kind_of(Numeric)
|
86
|
+
end
|
87
|
+
|
88
|
+
example "stat inodes_available is an alias for files_available" do
|
89
|
+
expect(@stat).to respond_to(:inodes_available)
|
90
|
+
expect(@stat.method(:inodes_available)).to eq(@stat.method(:files_available))
|
91
|
+
end
|
92
|
+
|
93
|
+
example "stat filesystem_id works as expected" do
|
94
|
+
expect(@stat).to respond_to(:filesystem_id)
|
95
|
+
expect(@stat.filesystem_id).to be_kind_of(Integer)
|
96
|
+
end
|
97
|
+
|
98
|
+
example "stat flags works as expected" do
|
99
|
+
expect(@stat).to respond_to(:flags)
|
100
|
+
expect(@stat.flags).to be_kind_of(Numeric)
|
101
|
+
end
|
102
|
+
|
103
|
+
example "stat name_max works as expected" do
|
104
|
+
expect(@stat).to respond_to(:name_max)
|
105
|
+
expect(@stat.name_max).to be_kind_of(Numeric)
|
106
|
+
end
|
107
|
+
|
108
|
+
example "stat base_type works as expected" do
|
109
|
+
skip "base_type test skipped except on Solaris" unless solaris
|
110
|
+
|
111
|
+
expect(@stat).to respond_to(:base_type)
|
112
|
+
expect(@stat.base_type).to be_kind_of(String)
|
113
|
+
end
|
114
|
+
|
115
|
+
example "stat constants are defined" do
|
116
|
+
expect(Sys::Filesystem::Stat::RDONLY).not_to be_nil
|
117
|
+
expect(Sys::Filesystem::Stat::NOSUID).not_to be_nil
|
118
|
+
end
|
119
|
+
|
120
|
+
example "stat constants for solaris are defined" do
|
121
|
+
skip "NOTRUNC test skipped except on Solaris" unless solaris
|
122
|
+
expect(Sys::Filesystem::Stat::NOTRUNC).not_to be_nil
|
123
|
+
end
|
124
|
+
|
125
|
+
example "stat bytes_total works as expected" do
|
126
|
+
expect(@stat).to respond_to(:bytes_total)
|
127
|
+
expect(@stat.bytes_total).to be_kind_of(Numeric)
|
128
|
+
end
|
129
|
+
|
130
|
+
example "stat bytes_free works as expected" do
|
131
|
+
expect(@stat).to respond_to(:bytes_free)
|
132
|
+
expect(@stat.bytes_free).to be_kind_of(Numeric)
|
133
|
+
expect(@stat.blocks_free * @stat.fragment_size).to eq(@stat.bytes_free)
|
134
|
+
end
|
135
|
+
|
136
|
+
example "stat bytes_available works as expected" do
|
137
|
+
expect(@stat).to respond_to(:bytes_available)
|
138
|
+
expect(@stat.bytes_available).to be_kind_of(Numeric)
|
139
|
+
expect(@stat.blocks_available * @stat.fragment_size).to eq(@stat.bytes_available)
|
140
|
+
end
|
141
|
+
|
142
|
+
example "stat bytes works as expected" do
|
143
|
+
expect(@stat).to respond_to(:bytes_used)
|
144
|
+
expect(@stat.bytes_used).to be_kind_of(Numeric)
|
145
|
+
end
|
146
|
+
|
147
|
+
example "stat percent_used works as expected" do
|
148
|
+
expect(@stat).to respond_to(:percent_used)
|
149
|
+
expect(@stat.percent_used).to be_kind_of(Float)
|
150
|
+
end
|
151
|
+
|
152
|
+
example "stat singleton method requires an argument" do
|
153
|
+
expect{ Sys::Filesystem.stat }.to raise_error(ArgumentError)
|
154
|
+
end
|
155
|
+
|
156
|
+
example "stat case_insensitive method works as expected" do
|
157
|
+
expected = darwin ? true : false
|
158
|
+
expect(@stat.case_insensitive?).to eq(expected)
|
159
|
+
expect(Sys::Filesystem.stat(Dir.home).case_insensitive?).to eq(expected)
|
160
|
+
end
|
161
|
+
|
162
|
+
example "stat case_sensitive method works as expected" do
|
163
|
+
expected = darwin ? false : true
|
164
|
+
expect(@stat.case_sensitive?).to eq(expected)
|
165
|
+
expect(Sys::Filesystem.stat(Dir.home).case_sensitive?).to eq(expected)
|
166
|
+
end
|
167
|
+
|
168
|
+
example "numeric helper methods are defined" do
|
169
|
+
expect(@size).to respond_to(:to_kb)
|
170
|
+
expect(@size).to respond_to(:to_mb)
|
171
|
+
expect(@size).to respond_to(:to_gb)
|
172
|
+
expect(@size).to respond_to(:to_tb)
|
173
|
+
end
|
174
|
+
|
175
|
+
example "to_kb works as expected" do
|
176
|
+
expect(@size.to_kb).to eq(57344)
|
177
|
+
end
|
178
|
+
|
179
|
+
example "to_mb works as expected" do
|
180
|
+
expect(@size.to_mb).to eq(56)
|
181
|
+
end
|
182
|
+
|
183
|
+
example "to_gb works as expected" do
|
184
|
+
expect(@size.to_gb).to eq(0)
|
185
|
+
end
|
186
|
+
|
187
|
+
context "Filesystem.stat(Pathname)" do
|
188
|
+
before do
|
189
|
+
@stat_pathname = Sys::Filesystem.stat(Pathname.new(root))
|
190
|
+
end
|
191
|
+
|
192
|
+
example "stat with Pathname argument works as expected" do
|
193
|
+
expect(@stat_pathname.class).to eq(@stat.class)
|
194
|
+
expect(@stat_pathname.path).to eq(@stat.path)
|
195
|
+
expect(@stat_pathname.block_size).to eq(@stat.block_size)
|
196
|
+
expect(@stat_pathname.fragment_size).to eq(@stat.fragment_size)
|
197
|
+
expect(@stat_pathname.blocks).to eq(@stat.blocks)
|
198
|
+
expect(@stat_pathname.blocks_free).to eq(@stat.blocks_free)
|
199
|
+
expect(@stat_pathname.blocks_available).to eq(@stat.blocks_available)
|
200
|
+
expect(@stat_pathname.files).to eq(@stat.files)
|
201
|
+
expect(@stat_pathname.files_free).to eq(@stat.files_free)
|
202
|
+
expect(@stat_pathname.files_available).to eq(@stat.files_available)
|
203
|
+
expect(@stat_pathname.filesystem_id).to eq(@stat.filesystem_id)
|
204
|
+
expect(@stat_pathname.flags).to eq(@stat.flags)
|
205
|
+
expect(@stat_pathname.name_max).to eq(@stat.name_max)
|
206
|
+
expect(@stat_pathname.base_type).to eq(@stat.base_type)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context "Filesystem.stat(File)" do
|
211
|
+
before do
|
212
|
+
@stat_file = File.open(root){ |file| Sys::Filesystem.stat(file) }
|
213
|
+
end
|
214
|
+
|
215
|
+
example "stat with File argument works as expected" do
|
216
|
+
expect(@stat_file.class).to eq(@stat.class)
|
217
|
+
expect(@stat_file.path).to eq(@stat.path)
|
218
|
+
expect(@stat_file.block_size).to eq(@stat.block_size)
|
219
|
+
expect(@stat_file.fragment_size).to eq(@stat.fragment_size)
|
220
|
+
expect(@stat_file.blocks).to eq(@stat.blocks)
|
221
|
+
expect(@stat_file.blocks_free).to eq(@stat.blocks_free)
|
222
|
+
expect(@stat_file.blocks_available).to eq(@stat.blocks_available)
|
223
|
+
expect(@stat_file.files).to eq(@stat.files)
|
224
|
+
expect(@stat_file.files_free).to eq(@stat.files_free)
|
225
|
+
expect(@stat_file.files_available).to eq(@stat.files_available)
|
226
|
+
expect(@stat_file.filesystem_id).to eq(@stat.filesystem_id)
|
227
|
+
expect(@stat_file.flags).to eq(@stat.flags)
|
228
|
+
expect(@stat_file.name_max).to eq(@stat.name_max)
|
229
|
+
expect(@stat_file.base_type).to eq(@stat.base_type)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
context "Filesystem.stat(Dir)" do
|
234
|
+
before do
|
235
|
+
@stat_dir = Dir.open(root){ |dir| Sys::Filesystem.stat(dir) }
|
236
|
+
end
|
237
|
+
|
238
|
+
example "stat with Dir argument works as expected" do
|
239
|
+
expect(@stat_dir.class).to eq(@stat.class)
|
240
|
+
expect(@stat_dir.path).to eq(@stat.path)
|
241
|
+
expect(@stat_dir.block_size).to eq(@stat.block_size)
|
242
|
+
expect(@stat_dir.fragment_size).to eq(@stat.fragment_size)
|
243
|
+
expect(@stat_dir.blocks).to eq(@stat.blocks)
|
244
|
+
expect(@stat_dir.blocks_free).to eq(@stat.blocks_free)
|
245
|
+
expect(@stat_dir.blocks_available).to eq(@stat.blocks_available)
|
246
|
+
expect(@stat_dir.files).to eq(@stat.files)
|
247
|
+
expect(@stat_dir.files_free).to eq(@stat.files_free)
|
248
|
+
expect(@stat_dir.files_available).to eq(@stat.files_available)
|
249
|
+
expect(@stat_dir.filesystem_id).to eq(@stat.filesystem_id)
|
250
|
+
expect(@stat_dir.flags).to eq(@stat.flags)
|
251
|
+
expect(@stat_dir.name_max).to eq(@stat.name_max)
|
252
|
+
expect(@stat_dir.base_type).to eq(@stat.base_type)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
context "Filesystem::Mount" do
|
257
|
+
let(:mount){ Sys::Filesystem.mounts[0] }
|
258
|
+
|
259
|
+
before do
|
260
|
+
@array = []
|
261
|
+
end
|
262
|
+
|
263
|
+
example "mounts singleton method works as expected without a block" do
|
264
|
+
expect{ @array = Sys::Filesystem.mounts }.not_to raise_error
|
265
|
+
expect(@array[0]).to be_kind_of(Sys::Filesystem::Mount)
|
266
|
+
end
|
267
|
+
|
268
|
+
example "mounts singleton method works as expected with a block" do
|
269
|
+
expect{ Sys::Filesystem.mounts{ |m| @array << m } }.not_to raise_error
|
270
|
+
expect(@array[0]).to be_kind_of(Sys::Filesystem::Mount)
|
271
|
+
end
|
272
|
+
|
273
|
+
example "calling the mounts singleton method a large number of times does not cause issues" do
|
274
|
+
expect{ 1000.times{ @array = Sys::Filesystem.mounts } }.not_to raise_error
|
275
|
+
end
|
276
|
+
|
277
|
+
example "mount name method works as expected" do
|
278
|
+
expect(mount).to respond_to(:name)
|
279
|
+
expect(mount.name).to be_kind_of(String)
|
280
|
+
end
|
281
|
+
|
282
|
+
example "mount fsname is an alias for name" do
|
283
|
+
expect(mount).to respond_to(:fsname)
|
284
|
+
expect(mount.method(:fsname)).to eq(mount.method(:name))
|
285
|
+
end
|
286
|
+
|
287
|
+
example "mount point method works as expected" do
|
288
|
+
expect(mount).to respond_to(:mount_point)
|
289
|
+
expect(mount.mount_point).to be_kind_of(String)
|
290
|
+
end
|
291
|
+
|
292
|
+
example "mount dir is an alias for mount_point" do
|
293
|
+
expect(mount).to respond_to(:dir)
|
294
|
+
expect(mount.method(:dir)).to eq(mount.method(:mount_point))
|
295
|
+
end
|
296
|
+
|
297
|
+
example "mount mount_type works as expected" do
|
298
|
+
expect(mount).to respond_to(:mount_type)
|
299
|
+
expect(mount.mount_type).to be_kind_of(String)
|
300
|
+
end
|
301
|
+
|
302
|
+
example "mount options works as expected" do
|
303
|
+
expect(mount).to respond_to(:options)
|
304
|
+
expect(mount.options).to be_kind_of(String)
|
305
|
+
end
|
306
|
+
|
307
|
+
example "mount opts is an alias for options" do
|
308
|
+
expect(mount).to respond_to(:opts)
|
309
|
+
expect(mount.method(:opts)).to eq(mount.method(:options))
|
310
|
+
end
|
311
|
+
|
312
|
+
example "mount time works as expected" do
|
313
|
+
expect(mount).to respond_to(:mount_time)
|
314
|
+
|
315
|
+
if solaris
|
316
|
+
expect(mount.mount_time).to be_kind_of(Time)
|
317
|
+
else
|
318
|
+
expect(mount.mount_time).to be_nil
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
example "mount dump_frequency works as expected" do
|
323
|
+
msg = 'dump_frequency test skipped on this platform'
|
324
|
+
skip msg if solaris || bsd || darwin
|
325
|
+
expect(mount).to respond_to(:dump_frequency)
|
326
|
+
expect(mount.dump_frequency).to be_kind_of(Numeric)
|
327
|
+
end
|
328
|
+
|
329
|
+
example "mount freq is an alias for dump_frequency" do
|
330
|
+
expect(mount).to respond_to(:freq)
|
331
|
+
expect(mount.method(:freq)).to eq(mount.method(:dump_frequency))
|
332
|
+
end
|
333
|
+
|
334
|
+
example "mount pass_number works as expected" do
|
335
|
+
msg = 'pass_number test skipped on this platform'
|
336
|
+
skip msg if solaris || bsd || darwin
|
337
|
+
expect(mount).to respond_to(:pass_number)
|
338
|
+
expect(mount.pass_number).to be_kind_of(Numeric)
|
339
|
+
end
|
340
|
+
|
341
|
+
example "mount passno is an alias for pass_number" do
|
342
|
+
expect(mount).to respond_to(:passno)
|
343
|
+
expect(mount.method(:passno)).to eq(mount.method(:pass_number))
|
344
|
+
end
|
345
|
+
|
346
|
+
example "mount_point singleton method works as expected" do
|
347
|
+
expect(Sys::Filesystem).to respond_to(:mount_point)
|
348
|
+
expect{ Sys::Filesystem.mount_point(Dir.pwd) }.not_to raise_error
|
349
|
+
expect(Sys::Filesystem.mount_point(Dir.pwd)).to be_kind_of(String)
|
350
|
+
end
|
351
|
+
|
352
|
+
example "mount singleton method is defined" do
|
353
|
+
expect(Sys::Filesystem).to respond_to(:mount)
|
354
|
+
end
|
355
|
+
|
356
|
+
example "umount singleton method is defined" do
|
357
|
+
expect(Sys::Filesystem).to respond_to(:umount)
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
context "FFI" do
|
362
|
+
require 'mkmf-lite'
|
363
|
+
include Mkmf::Lite
|
364
|
+
|
365
|
+
example "ffi functions are private" do
|
366
|
+
expect(Sys::Filesystem.methods.include?('statvfs')).to be false
|
367
|
+
expect(Sys::Filesystem.methods.include?('strerror')).to be false
|
368
|
+
end
|
369
|
+
|
370
|
+
example "statfs struct is expected size" do
|
371
|
+
header = bsd || darwin ? 'sys/mount.h' : 'sys/statfs.h'
|
372
|
+
expect(Sys::Filesystem::Structs::Statfs.size).to eq(check_sizeof('struct statfs', header))
|
373
|
+
end
|
374
|
+
|
375
|
+
example "statvfs struct is expected size" do
|
376
|
+
expect(Sys::Filesystem::Structs::Statvfs.size).to eq(check_sizeof('struct statvfs', 'sys/statvfs.h'))
|
377
|
+
end
|
378
|
+
|
379
|
+
example "mnttab struct is expected size" do
|
380
|
+
skip "mnttab test skipped except on Solaris" unless solaris
|
381
|
+
expect(Sys::Filesystem::Structs::Mnttab.size).to eq(check_sizeof('struct mnttab', 'sys/mnttab.h'))
|
382
|
+
end
|
383
|
+
|
384
|
+
example "mntent struct is expected size" do
|
385
|
+
skip "mnttab test skipped except on Linux" unless linux
|
386
|
+
expect(Sys::Filesystem::Structs::Mntent.size).to eq(check_sizeof('struct mntent', 'mntent.h'))
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|