Skip to content

Commit

Permalink
Improve UserRoutines#DeleteHome Perl subroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Feb 5, 2019
1 parent db70345 commit 602a6f8
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions src/modules/UsersRoutines.pm
Expand Up @@ -294,37 +294,39 @@ sub MoveHome {
BEGIN { $TYPEINFO{DeleteHome} = ["function", "boolean", "string"];}
sub DeleteHome {

my $self = shift;
my $home = $_[0];
my $self = shift;
my $home = $_[0];
my %stat = %{ SCR->Read( ".target.stat", $home ) };

my %stat = %{SCR->Read (".target.stat", $home)};
if (!%stat || !($stat{"isdir"} || 0)) {
y2warning("home directory does not exist or is not a directory: no rm");
return 1;
if ( !%stat || !( $stat{"isdir"} || 0 ) ) {
y2warning("home directory '$home' does not exist or is not a directory: no rm");
return 1;
}

if ( btrfs_subvolume($home) ) {
my $cmd = sprintf("$btrfs subvolume delete -C '%s'", String->Quote($home));
my %cmd_output = %{ SCR->Execute( ".target.bash_output", $cmd ) };
my $cmd;
my $type;

if ( $cmd_output{"exit"} ne 0 ) {
y2error( "Error calling $cmd: ", $cmd_output{"stderr"} || "" );
if ( btrfs_subvolume($home) ) {
$cmd = sprintf( "$btrfs subvolume delete -C '%s'", String->Quote($home) );
$type = "btrfs subvolume";
}
else {
$cmd = sprintf( "/usr/bin/rm -rf '%s'", String->Quote($home) );
$type = "directory";
}

return 0;
}
my %cmd_output = %{ SCR->Execute( ".target.bash_output", $cmd ) };
my $stderr = $cmd_output{"stderr"} || "";

y2milestone("The btrfs subvolume '$home' was succesfully deleted");
if ( $stderr ne "" ) {
y2error( "Error calling '$cmd': $stderr" );

return 1;
}
my $command = "/usr/bin/rm -rf '".String->Quote($home)."'";
my %out = %{SCR->Execute (".target.bash_output", $command)};
if (($out{"stderr"} || "") ne "") {
y2error ("error calling $command: ", $out{"stderr"} || "");
return 0;
return 0;
}
y2milestone ("The directory $home was succesfully deleted");
y2usernote ("Home directory removed: '$command'");

y2milestone("The $type '$home' was succesfully deleted");
y2usernote("Home $type removed: '$cmd'");

return 1;
}

Expand Down

0 comments on commit 602a6f8

Please sign in to comment.