lib/external/base.rb in external-0.3.0 vs lib/external/base.rb in external-0.3.1

- old
+ new

@@ -22,12 +22,17 @@ # # Nil may be provided as an fd, in which case a Tempfile will be # used (in which case mode gets ignored as Tempfiles always open # in 'r+' mode). def open(path=nil, mode="rb", *argv) - path = File.open(path, mode) unless path == nil - base = new(path, *argv) - + begin + io = path == nil ? nil : File.open(path, mode) + base = new(io, *argv) + rescue(Errno::ENOENT) + io.close if io + raise + end + if block_given? begin yield(base) ensure base.close \ No newline at end of file