Csaba Henk
2020-Feb-19 16:09 UTC
[Libguestfs] [PATCH] ruby: change value of 'readonly' drive toption to Boolean in doc/example/test
Seeing `g.add_drive_opt :readonly => 1` allows one to imply that ensuring writable access to drive should happen via `g.add_drive_opt :readonly => 0`. However, the passed option value gets passed down to C according to Ruby Boolean semantics, that is, any value apart from `false` and `nil` will be true (see RTEST in Ruby C API). So its more idiomatic and provides a better hint if we use `g.add_drive_opt :readonly => true` in Ruby samples. --- ruby/examples/guestfs-ruby.pod | 2 +- ruby/examples/inspect_vm.rb | 2 +- ruby/t/tc_070_optargs.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ruby/examples/guestfs-ruby.pod b/ruby/examples/guestfs-ruby.pod index bd8bb3108..cb9bfd0e7 100644 --- a/ruby/examples/guestfs-ruby.pod +++ b/ruby/examples/guestfs-ruby.pod @@ -7,7 +7,7 @@ guestfs-ruby - How to use libguestfs from Ruby require 'guestfs' g = Guestfs::Guestfs.new() g.add_drive_opts("disk.img", - :readonly => 1, :format => "raw") + :readonly => true, :format => "raw") g.launch() =head1 DESCRIPTION diff --git a/ruby/examples/inspect_vm.rb b/ruby/examples/inspect_vm.rb index abf227901..d444e01a2 100644 --- a/ruby/examples/inspect_vm.rb +++ b/ruby/examples/inspect_vm.rb @@ -11,7 +11,7 @@ disk = ARGV[0] g = Guestfs::Guestfs.new() # Attach the disk image read-only to libguestfs. -g.add_drive_opts(disk, :readonly => 1) +g.add_drive_opts(disk, :readonly => true) # Run the libguestfs back-end. g.launch() diff --git a/ruby/t/tc_070_optargs.rb b/ruby/t/tc_070_optargs.rb index 987b52005..2029c435f 100644 --- a/ruby/t/tc_070_optargs.rb +++ b/ruby/t/tc_070_optargs.rb @@ -22,9 +22,9 @@ class Test070Optargs < MiniTest::Unit::TestCase g = Guestfs::Guestfs.new() g.add_drive("/dev/null", {}) - g.add_drive("/dev/null", :readonly => 1) - g.add_drive("/dev/null", :readonly => 1, :iface => "virtio") + g.add_drive("/dev/null", :readonly => true) + g.add_drive("/dev/null", :readonly => true, :iface => "virtio") g.add_drive("/dev/null", - :readonly => 1, :iface => "virtio", :format => "raw") + :readonly => true, :iface => "virtio", :format => "raw") end end -- 2.25.1
Richard W.M. Jones
2020-Feb-19 18:27 UTC
Re: [Libguestfs] [PATCH] ruby: change value of 'readonly' drive toption to Boolean in doc/example/test
Thanks - I pushed this one as well. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html