Skip to content

Commit

Permalink
WIP: show the Btrfs subvolume checkbox when editing
Browse files Browse the repository at this point in the history
Disabled, only to show the current status.

PENDING TO VALIDATE
  • Loading branch information
dgdavid committed Feb 6, 2019
1 parent 4299a8e commit 9a181e8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/include/users/dialogs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -756,10 +756,6 @@ def EditUserDialog(what)
HBox(
HSpacing(),
Left(CheckBox(Id(:skel), _("E&mpty Home"), no_skel))
),
HBox(
HSpacing(),
Left(CheckBox(Id(:btrfs_subvolume), _("Btrfs subvolume"), btrfs_subvolume))
)
)

Expand Down Expand Up @@ -791,7 +787,14 @@ def EditUserDialog(what)
)
),
Top(
VBox(HBox(home_w, browse), new_user_term)
VBox(
HBox(home_w, browse),
new_user_term,
HBox(
HSpacing(),
Left(CheckBox(Id(:btrfs_subvolume), _("Btrfs subvolume"), btrfs_subvolume))
),
)
),
additional_data,
Top(edit_shell),
Expand Down Expand Up @@ -1762,8 +1765,6 @@ def EditUserDialog(what)
UI.ReplaceWidget(:tabContents, get_details_term.call)
Wizard.SetHelpText(EditUserDetailsDialogHelp(user_type, what))

UI.ChangeWidget(Id(:btrfs_subvolume), :Enabled, btrfs_available?)

if do_not_edit
UI.ChangeWidget(Id(:uid), :Enabled, false)
UI.ChangeWidget(Id(:home), :Enabled, false)
Expand All @@ -1786,6 +1787,8 @@ def EditUserDialog(what)
UI.ChangeWidget(Id(:mode), :InputMaxLength, 3)
end
UI.ChangeWidget(Id(:shell), :Value, shell)
UI.ChangeWidget(Id(:btrfs_subvolume), :Enabled, what == "add_user" && btrfs_available?)
UI.ChangeWidget(Id(:btrfs_subvolume), :Value, what == "edit_user" && btrfs_subvolume?(home))

current = ret
end
Expand Down Expand Up @@ -1906,6 +1909,17 @@ def btrfs_available?
available_filesystems.include?("btrfs")
end

# Whether given path is a Btrfs subvolume
#
# @param [String, Pathname] path
#
# @return [Boolean] true when is a Btrfs subvolume; false otherwise
def btrfs_subvolume?(path)
return false if path.to_s.empty?

!Yast::Execute.locally!.stdout("/usr/sbin/btrfs", "subvolume", "show", path).empty?
end

# Dialog for adding/editing group
# @param [String] what "add_group" or "edit_group"
# @return [Symbol] for wizard sequencer
Expand Down
35 changes: 35 additions & 0 deletions test/dialogs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,41 @@ def initialize
end
end

describe "#btrfs_subvolume?" do
let(:local_execution) { double }
let(:subvolume_info) { "" }
let(:path) { "/fake/path/to/user/home" }

before do
allow(Yast::Execute).to receive(:locally!).and_return(local_execution)
allow(local_execution).to receive(:stdout)
.with("/usr/sbin/btrfs", "subvolume", "show", path)
.and_return(subvolume_info)
end

context "when path is empty" do
let(:path) { Pathname.new("") }

it "returns false" do
expect(subject.btrfs_subvolume?(path)).to eq(false)
end
end

context "when given path is a Btrfs subvolume" do
let(:subvolume_info) { "@/fake/path/to/user/home\n..." }

it "returns true" do
expect(subject.btrfs_subvolume?(path)).to eq(true)
end
end

context "when given path is not a Btrfs subvolume" do
it "returns false" do
expect(subject.btrfs_subvolume?(path)).to eq(false)
end
end
end

describe "#ask_chown_home" do
before(:each) do
expect(Yast::UI).to receive(:OpenDialog)
Expand Down

0 comments on commit 9a181e8

Please sign in to comment.