file-attr-restore and dollar signs

Wayne Davison wayned at samba.org
Thu Aug 31 20:31:14 GMT 2006


On Thu, Aug 31, 2006 at 09:50:50AM -0500, Pat Hooper wrote:
> Anyway, I found a small bug in the script. file-attr-restore fails for file
> names with dollar signs.

Yeah, you're right.  The code uses an eval of a string in double quotes
in order to get all the normal perl decoding, such a \f, \033, and \".
However, it needs to escape '$', '@', and '%' to prevent perl from
treating those characters as variable references.  (Hopefully there is
not anything else that needs to be backslashed-escaped.)

..wayne..
-------------- next part --------------
--- file-attr-restore	21 Mar 2006 18:06:26 -0000	1.1
+++ file-attr-restore	31 Aug 2006 20:29:19 -0000
@@ -47,7 +47,9 @@ while (<>) {
     my($type, $perms, $owner, $group, $name) = /$detail_line/;
     die "Invalid input line $.:\n$_" unless defined $name;
     die "A filename is not properly escaped:\n$_" unless $name =~ /^[^"\\]*(\\(\d\d\d|\D)[^"\\]*)*$/;
-    my $fn = eval "\"$name\"";
+    my $fn = $name;
+    $fn =~ s/([\$\@\%])/\\$1/g;
+    $fn = eval "\"$fn\"";
     if ($type eq '-') {
 	undef $type unless -f $fn;
     } elsif ($type eq 'd') {


More information about the rsync mailing list