sys-filesystem 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +9 -0
- data/MANIFEST +11 -14
- data/README +17 -10
- data/Rakefile +70 -0
- data/ext/extconf.rb +13 -0
- data/ext/filesystem.c +36 -13
- data/test/tc_unix.rb +4 -15
- data/test/tc_windows.rb +3 -5
- metadata +7 -5
- data/extconf.rb +0 -9
data/CHANGES
CHANGED
@@ -1,2 +1,11 @@
|
|
1
|
+
== 0.1.1 - 28-Mar-2007
|
2
|
+
* Bug fix for BSD flavors. Thanks go to Jeremy Kemper and Ole Christian
|
3
|
+
Rynning for the spot.
|
4
|
+
* Bug fix for OS X (along the same lines as the BSD fix). Thanks go to
|
5
|
+
Aurelian Dehay for the spot.
|
6
|
+
* Some Rdoc improvements for the C extension.
|
7
|
+
* Tweaks to the gemspec.
|
8
|
+
* Added synopsis to the README.
|
9
|
+
|
1
10
|
== 0.1.0 - 17-Nov-2006
|
2
11
|
* Initial release. Alpha. Code is stable, but API is not.
|
data/MANIFEST
CHANGED
@@ -1,14 +1,11 @@
|
|
1
|
-
MANIFEST
|
2
|
-
CHANGES
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
sys-fileystem.gemspec
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
lib/sys/filesystem.rb
|
13
|
-
|
14
|
-
test/tc_filesystem.rb
|
1
|
+
* MANIFEST
|
2
|
+
* CHANGES
|
3
|
+
* Rakefile
|
4
|
+
* README
|
5
|
+
* install.rb
|
6
|
+
* sys-fileystem.gemspec
|
7
|
+
* examples/example_stat.rb
|
8
|
+
* ext/extconf.rb
|
9
|
+
* ext/filesystem.c
|
10
|
+
* lib/sys/filesystem.rb
|
11
|
+
* test/tc_filesystem.rb
|
data/README
CHANGED
@@ -6,15 +6,18 @@
|
|
6
6
|
* windows-pr, 0.6.0 or later.
|
7
7
|
|
8
8
|
= Installation
|
9
|
-
===
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
=== Manual Installation
|
10
|
+
rake test (optional)
|
11
|
+
rake install
|
12
|
+
=== Gem Installation
|
13
|
+
ruby sys-filesystem.gemspec
|
14
|
+
gem install sys-filesystem-X.Y.Z.gem
|
15
|
+
|
16
|
+
= Synopsis
|
17
|
+
require 'sys/filesystem'
|
18
|
+
include Sys
|
19
|
+
|
20
|
+
p Filesystem.stat("/")
|
18
21
|
|
19
22
|
= Notes
|
20
23
|
=== MS Windows
|
@@ -23,6 +26,10 @@
|
|
23
26
|
=== UNIX
|
24
27
|
This is a C extension that wraps statvfs, etc.
|
25
28
|
|
29
|
+
= Sample code
|
30
|
+
Run 'rake example' if you want to see a basic sample run. The actual code
|
31
|
+
is 'example_stat.rb' in the 'examples' directory. Modify it as you see fit.
|
32
|
+
|
26
33
|
= Known Bugs
|
27
34
|
None that I'm aware of. Please report bugs on the project page at
|
28
35
|
http://www.rubyforge.org/projects/sysutils.
|
@@ -35,7 +42,7 @@
|
|
35
42
|
Park Heesob, for implementation and API ideas for the MS Windows version.
|
36
43
|
|
37
44
|
= Copyright
|
38
|
-
(C) 2003-
|
45
|
+
(C) 2003-2007 Daniel J. Berger
|
39
46
|
All Rights Reserved
|
40
47
|
|
41
48
|
= Warranty
|
data/Rakefile
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
desc "Clean the build files for the sys-filesystem source for UNIX systems"
|
6
|
+
task :clean do
|
7
|
+
Dir.chdir('examples') do
|
8
|
+
FileUtils.rm_rf('sys') if File.exists?('sys')
|
9
|
+
end
|
10
|
+
|
11
|
+
Dir.chdir('ext') do
|
12
|
+
unless RUBY_PLATFORM.match('mswin')
|
13
|
+
FileUtils.rm_rf('sys') if File.exists?('sys')
|
14
|
+
build_file = 'filesystem.' + Config::CONFIG['DLEXT']
|
15
|
+
sh 'make distclean' if File.exists?(build_file)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Build the sys-filesystem package on UNIX systems (but don't install it)"
|
21
|
+
task :build => [:clean] do
|
22
|
+
Dir.chdir('ext') do
|
23
|
+
unless RUBY_PLATFORM.match('mswin')
|
24
|
+
ruby 'extconf.rb'
|
25
|
+
sh 'make'
|
26
|
+
build_file = 'filesystem.' + Config::CONFIG['DLEXT']
|
27
|
+
Dir.mkdir('sys') unless File.exists?('sys')
|
28
|
+
FileUtils.cp(build_file, 'sys')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
if RUBY_PLATFORM.match('mswin')
|
34
|
+
desc "Install the sys-filesystem package"
|
35
|
+
task :install do
|
36
|
+
sh 'ruby install.rb'
|
37
|
+
end
|
38
|
+
else
|
39
|
+
desc "Install the sys-filesystem package"
|
40
|
+
task :install => [:build] do
|
41
|
+
Dir.chdir('ext') do
|
42
|
+
sh 'make install'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Run the test suite"
|
48
|
+
Rake::TestTask.new("test") do |t|
|
49
|
+
if RUBY_PLATFORM.match('mswin')
|
50
|
+
t.libs << 'lib'
|
51
|
+
else
|
52
|
+
task :test => :build
|
53
|
+
t.libs << 'ext'
|
54
|
+
t.libs.delete('lib')
|
55
|
+
end
|
56
|
+
t.test_files = FileList['test/tc_filesystem.rb']
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "Run the example program"
|
60
|
+
task :example => [:build] do |t|
|
61
|
+
Dir.chdir('examples') do
|
62
|
+
Dir.mkdir('sys') unless File.exists?('sys')
|
63
|
+
end
|
64
|
+
|
65
|
+
FileUtils.cp('ext/sys/filesystem.' + Config::CONFIG['DLEXT'], 'examples/sys')
|
66
|
+
|
67
|
+
Dir.chdir('examples') do
|
68
|
+
ruby 'example_stat.rb'
|
69
|
+
end
|
70
|
+
end
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
have_header("sys/mnttab.h")
|
4
|
+
have_header("mntent.h")
|
5
|
+
have_func("statvfs")
|
6
|
+
|
7
|
+
if have_header("sys/statvfs.h")
|
8
|
+
have_struct_member("struct statvfs", "f_basetype", "sys/statvfs.h")
|
9
|
+
else
|
10
|
+
have_header("sys/vnode.h")
|
11
|
+
end
|
12
|
+
|
13
|
+
create_makefile("sys/filesystem")
|
data/ext/filesystem.c
CHANGED
@@ -7,11 +7,17 @@
|
|
7
7
|
#include <ruby.h>
|
8
8
|
|
9
9
|
#include <sys/types.h>
|
10
|
+
|
11
|
+
#ifdef HAVE_SYS_STATVFS_H /* Most flavors of UNIX */
|
10
12
|
#include <sys/statvfs.h>
|
13
|
+
#else /* FreeBSD 4.x */
|
14
|
+
#include <sys/param.h>
|
15
|
+
#include <sys/mount.h>
|
16
|
+
#include <sys/vnode.h>
|
17
|
+
#endif
|
11
18
|
|
12
|
-
#ifdef HAVE_SYS_MNTTAB_H
|
19
|
+
#ifdef HAVE_SYS_MNTTAB_H /* Solaris */
|
13
20
|
|
14
|
-
/* Solaris */
|
15
21
|
#include <sys/mnttab.h>
|
16
22
|
#define MNTENT mnttab
|
17
23
|
#define START_MNT(F,M) fopen(F,M)
|
@@ -19,15 +25,16 @@
|
|
19
25
|
#define END_MNT(F) fclose(F)
|
20
26
|
#define MOUNTLIST "/etc/mnttab"
|
21
27
|
|
22
|
-
#else
|
28
|
+
#else /* Most flavors of UNIX */
|
23
29
|
|
24
|
-
|
30
|
+
#ifdef HAVE_MNTENT_H
|
25
31
|
#include <mntent.h>
|
26
32
|
#define MNTENT mntent
|
27
33
|
#define START_MNT(F,M) setmntent(F,M)
|
28
34
|
#define GET_MNT(FP,MP) ((MP = getmntent(FP)) != NULL)
|
29
35
|
#define END_MNT(F) endmntent(F)
|
30
36
|
#define MOUNTLIST "/etc/mtab"
|
37
|
+
#endif
|
31
38
|
|
32
39
|
#endif
|
33
40
|
|
@@ -41,11 +48,21 @@ VALUE mSys, cFilesys, cStat;
|
|
41
48
|
*/
|
42
49
|
static VALUE fs_stat(VALUE klass, VALUE v_path){
|
43
50
|
VALUE v_stat;
|
44
|
-
struct statvfs fs;
|
45
51
|
char* path = StringValuePtr(v_path);
|
46
52
|
|
53
|
+
#ifdef HAVE_STATVFS
|
54
|
+
struct statvfs fs;
|
55
|
+
|
47
56
|
if(statvfs(path, &fs) < 0)
|
48
57
|
rb_sys_fail("statvfs");
|
58
|
+
#else
|
59
|
+
struct mount mp;
|
60
|
+
struct statfs fs;
|
61
|
+
struct proc p;
|
62
|
+
|
63
|
+
if(VFS_STATFS(&mp, &fs, &p) < 0)
|
64
|
+
rb_sys_fail("VFS_STATFS");
|
65
|
+
#endif
|
49
66
|
|
50
67
|
v_stat = rb_funcall(cStat, rb_intern("new"), 0, 0);
|
51
68
|
|
@@ -104,10 +121,16 @@ static VALUE fixnum_to_gb(VALUE self){
|
|
104
121
|
}
|
105
122
|
|
106
123
|
void Init_filesystem(){
|
107
|
-
/*
|
108
|
-
mSys
|
124
|
+
/* The toplevel namespace */
|
125
|
+
mSys = rb_define_module("Sys");
|
126
|
+
|
127
|
+
/* The Filesystem class serves an abstract base class. It's methods return
|
128
|
+
* objects of other types. Do not instantiate.
|
129
|
+
*/
|
109
130
|
cFilesys = rb_define_class_under(mSys, "Filesystem", rb_cObject);
|
110
|
-
|
131
|
+
|
132
|
+
/* Instances of this class are returned by the Filesystem.stat method */
|
133
|
+
cStat = rb_define_class_under(cFilesys, "Stat", rb_cObject);
|
111
134
|
|
112
135
|
/* Singleton methods */
|
113
136
|
rb_define_singleton_method(cFilesys, "stat", fs_stat, 1);
|
@@ -155,17 +178,17 @@ void Init_filesystem(){
|
|
155
178
|
|
156
179
|
/* Constants */
|
157
180
|
|
158
|
-
/* The version of this package */
|
159
|
-
rb_define_const(cFilesys, "VERSION", rb_str_new2("0.1.
|
181
|
+
/* 0.1.1: The version of this package */
|
182
|
+
rb_define_const(cFilesys, "VERSION", rb_str_new2("0.1.1"));
|
160
183
|
|
161
|
-
/* Read only file system */
|
184
|
+
/* 0x00000001: Read only file system */
|
162
185
|
rb_define_const(cStat, "RDONLY", INT2FIX(ST_RDONLY));
|
163
186
|
|
164
|
-
/* File system does not support suid or sgid semantics */
|
187
|
+
/* 0x00000002: File system does not support suid or sgid semantics */
|
165
188
|
rb_define_const(cStat, "NOSUID", INT2FIX(ST_NOSUID));
|
166
189
|
|
167
190
|
#ifdef ST_NOTRUNC
|
168
|
-
/* File system does not truncate file names longer than +name_max+ */
|
191
|
+
/* 0x00000003: File system does not truncate file names longer than +name_max+ */
|
169
192
|
rb_define_const(cStat, "NOTRUNC", INT2FIX(ST_NOTRUNC));
|
170
193
|
#endif
|
171
194
|
|
data/test/tc_unix.rb
CHANGED
@@ -2,19 +2,8 @@
|
|
2
2
|
# tc_unix.rb
|
3
3
|
#
|
4
4
|
# Test case for the Sys::Filesystem.stat method and related stuff.
|
5
|
+
# This test suite should be run via the 'rake test' task.
|
5
6
|
####################################################################
|
6
|
-
base = File.basename(Dir.pwd)
|
7
|
-
|
8
|
-
if base == 'test' || base =~ /filesystem/i
|
9
|
-
require 'fileutils'
|
10
|
-
require 'rbconfig'
|
11
|
-
Dir.chdir('..') if base == 'test'
|
12
|
-
Dir.mkdir('sys') rescue nil
|
13
|
-
file = 'filesystem.' + Config::CONFIG['DLEXT']
|
14
|
-
FileUtils.cp(file, 'sys')
|
15
|
-
$LOAD_PATH.unshift(Dir.pwd)
|
16
|
-
end
|
17
|
-
|
18
7
|
require 'test/unit'
|
19
8
|
require 'sys/filesystem'
|
20
9
|
include Sys
|
@@ -27,7 +16,7 @@ class TC_Filesystem_Unix < Test::Unit::TestCase
|
|
27
16
|
end
|
28
17
|
|
29
18
|
def test_version
|
30
|
-
assert_equal('0.1.
|
19
|
+
assert_equal('0.1.1', Filesystem::VERSION)
|
31
20
|
end
|
32
21
|
|
33
22
|
def test_stat_path
|
@@ -93,7 +82,7 @@ class TC_Filesystem_Unix < Test::Unit::TestCase
|
|
93
82
|
assert_kind_of(Fixnum, @stat.name_max)
|
94
83
|
end
|
95
84
|
|
96
|
-
unless RUBY_PLATFORM
|
85
|
+
unless RUBY_PLATFORM =~ /linux|darwin/i
|
97
86
|
def test_stat_base_type
|
98
87
|
assert_respond_to(@stat, :base_type)
|
99
88
|
assert_kind_of(String, @stat.base_type)
|
@@ -103,7 +92,7 @@ class TC_Filesystem_Unix < Test::Unit::TestCase
|
|
103
92
|
def test_stat_constants
|
104
93
|
assert_not_nil(Filesystem::Stat::RDONLY)
|
105
94
|
assert_not_nil(Filesystem::Stat::NOSUID)
|
106
|
-
unless RUBY_PLATFORM
|
95
|
+
unless RUBY_PLATFORM =~ /linux|darwin/i
|
107
96
|
assert_not_nil(Filesystem::Stat::NOTRUNC)
|
108
97
|
end
|
109
98
|
end
|
data/test/tc_windows.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
####################################################################
|
2
|
-
#
|
2
|
+
# tc_windows.rb
|
3
3
|
#
|
4
4
|
# Test case for the Sys::Filesystem.stat method and related stuff.
|
5
|
+
# This should be run via the 'rake test' task.
|
5
6
|
####################################################################
|
6
|
-
Dir.chdir('..') if File.basename(Dir.pwd) == 'test'
|
7
|
-
$LOAD_PATH.unshift(Dir.pwd + '/lib')
|
8
|
-
|
9
7
|
require 'test/unit'
|
10
8
|
require 'sys/filesystem'
|
11
9
|
include Sys
|
@@ -18,7 +16,7 @@ class TC_Filesystem_Unix < Test::Unit::TestCase
|
|
18
16
|
end
|
19
17
|
|
20
18
|
def test_version
|
21
|
-
assert_equal('0.1.
|
19
|
+
assert_equal('0.1.1', Filesystem::VERSION)
|
22
20
|
end
|
23
21
|
|
24
22
|
def test_stat_path
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.2
|
3
3
|
specification_version: 1
|
4
4
|
name: sys-filesystem
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date:
|
6
|
+
version: 0.1.1
|
7
|
+
date: 2007-03-28 00:00:00 -06:00
|
8
8
|
summary: A Ruby interface for getting file system information.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -35,7 +35,8 @@ files:
|
|
35
35
|
- CHANGES
|
36
36
|
- MANIFEST
|
37
37
|
- README
|
38
|
-
-
|
38
|
+
- Rakefile
|
39
|
+
- ext/extconf.rb
|
39
40
|
- ext/filesystem.c
|
40
41
|
test_files:
|
41
42
|
- test/tc_filesystem.rb
|
@@ -45,10 +46,11 @@ extra_rdoc_files:
|
|
45
46
|
- CHANGES
|
46
47
|
- README
|
47
48
|
- MANIFEST
|
49
|
+
- ext/filesystem.c
|
48
50
|
executables: []
|
49
51
|
|
50
52
|
extensions:
|
51
|
-
- extconf.rb
|
53
|
+
- ext/extconf.rb
|
52
54
|
requirements: []
|
53
55
|
|
54
56
|
dependencies: []
|