ruby-changes:33614
From: nobu <ko1@a...>
Date: Thu, 24 Apr 2014 09:35:40 +0900 (JST)
Subject: [ruby-changes:33614] nobu:r45695 (trunk): file.c: statfs_inspect
nobu 2014-04-24 09:35:34 +0900 (Thu, 24 Apr 2014) New Revision: 45695 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45695 Log: file.c: statfs_inspect * file.c (statfs_inspect): add File::Statfs#inspect method. Modified files: trunk/file.c trunk/test/ruby/test_file.rb Index: test/ruby/test_file.rb =================================================================== --- test/ruby/test_file.rb (revision 45694) +++ test/ruby/test_file.rb (revision 45695) @@ -400,6 +400,11 @@ class TestFile < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file.rb#L400 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 Index: file.c =================================================================== --- file.c (revision 45694) +++ file.c (revision 45695) @@ -5550,6 +5550,43 @@ statfs_fstypename(VALUE self) https://github.com/ruby/ruby/blob/trunk/file.c#L5550 #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) https://github.com/ruby/ruby/blob/trunk/file.c#L6186 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 } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/