Sha256: 6e7a02de0f644dc3fa70c5ffef62fd4557403321a16d112803bf3a0f62374e3e
Contents?: true
Size: 1.32 KB
Versions: 1
Compression:
Stored size: 1.32 KB
Contents
module Snapsync module Btrfs class Error < RuntimeError attr_reader :error_lines def initialize(error_lines = Array.new) @error_lines = error_lines end def pretty_print(pp) pp.text message pp.nest(2) do error_lines.each do |l| pp.breakable pp.text l.chomp end end end end def self.popen(*args, mode: 'r', raise_on_error: true, **options) err_r, err_w = IO.pipe result = IO.popen(['btrfs', *args, err: err_w, **options], mode) do |io| err_w.close yield(io) end if $?.success? result elsif raise_on_error raise Error.new, "btrfs failed" end rescue Error => e prefix = args.join(" ") lines = err_r.readlines.map do |line| "#{prefix}: #{line.chomp}" end raise Error.new(e.error_lines + lines), e.message, e.backtrace ensure err_r.close end def self.run(*args, **options) popen(*args, **options) do |io| io.read end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
snapsync-0.2.0 | lib/snapsync/btrfs.rb |