Class: MountInspector
- Inherits:
-
Object
- Object
- MountInspector
- Defined in:
- lib/ec2-consistent-backup.rb
Instance Method Summary collapse
-
#initialize(file = '/etc/mtab') ⇒ MountInspector
constructor
A new instance of MountInspector.
- #where_is_mounted(device) ⇒ Object
- #which_device(folder) ⇒ Object
Constructor Details
#initialize(file = '/etc/mtab') ⇒ MountInspector
Returns a new instance of MountInspector.
66 67 68 69 70 71 72 73 |
# File 'lib/ec2-consistent-backup.rb', line 66 def initialize(file = '/etc/mtab') @dev_to_fs = {} @fs_to_dev = {} File.open(file).read.split(/\n/).map {|line| line.split(/ /)[0..1]}.each do |m| @dev_to_fs[m[0]] = m[1] if m[0] != "none" @fs_to_dev[m[1]] = m[0] if m[1] != "none" end end |
Instance Method Details
#where_is_mounted(device) ⇒ Object
74 75 76 77 |
# File 'lib/ec2-consistent-backup.rb', line 74 def where_is_mounted(device) return @dev_to_fs[device] if @dev_to_fs.has_key?(device) raise NotMountedException.new(device) end |
#which_device(folder) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ec2-consistent-backup.rb', line 78 def which_device(folder) # Level 0 optimisation+ Handle "/" folder return @fs_to_dev[folder] if @fs_to_dev.has_key?(folder) components = folder.split(/\//) components.size.downto(0).each do |sz| current_folder = components[0..sz-1].join("/") current_folder = "/" if current_folder == "" return @fs_to_dev[current_folder] if @fs_to_dev.has_key?(current_folder) end raise NotMountedException.new(folder) end |