-
-
Save nilium/8566489480d673fa654d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Should succeed, has TYPE=".." | |
GOOD_BLKID = %{/dev/vg/root: LABEL="/" UUID="6a1e5f4f-37c9-4809-969a-89cf6725cbbd" TYPE="ext4"} | |
# No TYPE="ext[34]", shouldn't succeed | |
BAD_BLKID = %{/dev/vg/root: LABEL="/" UUID="6a1e5f4f-37c9-4809-969a-89cf6725cbbd" TYPE="reiserfs"} | |
TYPE_REGEX = /TYPE=\"(\S+)\"/ | |
MATCH_EXT34 = /ext[34]/ | |
# With the good blkid, this should return non-nil if it's not faulty | |
r = TYPE_REGEX.match(GOOD_BLKID) { |m| m =~ MATCH_EXT34 } # => nil | |
puts r.inspect | |
# With the bad blkid, this should return nil if it's not faulty | |
r = TYPE_REGEX.match(BAD_BLKID) { |m| m =~ MATCH_EXT34 } # => nil | |
puts r.inspect | |
# In reality, the above will both fail in a normal Ruby environment where =~ | |
# returns nil by default, as MatchData (m.class in the above block) does not | |
# implement a method for it. | |
# Both of these should work as expected, rather. | |
r = TYPE_REGEX.match(GOOD_BLKID) { |m| m[1] =~ MATCH_EXT34 } # => 0 | |
puts r.inspect | |
r = TYPE_REGEX.match(BAD_BLKID) { |m| m[1] =~ MATCH_EXT34 } # => nil | |
puts r.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment