diff options
author | Tao Wang <twang2218@gmail.com> | 2017-01-04 06:26:27 +0300 |
---|---|---|
committer | Benjamin Drung <benjamin.drung@profitbricks.com> | 2017-01-06 19:28:58 +0300 |
commit | 15ad1b7cc2bce683de74dfcfff35b1aa64d66d05 (patch) | |
tree | 0a6de65aea5fee314e5382653980f862990a865e | |
parent | e56928ef36ff04d328e4eecf268f04679b1e426e (diff) |
Add support for quoted variables with spaces
* Add support for quoted variables with spaces
* Add new function quoted_path to quote and escape the path.
* Change the system() call to system COMMAND LIST to handle
the spaces in path or argument cases.
fixes #43, #67
Signed-off-by: Tao Wang <twang2218@gmail.com>
Signed-off-by: Benjamin Drung <benjamin.drung@profitbricks.com>
-rwxr-xr-x | apt-mirror | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -201,6 +201,13 @@ sub get_variable return $value; } +sub quoted_path +{ + my $path = shift; + $path =~ s/'/'\\''/g; + return "'" . $path . "'"; +} + sub lock_aptmirror { open( LOCK_FILE, '>', get_variable("var_path") . "/apt-mirror.lock" ); @@ -294,10 +301,12 @@ sub parse_config_line $config{'arch'} = $+{arch}; } $config{'components'} = [ split /\s+/, $config{'components'} ]; - } elsif ( $line =~ /set[\t ]+(?<key>[^\s]+)[\t ]+(?<value>[^\s]+)/ ) { + } elsif ( $line =~ /set[\t ]+(?<key>[^\s]+)[\t ]+(?<value>"[^"]+"|'[^']+'|[^\s]+)/ ) { $config{'type'} = 'set'; $config{'key'} = $+{key}; $config{'value'} = $+{value}; + $config{'value'} =~ s/^'(.*)'$/$1/; + $config{'value'} =~ s/^"(.*)"$/$1/; } elsif ( $line =~ /(?<type>clean|skip-clean)[\t ]+(?<uri>[^\s]+)/ ) { $config{'type'} = $+{type}; $config{'uri'} = $+{uri}; @@ -999,7 +1008,7 @@ else print CLEAN "#!/bin/sh\n"; print CLEAN "set -e\n\n"; - print CLEAN "cd " . get_variable("mirror_path") . "\n\n"; + print CLEAN "cd " . quoted_path(get_variable("mirror_path")) . "\n\n"; print CLEAN "echo 'Removing $total unnecessary files [$size_output]...'\n"; foreach (@rm_files) { @@ -1038,11 +1047,11 @@ if ( get_variable("run_postmirror") ) print "(" . get_variable("postmirror_script") . ")\n\n"; if ( -x get_variable("postmirror_script") ) { - system( get_variable("postmirror_script") ); + system( get_variable("postmirror_script"), '' ); } else { - system( '/bin/sh ' . get_variable("postmirror_script") ); + system( '/bin/sh', get_variable("postmirror_script") ); } print "\nPost Mirror script has completed. See above output for any possible errors.\n\n"; } |