Sha256: 606633c9e4e85bc9e7d9be08caee78169e486dad6ba5a7d8325464270130a048

Contents?: true

Size: 846 Bytes

Versions: 25

Compression:

Stored size: 846 Bytes

Contents

module Sys

  #
  # Get an array of mounted filesystems (as fancy objects)
  #
  def self.mounts
    if linux?
      IO.popen(["findmnt", "--raw"]) { |io| io.drop(1).map { |line| Mount.new line } }
    else
      raise NotImplementedError.new("I dunno, how do you find mounts on #{os}?")
    end
  end


  class Mount
    attr_accessor :dev, :type, :options

    def initialize(line)
      @path, @dev, @type, @options = line.strip.split(' ')
      @options = @options.split(",")
    end

    def system?
      (path =~ %r{^/(sys|dev|proc|run/user|tmp)}) or dev == "systemd-1"
    end

    def inspect
      "#{type}: #{path} (#{dev})"
    end

    def to_s
      "#{path} (#{dev})"
    end

    def path
      # Unescape findmnt's hex codes
      Path.new "#{eval %{"#{@path}"}}/"
    end

    def dirname
      path.dirs.last
    end
  end

end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
epitools-0.5.136 lib/epitools/sys/mounts.rb
epitools-0.5.134 lib/epitools/sys/mounts.rb
epitools-0.5.133 lib/epitools/sys/mounts.rb
epitools-0.5.131 lib/epitools/sys/mounts.rb
epitools-0.5.130 lib/epitools/sys/mounts.rb
epitools-0.5.129 lib/epitools/sys/mounts.rb
epitools-0.5.128 lib/epitools/sys/mounts.rb
epitools-0.5.126 lib/epitools/sys/mounts.rb
epitools-0.5.125 lib/epitools/sys/mounts.rb
epitools-0.5.124 lib/epitools/sys/mounts.rb
epitools-0.5.123 lib/epitools/sys/mounts.rb
epitools-0.5.122 lib/epitools/sys/mounts.rb
epitools-0.5.121 lib/epitools/sys/mounts.rb
epitools-0.5.119 lib/epitools/sys/mounts.rb
epitools-0.5.118 lib/epitools/sys/mounts.rb
epitools-0.5.116 lib/epitools/sys/mounts.rb
epitools-0.5.115 lib/epitools/sys/mounts.rb
epitools-0.5.114 lib/epitools/sys/mounts.rb
epitools-0.5.113 lib/epitools/sys/mounts.rb
epitools-0.5.112 lib/epitools/sys/mounts.rb