Skip to content

Commit

Permalink
Revert "WIP: do not clean home if it's being reused"
Browse files Browse the repository at this point in the history
This reverts commit eccc84f.
  • Loading branch information
joseivanlopez committed Sep 24, 2021
1 parent ade4cbd commit 94c84a7
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 33 deletions.
12 changes: 0 additions & 12 deletions src/lib/y2users/commit_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ class CommitConfig
# @return [Boolean]
attr_writer :adapt_home_ownership

# Whether this user will reuse an existing directory/subvolume.
#
# Useful to avoid cleaning an existing home when creating a user with #empty_home
#
# @return [Boolean]
attr_writer :reuse_existing_home

# @return [Boolean]
def empty_home?
!!@empty_home
Expand All @@ -66,10 +59,5 @@ def move_home?
def adapt_home_ownership?
!!@adapt_home_ownership
end

# @return [Boolean]
def reuse_existing_home?
!!@reuse_existing_home
end
end
end
7 changes: 2 additions & 5 deletions src/lib/y2users/linux/users_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ def create_user(user, issues)
# @param issues [Y2Issues::List] a collection for adding an issue if something goes wrong
def try_create_user(user, issues)
Yast::Execute.on_target!(USERADD, *useradd_options(user))
clear_home(user, issues)
chown_home(user, issues)
clear_home(user, issues) if commit_config(user).empty_home?
chown_home(user, issues) if commit_config(user).adapt_home_ownership?
rescue Cheetah::ExecutionFailed => e
raise(e) unless e.status.exitstatus == USERADD_E_HOMEDIR

Expand All @@ -240,8 +240,6 @@ def try_create_user(user, issues)
# @param issues [Y2Issues::List] new issues can be added
def clear_home(user, issues)
return unless exist_user_home?(user)
return if commit_config(user).reuse_existing_home?
return unless commit_config(user).empty_home?

Yast::Execute.on_target!(FIND, user.home.path, "-mindepth", "1", "-delete")
rescue Cheetah::ExecutionFailed => e
Expand All @@ -259,7 +257,6 @@ def clear_home(user, issues)
# @param issues [Y2Issues::List] new issues can be added
def chown_home(user, issues)
return unless exist_user_home?(user)
return unless commit_config(user).adapt_home_ownership?

owner = user.name
owner << ":#{user.gid}" if user.gid
Expand Down
16 changes: 0 additions & 16 deletions test/lib/y2users/linux/writer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -765,22 +765,6 @@
end
end

context "and home is being reused" do
let(:commit_config) do
Y2Users::CommitConfig.new.tap do |config|
config.username = user.name
config.empty_home = true
config.reuse_existing_home = true
end
end

it "does not remove home content" do
expect(Yast::Execute).to_not receive(:on_target!).with(/find/, any_args)

writer.write
end
end

context "and home has been created" do
let(:commit_config) do
Y2Users::CommitConfig.new.tap do |config|
Expand Down

0 comments on commit 94c84a7

Please sign in to comment.