Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include names in the shadowed subvolumes popup (bsc#928641)
- Loading branch information
Showing
5 changed files
with
104 additions
and
23 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright (c) 2016 Novell, Inc. | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE. | ||
# | ||
# To contact SUSE about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "yast" | ||
Yast.import "FileSystems" | ||
|
||
module Yast | ||
class ShadowedVolList | ||
include Enumerable | ||
include Yast::Logger | ||
|
||
attr_reader :partition, :mntpoint | ||
|
||
def initialize(partition: nil, mntpoint: nil) | ||
raise ArgumentError unless partition && mntpoint | ||
@partition = partition | ||
@mntpoint = mntpoint | ||
@volumes = selected_volumes | ||
end | ||
|
||
def each(&block) | ||
@volumes.each(&block) | ||
end | ||
|
||
protected | ||
|
||
def selected_volumes | ||
subvols = partition.fetch("subvol", []) | ||
log.debug "Full list of subvolumes: #{subvols}" | ||
subvols.select do |subvol| | ||
name = full_name(subvol) | ||
shadowed?(name) | ||
end | ||
end | ||
|
||
def shadowed?(name) | ||
(name == mntpoint) || (name.start_with?(mntpoint) && name[mntpoint.size] == "/") | ||
end | ||
|
||
def full_name(subvol) | ||
if FileSystems.default_subvol.empty? | ||
"/" + subvol.fetch("name") | ||
else | ||
subvol.fetch("name")[FileSystems.default_subvol.size..-1] | ||
end | ||
end | ||
end | ||
end |
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