Skip to content

Commit

Permalink
Fix regression in 262 (rsnapshot#283)
Browse files Browse the repository at this point in the history
* Remove unused sub add_slashdot_if_root().
* Revert changes from rsnapshot#262 (rm -rf failure case on abnormal termination). Add replacement fix.
* Rm redundant backup dest mangling in validate_config_file().
  • Loading branch information
sgpinkus authored Jun 8, 2021
1 parent 7e5919b commit 2a2b302
Showing 1 changed file with 13 additions and 48 deletions.
61 changes: 13 additions & 48 deletions rsnapshot-program.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ sub parse_config_file {
# remember src/dest
my %hash;
$hash{'src'} = $src;
$hash{'dest'} = $dest;
$hash{'dest'} = normalize_dest_file_path_part($dest);
if (defined($opts_ref)) {
$hash{'opts'} = $opts_ref;
}
Expand Down Expand Up @@ -1173,7 +1173,7 @@ sub parse_config_file {
}

$hash{'script'} = $full_script;
$hash{'dest'} = $dest;
$hash{'dest'} = normalize_dest_file_path_part($dest);

$line_syntax_ok = 1;

Expand Down Expand Up @@ -1677,21 +1677,14 @@ sub validate_config_file {
# skip for backup_exec since it uses no destination
next if (defined($$bp_ref{'cmd'}));

my $tmp_dest_path = $$bp_ref{'dest'};

# normalize multiple slashes, and strip trailing slash
# FIXME: Decide whether to allow an empty destination path, and reject or handle such paths accordingly.
$tmp_dest_path =~ s/\/+/\//g;
$tmp_dest_path =~ s/\/$//;

# backup
if (defined($$bp_ref{'src'})) {
push(@backup_dest, $tmp_dest_path);
push(@backup_dest, $$bp_ref{'dest'});

# backup_script
}
elsif (defined($$bp_ref{'script'})) {
push(@backup_script_dest, $tmp_dest_path);
push(@backup_script_dest, $$bp_ref{'dest'});

}

Expand Down Expand Up @@ -3051,16 +3044,15 @@ sub remove_trailing_slash {
}

# accepts string
# returns /. if passed /, returns input otherwise
# this is to work around a bug in some versions of rsync
sub add_slashdot_if_root {
my $str = shift(@_);

if ($str eq '/') {
return '/.';
}

return ($str);
# partially normalizes file path intended to be prefixed with some other path (such as backup dest)
# does not handle symlinks or '..'
sub normalize_dest_file_path_part {
my $str = shift(@_);
# it's not a trailing slash if it's the root filesystem
if ($str eq '/') { return ($str); }
$str =~ s/^\.\/|\/.\/|\.$/\//g;
$str =~ s/\/+/\//g;
return ($str);
}

# accepts the interval (cmd) to run against
Expand Down Expand Up @@ -5252,19 +5244,6 @@ sub rm_rf {
# make sure we were passed an argument
if (!defined($path)) { return (0); }

# added by Matthew Jurgens as part of the fix for rm -rf failing when the path contains ./
# make sure $path does not contain ./ at the end since this makes rm -rf fail
# however the side effect of doing this is that we also remove the directory so we will have to create it later
# we could have added a * at the end so we had something like rm -rf PATH/* but probably safer not to use the *
$path=~s{/\./?$}{};
# in order to recreate the directory we will want to take a look at it before we remove it
my $st = lstat("$path");
if (!defined($st)) {
print_err("Could not lstat(\"$path\")", 2);
return(0);
}
# end addition

# extra bonus safety feature!
# confirm that whatever we're deleting must be inside the snapshot_root
if (index($path, $config_vars{'snapshot_root'}) != 0) {
Expand All @@ -5285,20 +5264,6 @@ sub rm_rf {
$result = rmtree("$path", 0, 0);
}

# added by Matthew Jurgens as part of the fix for rm -rf failing when the path contains ./
# make sure the directory is still in place
# if you cannot create this directory and this rm is part of a rollback which uses cp -al, then the cp -al will fail shortly after
# MKDIR DEST (AND SET MODE)
if (defined($st)) {
# create the directory
$result = mkdir("$path", $st->mode);
if ( ! $result ) {
print_err("Warning! Could not mkdir(\"$path\", $st->mode);", 2);
return(0);
}
}
# end addition

return ($result);
}

Expand Down

0 comments on commit 2a2b302

Please sign in to comment.