fstab 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,10 +20,10 @@ Adding a new entry to fstab:
20
20
  # Asuming /dev/sda1 has a valid FS
21
21
  # The library will use the FS UUID automatically by default even if the block device path
22
22
  # was used as an argument. This is usually safer.
23
- fstab.add_device '/dev/sda1', '/mnt', 'ext4', 'discard,errors=remount-ro', 0, 1
23
+ fstab.add_fs '/dev/sda1', '/mnt', 'ext4', 'discard,errors=remount-ro', 0, 1
24
24
 
25
25
  # You can use filesystem UUID also
26
- fstab.add_device '15baeabd-b419-4a69-a306-bc550dc8355f', '/mnt', 'ext4', 'discard,errors=remount-ro', 0, 1
26
+ fstab.add_fs '15baeabd-b419-4a69-a306-bc550dc8355f', '/mnt', 'ext4', 'discard,errors=remount-ro', 0, 1
27
27
 
28
28
  # List fstab entries
29
29
  fstab.entries.each do |key, val|
data/lib/fstab.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  class Fstab
2
2
 
3
- VERSION = "0.1"
3
+ VERSION = "0.1.1"
4
4
 
5
5
  # if safe_mode true, non existing devices won't be added to fstab.
6
6
  # Adding a non existing device to fstab will raise an exception.
@@ -77,6 +77,7 @@ class Fstab
77
77
  f.puts @contents
78
78
  f.puts format_entry(dev, opts)
79
79
  end
80
+ reload
80
81
  end
81
82
 
82
83
  def add_fs(dev, mpoint, type, opts, dump = 0, pass = 0)
@@ -94,8 +95,11 @@ class Fstab
94
95
  @lcount
95
96
  end
96
97
 
97
- def parse(reload = true)
98
- @contents = File.read @file if reload
98
+ def reload
99
+ @contents = File.read @file
100
+ end
101
+
102
+ def parse
99
103
  raise Exception.new("/sbin/blkid not found") unless File.exist?('/sbin/blkid')
100
104
  fslist = {}
101
105
  ucount = 0
@@ -122,7 +126,7 @@ class Fstab
122
126
  # by UUID
123
127
  uuid = fs.split("=").last.strip.chomp
124
128
  pdev = "/dev/" + File.readlink("/dev/disk/by-uuid/#{uuid}").split("/").last rescue "unknown_#{ucount}"
125
- label = Fstab.get_label pdev
129
+ label = Fstab.get_label pdev rescue nil
126
130
  elsif l =~ /^\s*\/dev/
127
131
  # by dev path
128
132
  pdev = fs
@@ -185,6 +189,7 @@ class Fstab
185
189
  f.puts format_entry(k, v)
186
190
  end
187
191
  end
192
+ reload
188
193
  true
189
194
  end
190
195
 
@@ -222,7 +227,7 @@ class Fstab
222
227
  # All the attributes except dev may be nil at any given time since
223
228
  # device may not have a valid filesystem or label.
224
229
  def self.get_blkdev_fs_attrs(dev)
225
- raise ArgumentError.new("Invalid device path") unless File.blockdev?(dev)
230
+ raise ArgumentError.new("Invalid device path #{dev}") unless File.blockdev?(dev)
226
231
  blkid = `/sbin/blkid #{dev}`
227
232
  attrs = {}
228
233
  attrs[:uuid] = blkid.match(/UUID="(.*?)"/)[1] rescue nil
@@ -105,6 +105,7 @@ describe Fstab do
105
105
  devs.first.last[:invalid].should == true
106
106
  f.puts 'weird_entry foo bar'
107
107
  f.flush
108
+ fstab.reload
108
109
  devs = fstab.parse
109
110
  devs.count.should == 2
110
111
  devs.each do |k,v|
@@ -112,6 +113,15 @@ describe Fstab do
112
113
  end
113
114
  end
114
115
  end
116
+
117
+ it "should parse valid UUID entries" do
118
+ pdev, uuid, label, type = get_first_blkid
119
+ File.open @fake_fstab, 'w+' do |f|
120
+ f.puts "UUID=74bc785f-1024-4779-80a1-7a1e0619ad26 /srv/node/74bc785f-1024-4779-80a1-7a1e0619ad26 xfs noatime,nodiratime,nobarrier,logbufs=8 0 0"
121
+ end
122
+ fstab = Fstab.new @fake_fstab
123
+ fstab.parse.count.should == 1
124
+ end
115
125
  end
116
126
 
117
127
  describe "#add_fs" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fstab
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-08 00:00:00.000000000 Z
12
+ date: 2012-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -90,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  segments:
92
92
  - 0
93
- hash: 866801040596206319
93
+ hash: -1231055836827073287
94
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements: