Skip to content

Commit

Permalink
Show the "Btrfs subvolume" option when creating a user
Browse files Browse the repository at this point in the history
Which will allow to create the user home as a btrfs subvolume instead as
a plain dir.
  • Loading branch information
dgdavid committed Feb 4, 2019
1 parent bfb448d commit b5aa03a
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/include/users/dialogs.rb
Expand Up @@ -27,6 +27,7 @@
#
# $Id$

require "pathname"
require "shellwords"

require "users/ssh_public_key"
Expand Down Expand Up @@ -64,6 +65,21 @@ def initialize_users_dialogs(include_target)
@default_pw = "******"
end

def btrfs_path?(path)
dirname = Pathname.new(path).dirname
fstype = Yast::Execute.locally!.stdout("/usr/bin/stat", "-f", "--format", "%T", dirname).chomp

fstype == "btrfs"
end

def redraw_btrfs_subvolume_option
home_dir = UI.QueryWidget(Id(:home), :Value)
valid_btrfs_path = btrfs_path?(home_dir)

UI.ChangeWidget(Id(:btrfs_subvolume), :Enabled, valid_btrfs_path)
UI.ChangeWidget(Id(:btrfs_subvolume), :Value, false) unless valid_btrfs_path
end

# Uppercase letters were used in username! (see bug #26409)
# In these popups, ask user what to do.
def AskForUppercasePopup(username)
Expand Down Expand Up @@ -389,6 +405,7 @@ def EditUserDialog(what)
create_home = Ops.get_boolean(user, "create_home", true)
chown_home = Ops.get_boolean(user, "chown_home", true)
no_skel = Ops.get_boolean(user, "no_skeleton", false)
btrfs_subvolume = Ops.get_boolean(user, "btrfs_subvolume", false)
do_not_edit = user_type == "nis"

complex_layout = installation && Users.StartDialog("user_add")
Expand Down Expand Up @@ -462,6 +479,7 @@ def EditUserDialog(what)

chown_home = Ops.get_boolean(user, "chown_home", chown_home)
no_skel = Ops.get_boolean(user, "no_skeleton", no_skel)
btrfs_subvolume = Ops.get_boolean(user, "btrfs_subvolume", btrfs_subvolume)
groups = Ops.get_map(user, "grouplist", {})
do_not_edit = user_type == "nis"

Expand Down Expand Up @@ -724,7 +742,7 @@ def EditUserDialog(what)

home_w = VBox(
# textentry label
InputField(Id(:home), Opt(:hstretch), _("&Home Directory"), home),
InputField(Id(:home), Opt(:hstretch, :notify), _("&Home Directory"), home),
action != "edited" ?
Empty() :
HBox(
Expand Down Expand Up @@ -753,6 +771,10 @@ 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 @@ -1011,6 +1033,12 @@ def EditUserDialog(what)
error = ""

ret = Convert.to_symbol(UI.UserInput) if current != nil

if ret == :home
redraw_btrfs_subvolume_option
next
end

if (ret == :abort || ret == :cancel) && ReallyAbort() != :abort
ret = :notnext
next
Expand Down Expand Up @@ -1342,6 +1370,7 @@ def EditUserDialog(what)
)
end
UI.ChangeWidget(Id(:home), :Value, dir)
redraw_btrfs_subvolume_option
end
end

Expand All @@ -1355,6 +1384,7 @@ def EditUserDialog(what)
new_home = Convert.to_string(UI.QueryWidget(Id(:home), :Value))

if what == "add_user"
btrfs_subvolume = UI.QueryWidget(Id(:btrfs_subvolume), :Enabled) && UI.QueryWidget(Id(:btrfs_subvolume), :Value)
no_skel = Convert.to_boolean(UI.QueryWidget(Id(:skel), :Value))
mode = Convert.to_string(UI.QueryWidget(Id(:mode), :Value))
end
Expand Down Expand Up @@ -1539,6 +1569,7 @@ def EditUserDialog(what)
Ops.set(user, "addit_data", addit_data)
Ops.set(user, "no_skeleton", no_skel)
Ops.set(user, "home_mode", mode)
Ops.set(user, "btrfs_subvolume", btrfs_subvolume)
end

if current == :passwordsettings && (ret == :next || tab)
Expand Down

0 comments on commit b5aa03a

Please sign in to comment.