mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
file.c: statfs_inspect
* file.c (statfs_inspect): add File::Statfs#inspect method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d8bb478e26
commit
ca258c86cf
2 changed files with 43 additions and 0 deletions
38
file.c
38
file.c
|
@ -5550,6 +5550,43 @@ statfs_fstypename(VALUE self)
|
|||
#else
|
||||
#define statfs_fstypename rb_f_notimplement
|
||||
#endif
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* st.inspect -> string
|
||||
*
|
||||
* Returns total file nodes in filesystem.
|
||||
*
|
||||
* f = File.new("testfile")
|
||||
* s = f.statfs
|
||||
* s.inspect #=> ""
|
||||
* #=> "#<File::Statfs type=zfs, bsize=4096, blocks=900000/1000000/2000000, files=100000/200000>
|
||||
*
|
||||
* +blocks+ are numbers of available/free/total blocks.
|
||||
* +files+ are numbers of free/total files.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
statfs_inspect(VALUE self)
|
||||
{
|
||||
struct statfs*st = get_statfs(self);
|
||||
return rb_sprintf("#<%"PRIsVALUE" type=%d"
|
||||
#ifdef HAVE_STRUCT_STATFS_F_FSTYPENAME
|
||||
"(%s)"
|
||||
#endif
|
||||
", bsize=%ld"
|
||||
", blocks=%"PRI_LL_PREFIX"d/%"PRI_LL_PREFIX"d/%"PRI_LL_PREFIX"d"
|
||||
", files=%"PRI_LL_PREFIX"d/%"PRI_LL_PREFIX"d"
|
||||
">",
|
||||
rb_obj_class(self), st->f_type,
|
||||
#ifdef HAVE_STRUCT_STATFS_F_FSTYPENAME
|
||||
st->f_fstypename,
|
||||
#endif
|
||||
(long)st->f_bsize,
|
||||
st->f_bavail, st->f_bfree, st->f_blocks,
|
||||
st->f_ffree, st->f_files);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
VALUE rb_mFConst;
|
||||
|
@ -6149,5 +6186,6 @@ Init_File(void)
|
|||
rb_define_method(rb_cStatfs, "files", statfs_files, 0);
|
||||
rb_define_method(rb_cStatfs, "ffree", statfs_ffree, 0);
|
||||
rb_define_method(rb_cStatfs, "fstypename", statfs_fstypename, 0);
|
||||
rb_define_method(rb_cStatfs, "inspect", statfs_inspect, 0);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -400,6 +400,11 @@ class TestFile < Test::Unit::TestCase
|
|||
assert_kind_of String, st.fstypename
|
||||
rescue NotImplementedError
|
||||
end
|
||||
s = st.inspect
|
||||
assert_match /\A\#<File::Statfs\b.*>\z/, s
|
||||
assert_match /\bbsize=\d+\b/, s
|
||||
assert_match /\bblocks=(?:\d+[,>\/])+\b/, s
|
||||
assert_match /\bfiles=(?:\d+[,>\/])+\b/, s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue