diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2009-07-01 20:56:58 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2009-07-02 10:11:55 +0100 |
commit | 5186251f8f681f2ebb028423bb49a748861fd11e (patch) | |
tree | b95ea92a8ed1b9443dc04aaf7cdacc8191291bc0 /ruby | |
parent | f20854ec61eef1aea313920f0cf193a78c1a9219 (diff) | |
download | libguestfs-5186251f8f681f2ebb028423bb49a748861fd11e.tar.gz libguestfs-5186251f8f681f2ebb028423bb49a748861fd11e.tar.xz libguestfs-5186251f8f681f2ebb028423bb49a748861fd11e.zip |
Add 'readdir' call.
This adds a readdir call (mostly intended for programs). The
return value is a list of guestfs_dirent structures.
This adds the new types 'struct guestfs_dirent' and
'struct guestfs_dirent_list', along with all the code to
return these in the different language bindings.
Also includes additional tests for OCaml and Perl bindings
to test this.
Diffstat (limited to 'ruby')
-rw-r--r-- | ruby/ext/guestfs/_guestfs.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/ruby/ext/guestfs/_guestfs.c b/ruby/ext/guestfs/_guestfs.c index 606e9a2a..38776b6b 100644 --- a/ruby/ext/guestfs/_guestfs.c +++ b/ruby/ext/guestfs/_guestfs.c @@ -4865,6 +4865,38 @@ static VALUE ruby_guestfs_umask (VALUE gv, VALUE maskv) return INT2NUM (r); } +static VALUE ruby_guestfs_readdir (VALUE gv, VALUE dirv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "readdir"); + + Check_Type (dirv, T_STRING); + const char *dir = StringValueCStr (dirv); + if (!dir) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "dir", "readdir"); + + struct guestfs_dirent_list *r; + + r = guestfs_readdir (g, dir); + if (r == NULL) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + VALUE rv = rb_ary_new2 (r->len); + int i; + for (i = 0; i < r->len; ++i) { + VALUE hv = rb_hash_new (); + rb_hash_aset (rv, rb_str_new2 ("ino"), ULL2NUM (r->val[i].ino)); + rb_hash_aset (rv, rb_str_new2 ("ftyp"), ULL2NUM (r->val[i].ftyp)); + rb_hash_aset (rv, rb_str_new2 ("name"), rb_str_new2 (r->val[i].name)); + rb_ary_push (rv, hv); + } + guestfs_free_dirent_list (r); + return rv; +} + /* Initialize the module. */ void Init__guestfs () { @@ -5257,4 +5289,6 @@ void Init__guestfs () ruby_guestfs_mknod_c, 4); rb_define_method (c_guestfs, "umask", ruby_guestfs_umask, 1); + rb_define_method (c_guestfs, "readdir", + ruby_guestfs_readdir, 1); } |