Spaces In Source
EricMountain 2004 September 4:
Here's a patch for another problem I hit setting up my home PC backups: I needed to backup some data from my Windoze partition, but the directories had spaces in their names. Dirvish doesn't like that too much, but it seems trivial to fix...
@@ -416,8 +416,9 @@
$$Options{Expire} = 'Never';
}
-($srctree, $aliastree) = split(/\s+/, $$Options{tree})
+($srctree, $aliastree) = split(/[^\\]\s+/, $$Options{tree})
or seppuku 228, "ERROR: no source tree defined";
+$srctree =~ s(\\ )( )g;
$srctree =~ s(/+$)();
$aliastree =~ s(/+$)();
$aliastree ||= $srctree;
@@ -530,10 +531,13 @@
printf SUMMARY "%s: %s\n", 'Backup-begin', strftime('%Y-%m-%d %H:%M:%S', localtime);
+$env_srctree = $srctree;
+$env_srctree =~ s/ /\\ /g;
+
$WRAPPER_ENV = sprintf (" %s=%s" x 5,
'DIRVISH_SERVER', $$Options{Server},
'DIRVISH_CLIENT', $$Options{client},
- 'DIRVISH_SRC', $srctree,
+ 'DIRVISH_SRC', $env_srctree,
'DIRVISH_DEST', $destree,
'DIRVISH_IMAGE', join(':',
$$Options{vault},Basically, this patch simply makes sure that the "tree" option read in from the config files allows the use of spaces protected by a backslash in the source tree name (a "bare" whitespace character then separates the source tree and - optional - alias), and that the DIRVISH_SRC value is set with spaces again protected by backslashes in normal shell convention.
NB - This patch only changes Dirvish's behaviour for the source tree.
Keith Lofstrom adds on 2006 Nov 10:
RFried pointed out that there is a problem with this modification - it deletes the last character of the source tree for a "srctree aliastree" pair of directories.
Instead, we can do this:
}
-($srctree, $aliastree) = split(/\s+/, $$Options{tree})
- or seppuku 228, "ERROR: no source tree defined";
-$srctree =~ s(/+$)();
-$aliastree =~ s(/+$)();
+$_ = $$Options{tree} ;
+s/(\s)/\\$1/g; #replace all whitespace chars with '\char'
+s/\\\\//g; #replace all \\ with nothing, now the separator is '\ '
+s/(\\\s)+/$1/g; #replace multiple separators with only one
+($srctree,$aliastree) = split /\\\s+/
+ or seppuku 228, "ERROR: no source tree defined";
$aliastree ||= $srctree;Yes, it is a cheesy hack :-/ .
The first two lines of our substitutions swap escaped whitespace for non-escaped whitespace; this makes the two (or more) fields look like they will in the end, while the field separator is a string of one or more escaped whitespace characters.
The third line replaces multiple field separators with single field separators. We then do a split on the now-single field separator, keep the first two fields, and throw away the rest. This should duplicate the original desired behavior when there are two or more fields, but allow us to escape white space characters in the fields. It also allows escaping whitespace characters at the end of a field, if for some twisted reason somebody wants to name a directory with spaces on the end.
