Class: Vmit::VFS::ISO

Inherits:
Handler show all
Defined in:
lib/vmit/vfs.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Handler

from

Constructor Details

#initialize(location, *rest) ⇒ ISO

Creates a ISO handler for iso

Parameters:

  • iso (URI, String)

    ISO file

Raises:

  • (ArgumentError)


139
140
141
142
143
144
145
146
# File 'lib/vmit/vfs.rb', line 139

def initialize(location, *rest)
  raise ArgumentError.new(location) unless self.class.accept?(location)
  path = case location
    when ::URI then location.path
    else ::URI.parse(location).path
  end
  @iso_file = path
end

Instance Attribute Details

#iso_fileObject (readonly)

Returns the value of attribute iso_file.



113
114
115
# File 'lib/vmit/vfs.rb', line 113

def iso_file
  @iso_file
end

Class Method Details

.accept?(location) ⇒ Boolean

Whether this handler accepts the given location.

Parameters:

  • uri (URI, String)

    location

Returns:

  • (Boolean)


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/vmit/vfs.rb', line 119

def self.accept?(location)
  uri = case location
    when ::URI then location
    else ::URI.parse(location)
  end

  # either an iso:// url or a local file
  unless (uri.scheme == 'iso' || uri.scheme.nil?)
    return false
  end
  return false unless File.exist?(uri.path)
  File.open(uri.path) do |f|
    f.seek(0x8001)
    return true if f.read(5) == 'CD001'
  end
  false
end

.open(location) ⇒ Object

Takes a iso URI on the form iso:///path/tothe/file.iso?path=/file/to/get

Parameters:

  • uri (URI, String)

    ISO file and path as query string



152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/vmit/vfs.rb', line 152

def self.open(location)
  uri = case location
    when ::URI then location
    else ::URI.parse(location)
  end
  handler = self.new(uri)
  query = Hash[*uri.query.split('&').map {|p| p.split('=')}.flatten]
  unless query.has_key?("path")
    raise ArgumentError.new("#{uri}: missing path in query string")
  end
  handler.open(query["path"])
end

Instance Method Details

#open(name, *rest) ⇒ Object

Takes a path relative to iso_file

Raises:

  • (Errno::ENOENT)

See Also:



167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/vmit/vfs.rb', line 167

def open(name, *rest)
  index = Cheetah.run('isoinfo', '-f', '-R', '-i', iso_file, :stdout => :capture)
  files = index.each_line.to_a.map(&:strip)
  raise Errno::ENOENT.new(name) if not files.include?(name)
  tmp = Tempfile.new('vmit-vfs-iso-')
  Cheetah.run('isoinfo', '-R', '-i', iso_file, '-x', name, :stdout => tmp)
  tmp.close
  tmp.open
  if block_given?
    yield tmp
  end
  tmp
end