Skip to content

Commit

Permalink
Improve btrfs_subvol_name_for
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Nov 3, 2016
1 parent 32a1399 commit a8d9f09
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/modules/FileSystems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,7 @@ def default_subvol_from_target
parts = Storage.GetTargetMap.map { |_k, d| d.fetch("partitions") }.flatten.compact
btrfs_parts = parts.select { |p| p["used_fs"] == :btrfs }
default_subvol_names = btrfs_parts.reduce({}) do |memo, part|
memo[part["mount"]] = btrfs_subvol_name_for(part) unless part["mount"].nil?
memo[part["mount"]] = btrfs_subvol_name_for(part["mount"]) unless part["mount"].nil?
memo
end

Expand Down Expand Up @@ -2101,8 +2101,14 @@ def read_default_subvol_from_target

protected

def btrfs_subvol_name_for(partition)
ret = Yast::Execute.on_target("btrfs", "subvol", "list", partition["mount"], stdout: :capture)
# Find the default subvolume name
#
# Only "" and "@" are supported.
#
# @param mount [String] Mount point.
# @return ["@", ""] Default subvolume name for the given mount point.
def btrfs_subvol_name_for(mount)
ret = Yast::Execute.on_target("btrfs", "subvol", "list", mount, stdout: :capture)
ret.split("\n").first =~ /.+ @\z/ ? "@" : ""
end

Expand Down

0 comments on commit a8d9f09

Please sign in to comment.