Skip to content

Commit

Permalink
Added path-escaping for working with archives containing spaces and s…
Browse files Browse the repository at this point in the history
…pecial characters

- BNC #776078
  • Loading branch information
kobliha committed Nov 2, 2012
1 parent 9a24195 commit ae90295
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Backup.ycp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ global define boolean PostBackup() ``{
*/

global define string get_archive_script_parameters(string file_list, string file_comment) ``{
string archive_options = " --verbose --files-info " + file_list + " --comment-file " + file_comment;
string archive_options = " --verbose --files-info '" + String::Quote(file_list) + "' --comment-file '" + String::Quote(file_comment) + "'";

if (size(complete_backup) > 0)
{
Expand All @@ -596,8 +596,8 @@ global define string get_archive_script_parameters(string file_list, string file

y2debug("nfsmount: %1, archive_name: %2", nfsmount, archive_name);

archive_options = archive_options + " --archive-name " + ((target_type == `file) ? archive_name :
sformat("%1/%2", nfsmount, archive_name));
archive_options = archive_options + " --archive-name '" + String::Quote((target_type == `file) ? archive_name :
sformat("%1/%2", nfsmount, archive_name)) + "'";

if (system)
{
Expand Down
9 changes: 7 additions & 2 deletions src/functions.ycp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import "FileUtils";
import "Mode";
import "FileUtils";
import "Directory";
import "String";

textdomain "backup";

Expand Down Expand Up @@ -944,6 +945,9 @@ printf (\"%d%02d%02d%02d%02d%02d\", $year, $mon, $mday, $hour, $min, $sec);'");
return server + ":" + share + slash + filename;
}

define string quote(string var) {
return mergestring(splitstring(var, "\""), "\\\\\"");
}

/**
* Get available space in the directory
Expand All @@ -960,12 +964,13 @@ printf (\"%d%02d%02d%02d%02d%02d\", $year, $mon, $mday, $hour, $min, $sec);'");
return $[];
}

map result = (map)SCR::Execute(.target.bash_output, "/bin/df -P " + directory);
string cmd = "/bin/df -P \"" + quote(directory) + "\"";
map result = (map)SCR::Execute(.target.bash_output, cmd);
integer exit = result["exit"]:-1;

if (exit != 0)
{
y2warning("Command df failed, exit: %1", exit);
y2warning("Command %1 failed, exit: %2", cmd, exit);
return $[];
}

Expand Down
18 changes: 10 additions & 8 deletions src/scripts/backup_archive.pl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use File::Temp qw( tempdir );
use POSIX qw( strftime );
use File::Path qw(make_path);

# command line options
my $archive_name = '';
Expand Down Expand Up @@ -75,9 +76,9 @@ ($)
{
my $dirs = substr($f, 0, $ix);
if ($verbose) {
print "Running: /bin/mkdir -p $dirs 2> /dev/null\n";
print "Running: make_path $dirs\n";
}
system("/bin/mkdir -p $dirs 2> /dev/null"); # create directory with parents
make_path($dirs);
}
}

Expand Down Expand Up @@ -218,7 +219,7 @@ ($)
}

my $tmp_dir_root = tempdir($temp_dir."/backup_tmp_XXXXXXXX", CLEANUP => 1); # remove directory content at exit
system("/bin/mkdir -p '$tmp_dir_root'");
system("/bin/mkdir -p $tmp_dir_root");
if (! -d $tmp_dir_root) {
die "Cannot create directory $tmp_dir_root: ".$!;
}
Expand Down Expand Up @@ -736,7 +737,8 @@ ($)
}

my $num_string = sprintf("%02d", $volume_num);
$tar_command .= " -M -V 'YaST2 backup:' -f $output_directory/${num_string}_$output_filename";
my $out_filename = "$output_directory/${num_string}_$output_filename";
$tar_command .= " -M -V 'YaST2 backup:' -f '".qq($out_filename)."'";

if ($multi_volume > 0)
{
Expand Down Expand Up @@ -803,16 +805,16 @@ ($)
else
{
# create standard (no multi volume) archive
$tar_command .= " -f $archive_name 2> /dev/null)";

$archive_name =~ s/\'/\'\\\'\'/g;
$tar_command .= " -f '$archive_name')";
print "Tar command: $tar_command\n";

system($tar_command);
}

print STDERR $!."\n";

if ($verbose)
{
print "/Tar result: $?\n";
}


2 changes: 2 additions & 0 deletions src/ui.ycp
Original file line number Diff line number Diff line change
Expand Up @@ -2827,6 +2827,8 @@ Aborting the backup.
{
if (substring(line, 0, size(id_tar_exit)) == id_tar_exit)
{
y2milestone ("Tar exit: %1\nErr: %2", line, SCR::Read (.process.read_stderr, backup_PID));

tar_result = tointeger(substring(line, size(id_tar_exit)));
}
else
Expand Down

0 comments on commit ae90295

Please sign in to comment.