sys-filesystem 0.1.1 → 0.2.0
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.
- data/CHANGES +4 -0
- data/MANIFEST +4 -2
- data/README +25 -9
- data/Rakefile +21 -19
- data/doc/sys-filesystem.txt +165 -0
- data/examples/example_stat.rb +24 -0
- data/ext/extconf.rb +6 -3
- data/ext/{filesystem.c → sys/filesystem.c} +119 -7
- data/test/test_sys_filesystem.rb +9 -0
- data/test/test_sys_filesystem_unix.rb +234 -0
- data/test/test_sys_filesystem_windows.rb +192 -0
- metadata +52 -42
- data/test/tc_filesystem.rb +0 -7
- data/test/tc_unix.rb +0 -118
- data/test/tc_windows.rb +0 -127
data/CHANGES
CHANGED
data/MANIFEST
CHANGED
@@ -2,10 +2,12 @@
|
|
2
2
|
* CHANGES
|
3
3
|
* Rakefile
|
4
4
|
* README
|
5
|
-
* install.rb
|
6
5
|
* sys-fileystem.gemspec
|
7
6
|
* examples/example_stat.rb
|
7
|
+
* doc/sys-filesystem.txt
|
8
8
|
* ext/extconf.rb
|
9
9
|
* ext/filesystem.c
|
10
10
|
* lib/sys/filesystem.rb
|
11
|
-
* test/
|
11
|
+
* test/test_sys_filesystem.rb
|
12
|
+
* test/test_sys_filesystem_unix
|
13
|
+
* test/test_sys_filesystem_windows
|
data/README
CHANGED
@@ -3,15 +3,11 @@
|
|
3
3
|
|
4
4
|
= Prerequisites
|
5
5
|
=== MS Windows
|
6
|
-
* windows-pr, 0.
|
6
|
+
* windows-pr, 0.9.8 or later.
|
7
7
|
|
8
8
|
= Installation
|
9
|
-
=== Manual Installation
|
10
9
|
rake test (optional)
|
11
|
-
rake install
|
12
|
-
=== Gem Installation
|
13
|
-
ruby sys-filesystem.gemspec
|
14
|
-
gem install sys-filesystem-X.Y.Z.gem
|
10
|
+
rake install (non-gem) OR rake install_gem (gem)
|
15
11
|
|
16
12
|
= Synopsis
|
17
13
|
require 'sys/filesystem'
|
@@ -19,6 +15,26 @@
|
|
19
15
|
|
20
16
|
p Filesystem.stat("/")
|
21
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
|
+
Filesystem.mounts{ |mount| p mount }
|
37
|
+
|
22
38
|
= Notes
|
23
39
|
=== MS Windows
|
24
40
|
This is a pure Ruby implementation using the windows-pr package, which in
|
@@ -35,18 +51,18 @@
|
|
35
51
|
http://www.rubyforge.org/projects/sysutils.
|
36
52
|
|
37
53
|
= Future Plans
|
38
|
-
|
54
|
+
Suggestions welcome.
|
39
55
|
|
40
56
|
= Acknowledgements
|
41
57
|
Mike Hall, for ideas and code that I borrowed from his 'filesystem' package.
|
42
58
|
Park Heesob, for implementation and API ideas for the MS Windows version.
|
43
59
|
|
44
60
|
= Copyright
|
45
|
-
(C) 2003-
|
61
|
+
(C) 2003-2008 Daniel J. Berger
|
46
62
|
All Rights Reserved
|
47
63
|
|
48
64
|
= Warranty
|
49
|
-
This
|
65
|
+
This library is provided "as is" and without any express or
|
50
66
|
implied warranties, including, without limitation, the implied
|
51
67
|
warranties of merchantability and fitness for a particular purpose.
|
52
68
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rake/clean'
|
3
3
|
require 'rake/testtask'
|
4
|
+
include Config
|
4
5
|
|
5
6
|
desc "Clean the build files for the sys-filesystem source for UNIX systems"
|
6
7
|
task :clean do
|
@@ -8,35 +9,36 @@ task :clean do
|
|
8
9
|
FileUtils.rm_rf('sys') if File.exists?('sys')
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
unless CONFIG['host_os'].match('mswin')
|
13
|
+
file = 'sys/filesystem.' + CONFIG['DLEXT']
|
14
|
+
Dir.chdir('ext') do
|
15
|
+
sh 'make distclean' rescue nil
|
16
|
+
rm file if File.exists?(file)
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
|
-
desc "Build the sys-filesystem
|
21
|
+
desc "Build the sys-filesystem library on UNIX systems (but don't install it)"
|
21
22
|
task :build => [:clean] do
|
22
|
-
|
23
|
-
|
23
|
+
unless CONFIG['host_os'].match('mswin')
|
24
|
+
file = 'filesystem.' + CONFIG['DLEXT']
|
25
|
+
Dir.chdir('ext') do
|
24
26
|
ruby 'extconf.rb'
|
25
27
|
sh 'make'
|
26
|
-
|
27
|
-
Dir.mkdir('sys') unless File.exists?('sys')
|
28
|
-
FileUtils.cp(build_file, 'sys')
|
28
|
+
mv file, 'sys'
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
if
|
34
|
-
desc "Install the sys-filesystem
|
33
|
+
if CONFIG['host_os'].match('mswin')
|
34
|
+
desc "Install the sys-filesystem library"
|
35
35
|
task :install do
|
36
|
-
|
36
|
+
install_dir = File.join(CONFIG['sitelibdir'], 'sys')
|
37
|
+
Dir.mkdir(install_dir) unless File.exists?(install_dir)
|
38
|
+
FileUtils.cp('lib/sys/filesystem.rb', install_dir, :verbose => true)
|
37
39
|
end
|
38
40
|
else
|
39
|
-
desc "Install the sys-filesystem
|
41
|
+
desc "Install the sys-filesystem library"
|
40
42
|
task :install => [:build] do
|
41
43
|
Dir.chdir('ext') do
|
42
44
|
sh 'make install'
|
@@ -46,14 +48,14 @@ end
|
|
46
48
|
|
47
49
|
desc "Run the test suite"
|
48
50
|
Rake::TestTask.new("test") do |t|
|
49
|
-
|
50
|
-
t.libs << 'lib'
|
51
|
-
else
|
51
|
+
unless CONFIG['host_os'].match('mswin')
|
52
52
|
task :test => :build
|
53
53
|
t.libs << 'ext'
|
54
54
|
t.libs.delete('lib')
|
55
55
|
end
|
56
|
-
t.
|
56
|
+
t.warning = true
|
57
|
+
t.verbose = true
|
58
|
+
t.test_files = FileList['test/test_sys_filesystem.rb']
|
57
59
|
end
|
58
60
|
|
59
61
|
desc "Run the example program"
|
@@ -0,0 +1,165 @@
|
|
1
|
+
= Description
|
2
|
+
A Ruby interface for getting filesystem information.
|
3
|
+
|
4
|
+
= Synopsis
|
5
|
+
require 'sys/filesystem'
|
6
|
+
include Sys
|
7
|
+
|
8
|
+
p Filesystem.stat("/") # => Sys::Filesystem::Stat object
|
9
|
+
|
10
|
+
Filesystem.mounts{ |mount|
|
11
|
+
p mount
|
12
|
+
}
|
13
|
+
|
14
|
+
= Constants
|
15
|
+
== Sys::Filesystem
|
16
|
+
VERSION
|
17
|
+
The version of this package, returned as a string.
|
18
|
+
|
19
|
+
== Sys::Filesystem::Stat
|
20
|
+
RDONLY
|
21
|
+
Read only filesystem.
|
22
|
+
|
23
|
+
See the +flags+ method for more information.
|
24
|
+
|
25
|
+
NOSUID
|
26
|
+
Filesystem does not support suid or sgid semantics.
|
27
|
+
|
28
|
+
See the +flags+ method for more information.
|
29
|
+
|
30
|
+
NOTRUNC
|
31
|
+
Filesystem does not truncate file names longer than +name_max+. Not
|
32
|
+
supported on all platforms.
|
33
|
+
|
34
|
+
See the +flags+ method for more information.
|
35
|
+
|
36
|
+
= Class Methods
|
37
|
+
=== Sys::Filesystem
|
38
|
+
Sys::Filesystem.stat(path)
|
39
|
+
Returns a Filesystem::Stat object containing information about the
|
40
|
+
+path+ filesystem.
|
41
|
+
|
42
|
+
Sys::Filesystem.mounts
|
43
|
+
Returns an array of Filesystem::Mount objects containing information
|
44
|
+
about the mount points available on your system.
|
45
|
+
|
46
|
+
In block form this method yields each Mount object in turn instead
|
47
|
+
of returning an array.
|
48
|
+
|
49
|
+
= Instance Methods
|
50
|
+
=== Sys::Filesystem::Mount
|
51
|
+
name
|
52
|
+
The name of the mounted resource.
|
53
|
+
|
54
|
+
On MS Windows this is the device mapping.
|
55
|
+
|
56
|
+
mount_time
|
57
|
+
The last time the volume was mounted.
|
58
|
+
|
59
|
+
On MS Windows this is your system's boot time.
|
60
|
+
|
61
|
+
mount_type
|
62
|
+
The type of mount, e.g. NFS, NTFS.
|
63
|
+
|
64
|
+
mount_point
|
65
|
+
The volume mount point.
|
66
|
+
|
67
|
+
On MS Windows this is the volume letter.
|
68
|
+
|
69
|
+
options
|
70
|
+
A list of comma separated options that denote properties of the volume.
|
71
|
+
|
72
|
+
pass_number
|
73
|
+
The number of the filesystem check, or nil if not present.
|
74
|
+
|
75
|
+
This is always nil on MS Windows.
|
76
|
+
|
77
|
+
frequency
|
78
|
+
The dump frequency in days, or nil if not present or supported.
|
79
|
+
|
80
|
+
This is always nil on MS Windows.
|
81
|
+
|
82
|
+
=== Sys::Filesystem::Stat
|
83
|
+
base_type
|
84
|
+
The filesystem type, e.g. UFS.
|
85
|
+
|
86
|
+
block_size
|
87
|
+
The preferred system block size.
|
88
|
+
|
89
|
+
blocks
|
90
|
+
The total number of +fragment_size+ blocks in the filesystem.
|
91
|
+
|
92
|
+
blocks_available
|
93
|
+
The number of free blocks available to unprivileged processes.
|
94
|
+
|
95
|
+
blocks_free
|
96
|
+
The total number of free blocks in the filesystem.
|
97
|
+
|
98
|
+
files
|
99
|
+
The total number of files/inodes that can be created.
|
100
|
+
|
101
|
+
files_free
|
102
|
+
The total number of free files/inodes on the file system.
|
103
|
+
|
104
|
+
filesystem_id
|
105
|
+
The filesystem identifier.
|
106
|
+
|
107
|
+
flags
|
108
|
+
A bit mask of flags. See the 'Constants' section for a list of flags.
|
109
|
+
|
110
|
+
fragment_size
|
111
|
+
The fragment size, i.e. fundamental file system block size.
|
112
|
+
|
113
|
+
inodes
|
114
|
+
Alias for +files+.
|
115
|
+
|
116
|
+
inodes_free
|
117
|
+
Alias for +files_free+.
|
118
|
+
|
119
|
+
inodes_available
|
120
|
+
Alias for +files_available+.
|
121
|
+
|
122
|
+
name_max
|
123
|
+
The maximum length of a file name permitted on the file system.
|
124
|
+
|
125
|
+
path
|
126
|
+
The path of the filesystem.
|
127
|
+
|
128
|
+
= Fixnum helper methods
|
129
|
+
Fixnum#to_gb
|
130
|
+
Returns a number in terms of gigabytes.
|
131
|
+
|
132
|
+
Fixnum#to_kb
|
133
|
+
Returns a number in terms of kilobytes
|
134
|
+
|
135
|
+
Fixnum#to_mb
|
136
|
+
Returns a number in terms of megabytes
|
137
|
+
|
138
|
+
== Known Bugs
|
139
|
+
None that I am aware of. Please log any bugs you find on the project
|
140
|
+
website at http://www.rubyforge.org/projects/sysutils.
|
141
|
+
|
142
|
+
== License
|
143
|
+
Ruby's
|
144
|
+
|
145
|
+
== Copyright
|
146
|
+
Copyright 2002-2008, Daniel J. Berger
|
147
|
+
|
148
|
+
All Rights Reserved. This module is free software. It may be used,
|
149
|
+
redistributed and/or modified under the same terms as Ruby itself.
|
150
|
+
|
151
|
+
== Warranty
|
152
|
+
This library is provided "as is" and without any express or
|
153
|
+
implied warranties, including, without limitation, the implied
|
154
|
+
warranties of merchantability and fitness for a particular purpose.
|
155
|
+
|
156
|
+
== Acknowledgements
|
157
|
+
Mike Hall for his original source code.
|
158
|
+
|
159
|
+
== Author
|
160
|
+
Daniel J. Berger
|
161
|
+
djberg96 at nospam at gmail dot com
|
162
|
+
imperator on IRC (Freenode)
|
163
|
+
|
164
|
+
== See Also
|
165
|
+
mount
|
@@ -0,0 +1,24 @@
|
|
1
|
+
######################################################################
|
2
|
+
# example_stat.rb
|
3
|
+
#
|
4
|
+
# Example program that demonstrates the FileSystem.stat method.
|
5
|
+
# Use the 'rake example' task to run this program.
|
6
|
+
######################################################################
|
7
|
+
require 'sys/filesystem'
|
8
|
+
include Sys
|
9
|
+
|
10
|
+
p Filesystem::VERSION
|
11
|
+
|
12
|
+
stat = Filesystem.stat("/")
|
13
|
+
puts "Path: " + stat.path
|
14
|
+
puts "Block size: " + stat.block_size.to_s
|
15
|
+
puts "Fragment size: " + stat.fragment_size.to_s
|
16
|
+
puts "Blocks free: " + stat.blocks_free.to_s
|
17
|
+
puts "Blocks available: " + stat.blocks_available.to_s
|
18
|
+
puts "Files/Inodes: " + stat.files.to_s
|
19
|
+
puts "Files/Inodes free: " + stat.files_free.to_s
|
20
|
+
puts "Files/Inodes available: " + stat.files_available.to_s
|
21
|
+
puts "File system id: " + stat.filesystem_id.to_s
|
22
|
+
puts "Base type: " + stat.base_type if stat.base_type
|
23
|
+
puts "Flags: " + stat.flags.to_s
|
24
|
+
puts "Name max: " + stat.name_max.to_s
|
data/ext/extconf.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'mkmf'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
dir_config('filesystem')
|
4
|
+
|
5
|
+
have_header("sys/mnttab.h") || have_header("mntent.h")
|
6
|
+
|
5
7
|
have_func("statvfs")
|
8
|
+
have_func("getextmntent")
|
6
9
|
|
7
10
|
if have_header("sys/statvfs.h")
|
8
11
|
have_struct_member("struct statvfs", "f_basetype", "sys/statvfs.h")
|
@@ -10,4 +13,4 @@ else
|
|
10
13
|
have_header("sys/vnode.h")
|
11
14
|
end
|
12
15
|
|
13
|
-
create_makefile("sys/filesystem")
|
16
|
+
create_makefile("sys/filesystem", "sys")
|
@@ -23,7 +23,7 @@
|
|
23
23
|
#define START_MNT(F,M) fopen(F,M)
|
24
24
|
#define GET_MNT(FP,MP) (getmntent(FP,MP) == 0)
|
25
25
|
#define END_MNT(F) fclose(F)
|
26
|
-
#define
|
26
|
+
#define MOUNTFILE "/etc/mnttab"
|
27
27
|
|
28
28
|
#else /* Most flavors of UNIX */
|
29
29
|
|
@@ -33,12 +33,14 @@
|
|
33
33
|
#define START_MNT(F,M) setmntent(F,M)
|
34
34
|
#define GET_MNT(FP,MP) ((MP = getmntent(FP)) != NULL)
|
35
35
|
#define END_MNT(F) endmntent(F)
|
36
|
-
#define
|
36
|
+
#define MOUNTFILE "/etc/mtab"
|
37
37
|
#endif
|
38
38
|
|
39
39
|
#endif
|
40
40
|
|
41
|
-
VALUE mSys, cFilesys, cStat;
|
41
|
+
VALUE mSys, cFilesys, cStat, cMount;
|
42
|
+
|
43
|
+
static VALUE create_mount_object(struct MNTENT*);
|
42
44
|
|
43
45
|
/* call-seq:
|
44
46
|
* Filesystem.stat(path)
|
@@ -120,6 +122,81 @@ static VALUE fixnum_to_gb(VALUE self){
|
|
120
122
|
return ULL2NUM(NUM2ULONG(self) / 1073741824);
|
121
123
|
}
|
122
124
|
|
125
|
+
/*
|
126
|
+
* call-seq:
|
127
|
+
* Filesystem.mounts
|
128
|
+
* Filesystem.mounts{ ... }
|
129
|
+
*
|
130
|
+
* In block form, yields a Filesystem::Mount object for each mounted filesystem
|
131
|
+
* on your machine. In non-block form, returns an array of Filesystem::Mount
|
132
|
+
* objects instead.
|
133
|
+
*
|
134
|
+
* Example:
|
135
|
+
*
|
136
|
+
* Filesystem.mounts{ |fs|
|
137
|
+
* p fs.name # => e.g. '/dev/dsk/c0t0d0s0', 'proc', etc
|
138
|
+
* p fs.mount_time # => e.g. Thu Dec 11 15:07:23 -0700 2008
|
139
|
+
* p fs.mount_type # => e.g. 'ufs', 'proc', etc
|
140
|
+
* p fs.mount_point # => e.g. '/', '/proc', '/tmp', etc
|
141
|
+
* p fs.options # => e.g. "rw,intr,largefiles,logging,xattr,onerror=panic,dev=2200008"
|
142
|
+
* p fs.pass_number # => e.g. ???
|
143
|
+
* p fs.dump_frequency # => e.g. ???
|
144
|
+
* }
|
145
|
+
*/
|
146
|
+
static VALUE fs_mounts(VALUE klass){
|
147
|
+
VALUE v_array;
|
148
|
+
FILE* fp;
|
149
|
+
struct MNTENT* mp;
|
150
|
+
#ifdef HAVE_SYS_MNTTAB_H
|
151
|
+
struct MNTENT mt;
|
152
|
+
mp = &mt;
|
153
|
+
#endif
|
154
|
+
|
155
|
+
v_array = Qnil;
|
156
|
+
|
157
|
+
if((fp = START_MNT(MOUNTFILE, "r")) == NULL)
|
158
|
+
rb_sys_fail(MOUNTFILE);
|
159
|
+
|
160
|
+
if(rb_block_given_p()){
|
161
|
+
while(GET_MNT(fp, mp))
|
162
|
+
rb_yield(create_mount_object(mp));
|
163
|
+
}
|
164
|
+
else{
|
165
|
+
v_array = rb_ary_new();
|
166
|
+
while(GET_MNT(fp, mp))
|
167
|
+
rb_ary_push(v_array, create_mount_object(mp));
|
168
|
+
}
|
169
|
+
|
170
|
+
END_MNT(fp);
|
171
|
+
|
172
|
+
return v_array; /* nil in block form */
|
173
|
+
}
|
174
|
+
|
175
|
+
/* Private function to create a Filesystem object */
|
176
|
+
static VALUE create_mount_object(struct MNTENT* mp){
|
177
|
+
VALUE v_mount = rb_funcall(cMount, rb_intern("new"), 0, 0);
|
178
|
+
|
179
|
+
#ifdef HAVE_SYS_MNTTAB_H
|
180
|
+
rb_iv_set(v_mount, "@name", rb_tainted_str_new2(mp->mnt_special));
|
181
|
+
rb_iv_set(v_mount, "@mount_point", rb_tainted_str_new2(mp->mnt_mountp));
|
182
|
+
rb_iv_set(v_mount, "@mount_type", rb_tainted_str_new2(mp->mnt_fstype));
|
183
|
+
rb_iv_set(v_mount, "@options", rb_tainted_str_new2(mp->mnt_mntopts));
|
184
|
+
rb_iv_set(v_mount, "@mount_time", rb_time_new(atoi(mp->mnt_time), 0));
|
185
|
+
rb_iv_set(v_mount, "@dump_frequency", Qnil);
|
186
|
+
rb_iv_set(v_mount, "@pass_number", Qnil);
|
187
|
+
#else
|
188
|
+
rb_iv_set(v_mount, "@name", rb_tainted_str_new2(mp->mnt_fsname));
|
189
|
+
rb_iv_set(v_mount, "@mount_point", rb_tainted_str_new2(mp->mnt_dir));
|
190
|
+
rb_iv_set(v_mount, "@mount_type", rb_tainted_str_new2(mp->mnt_type));
|
191
|
+
rb_iv_set(v_mount, "@options", rb_tainted_str_new2(mp->mnt_opts));
|
192
|
+
rb_iv_set(v_mount, "@mount_time", Qnil);
|
193
|
+
rb_iv_set(v_mount, "@dump_frequency", INT2NUM(mp->mnt_freq));
|
194
|
+
rb_iv_set(v_mount, "@pass_number", INT2NUM(mp->mnt_passno));
|
195
|
+
#endif
|
196
|
+
|
197
|
+
return v_mount;
|
198
|
+
}
|
199
|
+
|
123
200
|
void Init_filesystem(){
|
124
201
|
/* The toplevel namespace */
|
125
202
|
mSys = rb_define_module("Sys");
|
@@ -129,13 +206,48 @@ void Init_filesystem(){
|
|
129
206
|
*/
|
130
207
|
cFilesys = rb_define_class_under(mSys, "Filesystem", rb_cObject);
|
131
208
|
|
209
|
+
/* Instances of this class are returned by the Filesystem.mount method */
|
210
|
+
cMount = rb_define_class_under(cFilesys, "Mount", rb_cObject);
|
211
|
+
|
132
212
|
/* Instances of this class are returned by the Filesystem.stat method */
|
133
|
-
cStat
|
213
|
+
cStat = rb_define_class_under(cFilesys, "Stat", rb_cObject);
|
134
214
|
|
135
215
|
/* Singleton methods */
|
216
|
+
rb_define_singleton_method(cFilesys, "mounts", fs_mounts, 0);
|
136
217
|
rb_define_singleton_method(cFilesys, "stat", fs_stat, 1);
|
137
218
|
|
138
|
-
/*
|
219
|
+
/* Filesystem::Mount accessors */
|
220
|
+
|
221
|
+
/* The name of the mounted resource */
|
222
|
+
rb_define_attr(cMount, "name", 1, 0);
|
223
|
+
|
224
|
+
/* The mount point/directory */
|
225
|
+
rb_define_attr(cMount, "mount_point", 1, 0);
|
226
|
+
|
227
|
+
/* The type of the file system mount, e.g. 'ufs', 'nfs', etc */
|
228
|
+
rb_define_attr(cMount, "mount_type", 1, 0);
|
229
|
+
|
230
|
+
/* A list of comma separated options for the mount, e.g. 'rw', etc */
|
231
|
+
rb_define_attr(cMount, "options", 1, 0);
|
232
|
+
|
233
|
+
/* The time the file system was mounted or nil if not supported */
|
234
|
+
rb_define_attr(cMount, "mount_time", 1, 0);
|
235
|
+
|
236
|
+
/* The dump frequency in days (or nil if not supported) */
|
237
|
+
rb_define_attr(cMount, "dump_frequency", 1, 0);
|
238
|
+
|
239
|
+
/* The pass number of the file system check or nil if not supported */
|
240
|
+
rb_define_attr(cMount, "pass_number", 1, 0);
|
241
|
+
|
242
|
+
/* Filesystem::Mount Aliases */
|
243
|
+
|
244
|
+
rb_define_alias(cMount, "fsname", "name");
|
245
|
+
rb_define_alias(cMount, "dir", "mount_point");
|
246
|
+
rb_define_alias(cMount, "opts", "options");
|
247
|
+
rb_define_alias(cMount, "passno", "pass_number");
|
248
|
+
rb_define_alias(cMount, "freq", "dump_frequency");
|
249
|
+
|
250
|
+
/* Filesystem::Stat accessors */
|
139
251
|
|
140
252
|
/* The path of the file system */
|
141
253
|
rb_define_attr(cStat, "path", 1, 0);
|
@@ -178,8 +290,8 @@ void Init_filesystem(){
|
|
178
290
|
|
179
291
|
/* Constants */
|
180
292
|
|
181
|
-
/* 0.
|
182
|
-
rb_define_const(cFilesys, "VERSION", rb_str_new2("0.
|
293
|
+
/* 0.2.0: The version of this library (a String) */
|
294
|
+
rb_define_const(cFilesys, "VERSION", rb_str_new2("0.2.0"));
|
183
295
|
|
184
296
|
/* 0x00000001: Read only file system */
|
185
297
|
rb_define_const(cStat, "RDONLY", INT2FIX(ST_RDONLY));
|
@@ -0,0 +1,234 @@
|
|
1
|
+
####################################################################
|
2
|
+
# tc_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 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'sys/filesystem'
|
12
|
+
include Sys
|
13
|
+
|
14
|
+
class TC_Sys_Filesystem_Unix < Test::Unit::TestCase
|
15
|
+
def self.startup
|
16
|
+
@@solaris = Config::CONFIG['host_os'] =~ /solaris/i
|
17
|
+
@@linux = Config::CONFIG['host_os'] =~ /linux/i
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@dir = "/"
|
22
|
+
@stat = Filesystem.stat(@dir)
|
23
|
+
@mnt = Filesystem.mounts[0]
|
24
|
+
@size = 58720256
|
25
|
+
@array = []
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_version
|
29
|
+
assert_equal('0.2.0', Filesystem::VERSION)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_stat_path
|
33
|
+
assert_respond_to(@stat, :path)
|
34
|
+
assert_equal("/", @stat.path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_stat_block_size
|
38
|
+
assert_respond_to(@stat, :block_size)
|
39
|
+
assert_kind_of(Fixnum, @stat.block_size)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_stat_fragment_size
|
43
|
+
assert_respond_to(@stat, :fragment_size)
|
44
|
+
assert_kind_of(Fixnum, @stat.fragment_size)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_stat_blocks
|
48
|
+
assert_respond_to(@stat, :blocks)
|
49
|
+
assert_kind_of(Fixnum, @stat.blocks)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_stat_blocks_free
|
53
|
+
assert_respond_to(@stat, :blocks_free)
|
54
|
+
assert_kind_of(Fixnum, @stat.blocks_free)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_stat_blocks_available
|
58
|
+
assert_respond_to(@stat, :blocks_available)
|
59
|
+
assert_kind_of(Fixnum, @stat.blocks_available)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_stat_files
|
63
|
+
assert_respond_to(@stat, :files)
|
64
|
+
assert_kind_of(Fixnum, @stat.files)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_inodes_alias
|
68
|
+
assert_respond_to(@stat, :inodes)
|
69
|
+
assert_true(@stat.method(:inodes) == @stat.method(:files))
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_stat_files_free
|
73
|
+
assert_respond_to(@stat, :files_free)
|
74
|
+
assert_kind_of(Fixnum, @stat.files_free)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_stat_inodes_free_alias
|
78
|
+
assert_respond_to(@stat, :inodes_free)
|
79
|
+
assert_true(@stat.method(:inodes_free) == @stat.method(:files_free))
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_stat_files_available
|
83
|
+
assert_respond_to(@stat, :files_available)
|
84
|
+
assert_kind_of(Fixnum, @stat.files_available)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_stat_inodes_available_alias
|
88
|
+
assert_respond_to(@stat, :inodes_available)
|
89
|
+
assert_true(@stat.method(:inodes_available) == @stat.method(:files_available))
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_stat_filesystem_id
|
93
|
+
assert_respond_to(@stat, :filesystem_id)
|
94
|
+
assert_kind_of(Integer, @stat.filesystem_id)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_stat_flags
|
98
|
+
assert_respond_to(@stat, :flags)
|
99
|
+
assert_kind_of(Fixnum, @stat.flags)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_stat_name_max
|
103
|
+
assert_respond_to(@stat, :name_max)
|
104
|
+
assert_kind_of(Fixnum, @stat.name_max)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_stat_base_type
|
108
|
+
omit_unless(@@solaris, "NOTRUNC test skipped except on Solaris")
|
109
|
+
assert_respond_to(@stat, :base_type)
|
110
|
+
assert_kind_of(String, @stat.base_type)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_stat_constants
|
114
|
+
assert_not_nil(Filesystem::Stat::RDONLY)
|
115
|
+
assert_not_nil(Filesystem::Stat::NOSUID)
|
116
|
+
omit_unless(@@solaris, "NOTRUNC test skipped except on Solaris")
|
117
|
+
assert_not_nil(Filesystem::Stat::NOTRUNC)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_stat_expected_errors
|
121
|
+
assert_raises(ArgumentError){ Filesystem.stat }
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_fixnum_methods_basic
|
125
|
+
assert_respond_to(@size, :to_kb)
|
126
|
+
assert_respond_to(@size, :to_mb)
|
127
|
+
assert_respond_to(@size, :to_gb)
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_to_kb
|
131
|
+
assert_equal(57344, @size.to_kb)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_to_mb
|
135
|
+
assert_equal(56, @size.to_mb)
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_to_gb
|
139
|
+
assert_equal(0, @size.to_gb)
|
140
|
+
end
|
141
|
+
|
142
|
+
# Filesystem::Mount tests
|
143
|
+
|
144
|
+
def test_mounts_with_no_block
|
145
|
+
assert_nothing_raised{ @array = Filesystem.mounts }
|
146
|
+
assert_kind_of(Filesystem::Mount, @array[0])
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_mounts_with_block
|
150
|
+
assert_nothing_raised{ Filesystem.mounts{ |m| @array << m } }
|
151
|
+
assert_kind_of(Filesystem::Mount, @array[0])
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_mounts_high_iteration
|
155
|
+
assert_nothing_raised{ 1000.times{ @array = Filesystem.mounts } }
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_mount_name
|
159
|
+
assert_respond_to(@mnt, :name)
|
160
|
+
assert_kind_of(String, @mnt.name)
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_fsname_alias
|
164
|
+
assert_respond_to(@mnt, :fsname)
|
165
|
+
assert_true(@mnt.method(:fsname) == @mnt.method(:name))
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_mount_point
|
169
|
+
assert_respond_to(@mnt, :mount_point)
|
170
|
+
assert_kind_of(String, @mnt.mount_point)
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_dir_alias
|
174
|
+
assert_respond_to(@mnt, :dir)
|
175
|
+
assert_true(@mnt.method(:dir) == @mnt.method(:mount_point))
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_mount_type
|
179
|
+
assert_respond_to(@mnt, :mount_type)
|
180
|
+
assert_kind_of(String, @mnt.mount_type)
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_mount_options
|
184
|
+
assert_respond_to(@mnt, :options)
|
185
|
+
assert_kind_of(String, @mnt.options)
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_opts_alias
|
189
|
+
assert_respond_to(@mnt, :opts)
|
190
|
+
assert_true(@mnt.method(:opts) == @mnt.method(:options))
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_mount_time
|
194
|
+
assert_respond_to(@mnt, :mount_time)
|
195
|
+
if @@solaris
|
196
|
+
assert_kind_of(String, @mnt.mount_time)
|
197
|
+
else
|
198
|
+
assert_nil(@mnt.mount_time)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_mount_dump_frequency
|
203
|
+
omit_if(@@solaris, 'dump_frequency test skipped on Solaris')
|
204
|
+
assert_respond_to(@mnt, :dump_frequency)
|
205
|
+
assert_kind_of(Fixnum, @mnt.dump_frequency)
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_freq_alias
|
209
|
+
assert_respond_to(@mnt, :freq)
|
210
|
+
assert_true(@mnt.method(:freq) == @mnt.method(:dump_frequency))
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_mount_pass_number
|
214
|
+
omit_if(@@solaris, 'pass_number test skipped on Solaris')
|
215
|
+
assert_respond_to(@mnt, :pass_number)
|
216
|
+
assert_kind_of(Fixnum, @mnt.pass_number)
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_passno_alias
|
220
|
+
assert_respond_to(@mnt, :passno)
|
221
|
+
assert_true(@mnt.method(:passno) == @mnt.method(:pass_number))
|
222
|
+
end
|
223
|
+
|
224
|
+
def teardown
|
225
|
+
@dir = nil
|
226
|
+
@stat = nil
|
227
|
+
@array = nil
|
228
|
+
end
|
229
|
+
|
230
|
+
def self.shutdown
|
231
|
+
@@solaris = nil
|
232
|
+
@@linux = nil
|
233
|
+
end
|
234
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
####################################################################
|
2
|
+
# tc_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 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'sys/filesystem'
|
12
|
+
require 'rbconfig'
|
13
|
+
include Sys
|
14
|
+
|
15
|
+
class TC_Sys_Filesystem_Windows < Test::Unit::TestCase
|
16
|
+
def setup
|
17
|
+
@dir = '/'
|
18
|
+
@stat = Filesystem.stat(@dir)
|
19
|
+
@mount = Filesystem.mounts[0]
|
20
|
+
@size = 58720256
|
21
|
+
@array = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_version
|
25
|
+
assert_equal('0.2.0', Filesystem::VERSION)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_stat_path
|
29
|
+
assert_respond_to(@stat, :path)
|
30
|
+
assert_equal("/", @stat.path)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_stat_block_size
|
34
|
+
assert_respond_to(@stat, :block_size)
|
35
|
+
assert_kind_of(Fixnum, @stat.block_size)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_stat_fragment_size
|
39
|
+
assert_respond_to(@stat, :fragment_size)
|
40
|
+
assert_nil(@stat.fragment_size)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_stat_blocks
|
44
|
+
assert_respond_to(@stat, :blocks)
|
45
|
+
assert_kind_of(Fixnum, @stat.blocks)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_stat_blocks_free
|
49
|
+
assert_respond_to(@stat, :blocks_free)
|
50
|
+
assert_kind_of(Fixnum, @stat.blocks_free)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_stat_blocks_available
|
54
|
+
assert_respond_to(@stat, :blocks_available)
|
55
|
+
assert_kind_of(Fixnum, @stat.blocks_available)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_stat_files
|
59
|
+
assert_respond_to(@stat, :files)
|
60
|
+
assert_respond_to(@stat, :inodes) # Alias
|
61
|
+
assert_nil(@stat.files)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_stat_files_free
|
65
|
+
assert_respond_to(@stat, :files_free)
|
66
|
+
assert_respond_to(@stat, :inodes_free) # Alias
|
67
|
+
assert_nil(@stat.files_free)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_stat_files_available
|
71
|
+
assert_respond_to(@stat, :files_available)
|
72
|
+
assert_respond_to(@stat, :inodes_available) # Alias
|
73
|
+
assert_nil(@stat.files_available)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_stat_filesystem_id
|
77
|
+
assert_respond_to(@stat, :filesystem_id)
|
78
|
+
assert_kind_of(Integer, @stat.filesystem_id)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_stat_flags
|
82
|
+
assert_respond_to(@stat, :flags)
|
83
|
+
assert_kind_of(Fixnum, @stat.flags)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_stat_name_max
|
87
|
+
assert_respond_to(@stat, :name_max)
|
88
|
+
assert_kind_of(Fixnum, @stat.name_max)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_stat_base_type
|
92
|
+
assert_respond_to(@stat, :base_type)
|
93
|
+
assert_kind_of(String, @stat.base_type)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_constants
|
97
|
+
assert_not_nil(Filesystem::CASE_SENSITIVE_SEARCH)
|
98
|
+
assert_not_nil(Filesystem::CASE_PRESERVED_NAMES)
|
99
|
+
assert_not_nil(Filesystem::UNICODE_ON_DISK)
|
100
|
+
assert_not_nil(Filesystem::PERSISTENT_ACLS)
|
101
|
+
assert_not_nil(Filesystem::FILE_COMPRESSION)
|
102
|
+
assert_not_nil(Filesystem::VOLUME_QUOTAS)
|
103
|
+
assert_not_nil(Filesystem::SUPPORTS_SPARSE_FILES)
|
104
|
+
assert_not_nil(Filesystem::SUPPORTS_REPARSE_POINTS)
|
105
|
+
assert_not_nil(Filesystem::SUPPORTS_REMOTE_STORAGE)
|
106
|
+
assert_not_nil(Filesystem::VOLUME_IS_COMPRESSED)
|
107
|
+
assert_not_nil(Filesystem::SUPPORTS_OBJECT_IDS)
|
108
|
+
assert_not_nil(Filesystem::SUPPORTS_ENCRYPTION)
|
109
|
+
assert_not_nil(Filesystem::NAMED_STREAMS)
|
110
|
+
assert_not_nil(Filesystem::READ_ONLY_VOLUME)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_stat_expected_errors
|
114
|
+
assert_raises(ArgumentError){ Filesystem.stat }
|
115
|
+
end
|
116
|
+
|
117
|
+
# Filesystem.mounts
|
118
|
+
|
119
|
+
def test_mounts_constructor_basic
|
120
|
+
assert_respond_to(Filesystem, :mounts)
|
121
|
+
assert_nothing_raised{ Filesystem.mounts }
|
122
|
+
assert_nothing_raised{ Filesystem.mounts{} }
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_mounts
|
126
|
+
assert_kind_of(Array, Filesystem.mounts)
|
127
|
+
assert_kind_of(Filesystem::Mount, Filesystem.mounts[0])
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_mounts_block_form
|
131
|
+
assert_nil(Filesystem.mounts{})
|
132
|
+
assert_nothing_raised{ Filesystem.mounts{ |mt| @array << mt }}
|
133
|
+
assert_kind_of(Filesystem::Mount, @array[0])
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_mount_name
|
137
|
+
assert_respond_to(@mount, :name)
|
138
|
+
assert_kind_of(String, @mount.name)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_mount_time
|
142
|
+
assert_respond_to(@mount, :mount_time)
|
143
|
+
assert_kind_of(Time, @mount.mount_time)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_mount_type
|
147
|
+
assert_respond_to(@mount, :mount_type)
|
148
|
+
assert_kind_of(String, @mount.mount_type)
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_mount_point
|
152
|
+
assert_respond_to(@mount, :mount_point)
|
153
|
+
assert_kind_of(String, @mount.mount_point)
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_mount_options
|
157
|
+
assert_respond_to(@mount, :options)
|
158
|
+
assert_kind_of(String, @mount.options)
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_pass_number
|
162
|
+
assert_respond_to(@mount, :pass_number)
|
163
|
+
assert_nil(@mount.pass_number)
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_frequency
|
167
|
+
assert_respond_to(@mount, :frequency)
|
168
|
+
assert_nil(@mount.frequency)
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_mounts_expected_errors
|
172
|
+
assert_raise(ArgumentError){ Filesystem.mounts("C:\\") }
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_fixnum_methods
|
176
|
+
assert_respond_to(@size, :to_kb)
|
177
|
+
assert_respond_to(@size, :to_mb)
|
178
|
+
assert_respond_to(@size, :to_gb)
|
179
|
+
|
180
|
+
assert_equal(57344, @size.to_kb)
|
181
|
+
assert_equal(56, @size.to_mb)
|
182
|
+
assert_equal(0, @size.to_gb)
|
183
|
+
end
|
184
|
+
|
185
|
+
def teardown
|
186
|
+
@array = nil
|
187
|
+
@dir = nil
|
188
|
+
@stat = nil
|
189
|
+
@size = nil
|
190
|
+
@mount = nil
|
191
|
+
end
|
192
|
+
end
|
metadata
CHANGED
@@ -1,57 +1,67 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.2
|
3
|
-
specification_version: 1
|
4
2
|
name: sys-filesystem
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-03-28 00:00:00 -06:00
|
8
|
-
summary: A Ruby interface for getting file system information.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: djberg96@gmail.com
|
12
|
-
homepage: http://www.rubyforge.org/projects/sysutils
|
13
|
-
rubyforge_project: sysutils
|
14
|
-
description: A Ruby interface for getting file system information.
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.8.0
|
24
|
-
version:
|
4
|
+
version: 0.2.0
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Daniel J. Berger
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-12-13 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A Ruby interface for getting file system information.
|
17
|
+
email: djberg96@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions:
|
21
|
+
- ext/extconf.rb
|
22
|
+
extra_rdoc_files:
|
35
23
|
- CHANGES
|
24
|
+
- README
|
25
|
+
- MANIFEST
|
26
|
+
- ext/sys/filesystem.c
|
27
|
+
files:
|
28
|
+
- doc/sys-filesystem.txt
|
29
|
+
- examples/example_stat.rb
|
30
|
+
- test/test_sys_filesystem_unix.rb
|
31
|
+
- test/test_sys_filesystem.rb
|
32
|
+
- test/test_sys_filesystem_windows.rb
|
36
33
|
- MANIFEST
|
37
34
|
- README
|
35
|
+
- CHANGES
|
38
36
|
- Rakefile
|
39
37
|
- ext/extconf.rb
|
40
|
-
- ext/
|
41
|
-
|
42
|
-
|
38
|
+
- ext/sys
|
39
|
+
- ext/sys/filesystem.c
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://www.rubyforge.org/projects/sysutils
|
42
|
+
post_install_message:
|
43
43
|
rdoc_options: []
|
44
44
|
|
45
|
-
|
46
|
-
-
|
47
|
-
|
48
|
-
|
49
|
-
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 1.8.0
|
52
|
+
version:
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
54
59
|
requirements: []
|
55
60
|
|
56
|
-
|
57
|
-
|
61
|
+
rubyforge_project: sysutils
|
62
|
+
rubygems_version: 1.3.1
|
63
|
+
signing_key:
|
64
|
+
specification_version: 2
|
65
|
+
summary: A Ruby interface for getting file system information.
|
66
|
+
test_files:
|
67
|
+
- test/test_sys_filesystem.rb
|
data/test/tc_filesystem.rb
DELETED
data/test/tc_unix.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
####################################################################
|
2
|
-
# tc_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
|
-
include Sys
|
10
|
-
|
11
|
-
class TC_Filesystem_Unix < Test::Unit::TestCase
|
12
|
-
def setup
|
13
|
-
@dir = "/"
|
14
|
-
@stat = Filesystem.stat(@dir)
|
15
|
-
@size = 58720256
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_version
|
19
|
-
assert_equal('0.1.1', Filesystem::VERSION)
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_stat_path
|
23
|
-
assert_respond_to(@stat, :path)
|
24
|
-
assert_equal("/", @stat.path)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_stat_block_size
|
28
|
-
assert_respond_to(@stat, :block_size)
|
29
|
-
assert_kind_of(Fixnum, @stat.block_size)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_stat_fragment_size
|
33
|
-
assert_respond_to(@stat, :fragment_size)
|
34
|
-
assert_kind_of(Fixnum, @stat.fragment_size)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_stat_blocks
|
38
|
-
assert_respond_to(@stat, :blocks)
|
39
|
-
assert_kind_of(Fixnum, @stat.blocks)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_stat_blocks_free
|
43
|
-
assert_respond_to(@stat, :blocks_free)
|
44
|
-
assert_kind_of(Fixnum, @stat.blocks_free)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_stat_blocks_available
|
48
|
-
assert_respond_to(@stat, :blocks_available)
|
49
|
-
assert_kind_of(Fixnum, @stat.blocks_available)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_stat_files
|
53
|
-
assert_respond_to(@stat, :files)
|
54
|
-
assert_respond_to(@stat, :inodes) # Alias
|
55
|
-
assert_kind_of(Fixnum, @stat.files)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_stat_files_free
|
59
|
-
assert_respond_to(@stat, :files_free)
|
60
|
-
assert_respond_to(@stat, :inodes_free) # Alias
|
61
|
-
assert_kind_of(Fixnum, @stat.files_free)
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_stat_files_available
|
65
|
-
assert_respond_to(@stat, :files_available)
|
66
|
-
assert_respond_to(@stat, :inodes_available) # Alias
|
67
|
-
assert_kind_of(Fixnum, @stat.files_available)
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_stat_filesystem_id
|
71
|
-
assert_respond_to(@stat, :filesystem_id)
|
72
|
-
assert_kind_of(Fixnum, @stat.filesystem_id)
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_stat_flags
|
76
|
-
assert_respond_to(@stat, :flags)
|
77
|
-
assert_kind_of(Fixnum, @stat.flags)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_stat_name_max
|
81
|
-
assert_respond_to(@stat, :name_max)
|
82
|
-
assert_kind_of(Fixnum, @stat.name_max)
|
83
|
-
end
|
84
|
-
|
85
|
-
unless RUBY_PLATFORM =~ /linux|darwin/i
|
86
|
-
def test_stat_base_type
|
87
|
-
assert_respond_to(@stat, :base_type)
|
88
|
-
assert_kind_of(String, @stat.base_type)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_stat_constants
|
93
|
-
assert_not_nil(Filesystem::Stat::RDONLY)
|
94
|
-
assert_not_nil(Filesystem::Stat::NOSUID)
|
95
|
-
unless RUBY_PLATFORM =~ /linux|darwin/i
|
96
|
-
assert_not_nil(Filesystem::Stat::NOTRUNC)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_stat_expected_errors
|
101
|
-
assert_raises(ArgumentError){ Filesystem.stat }
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_fixnum_methods
|
105
|
-
assert_respond_to(@size, :to_kb)
|
106
|
-
assert_respond_to(@size, :to_mb)
|
107
|
-
assert_respond_to(@size, :to_gb)
|
108
|
-
|
109
|
-
assert_equal(57344, @size.to_kb)
|
110
|
-
assert_equal(56, @size.to_mb)
|
111
|
-
assert_equal(0, @size.to_gb)
|
112
|
-
end
|
113
|
-
|
114
|
-
def teardown
|
115
|
-
@dir = nil
|
116
|
-
@stat = nil
|
117
|
-
end
|
118
|
-
end
|
data/test/tc_windows.rb
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
####################################################################
|
2
|
-
# tc_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
|
-
include Sys
|
10
|
-
|
11
|
-
class TC_Filesystem_Unix < Test::Unit::TestCase
|
12
|
-
def setup
|
13
|
-
@dir = "/"
|
14
|
-
@stat = Filesystem.stat(@dir)
|
15
|
-
@size = 58720256
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_version
|
19
|
-
assert_equal('0.1.1', Filesystem::VERSION)
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_stat_path
|
23
|
-
assert_respond_to(@stat, :path)
|
24
|
-
assert_equal("/", @stat.path)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_stat_block_size
|
28
|
-
assert_respond_to(@stat, :block_size)
|
29
|
-
assert_kind_of(Fixnum, @stat.block_size)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_stat_fragment_size
|
33
|
-
assert_respond_to(@stat, :fragment_size)
|
34
|
-
assert_nil(@stat.fragment_size)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_stat_blocks
|
38
|
-
assert_respond_to(@stat, :blocks)
|
39
|
-
assert_kind_of(Fixnum, @stat.blocks)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_stat_blocks_free
|
43
|
-
assert_respond_to(@stat, :blocks_free)
|
44
|
-
assert_kind_of(Fixnum, @stat.blocks_free)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_stat_blocks_available
|
48
|
-
assert_respond_to(@stat, :blocks_available)
|
49
|
-
assert_kind_of(Fixnum, @stat.blocks_available)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_stat_files
|
53
|
-
assert_respond_to(@stat, :files)
|
54
|
-
assert_respond_to(@stat, :inodes) # Alias
|
55
|
-
assert_nil(@stat.files)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_stat_files_free
|
59
|
-
assert_respond_to(@stat, :files_free)
|
60
|
-
assert_respond_to(@stat, :inodes_free) # Alias
|
61
|
-
assert_nil(@stat.files_free)
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_stat_files_available
|
65
|
-
assert_respond_to(@stat, :files_available)
|
66
|
-
assert_respond_to(@stat, :inodes_available) # Alias
|
67
|
-
assert_nil(@stat.files_available)
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_stat_filesystem_id
|
71
|
-
assert_respond_to(@stat, :filesystem_id)
|
72
|
-
assert_kind_of(Integer, @stat.filesystem_id)
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_stat_flags
|
76
|
-
assert_respond_to(@stat, :flags)
|
77
|
-
assert_kind_of(Fixnum, @stat.flags)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_stat_name_max
|
81
|
-
assert_respond_to(@stat, :name_max)
|
82
|
-
assert_kind_of(Fixnum, @stat.name_max)
|
83
|
-
end
|
84
|
-
|
85
|
-
unless RUBY_PLATFORM.match('linux')
|
86
|
-
def test_stat_base_type
|
87
|
-
assert_respond_to(@stat, :base_type)
|
88
|
-
assert_kind_of(String, @stat.base_type)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_stat_constants
|
93
|
-
assert_not_nil(Filesystem::Stat::CASE_SENSITIVE_SEARCH)
|
94
|
-
assert_not_nil(Filesystem::Stat::CASE_PRESERVED_NAMES)
|
95
|
-
assert_not_nil(Filesystem::Stat::UNICODE_ON_DISK)
|
96
|
-
assert_not_nil(Filesystem::Stat::PERSISTENT_ACLS)
|
97
|
-
assert_not_nil(Filesystem::Stat::FILE_COMPRESSION)
|
98
|
-
assert_not_nil(Filesystem::Stat::VOLUME_QUOTAS)
|
99
|
-
assert_not_nil(Filesystem::Stat::SUPPORTS_SPARSE_FILES)
|
100
|
-
assert_not_nil(Filesystem::Stat::SUPPORTS_REPARSE_POINTS)
|
101
|
-
assert_not_nil(Filesystem::Stat::SUPPORTS_REMOTE_STORAGE)
|
102
|
-
assert_not_nil(Filesystem::Stat::VOLUME_IS_COMPRESSED)
|
103
|
-
assert_not_nil(Filesystem::Stat::SUPPORTS_OBJECT_IDS)
|
104
|
-
assert_not_nil(Filesystem::Stat::SUPPORTS_ENCRYPTION)
|
105
|
-
assert_not_nil(Filesystem::Stat::NAMED_STREAMS)
|
106
|
-
assert_not_nil(Filesystem::Stat::READ_ONLY_VOLUME)
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_stat_expected_errors
|
110
|
-
assert_raises(ArgumentError){ Filesystem.stat }
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_fixnum_methods
|
114
|
-
assert_respond_to(@size, :to_kb)
|
115
|
-
assert_respond_to(@size, :to_mb)
|
116
|
-
assert_respond_to(@size, :to_gb)
|
117
|
-
|
118
|
-
assert_equal(57344, @size.to_kb)
|
119
|
-
assert_equal(56, @size.to_mb)
|
120
|
-
assert_equal(0, @size.to_gb)
|
121
|
-
end
|
122
|
-
|
123
|
-
def teardown
|
124
|
-
@dir = nil
|
125
|
-
@stat = nil
|
126
|
-
end
|
127
|
-
end
|