Hi All, I've been using the great file-attr-restore script with rsync to get around problems with uid's on a portable hard drive... It's the perfect solution for me. (for those that haven't seen it,you can get it here: http://samba.org/ftp/unpacked/rsync/support/file-attr-restore ) Anyway, I found a small bug in the script. file-attr-restore fails for file names with dollar signs. You might ask "why would you want to put a dollar sign in a file name?" The answer is you wouldn't, but Java creates these sorts of files when you compile a class that has inner classes (eg files like "outer$inner.class") I created a little bash script that illustrates the problem: ---------------------------------------- #!/bin/bash touch 'a$b' chmod og-rw a?b echo "State 0:" ls -l a?b # save permissions state to file echo `find . -name "a?b" -ls` > findout # change permissions chmod a+rw a?b echo "State 1:" ls -l a?b # attempt to restore echo "Attempting to restore original permissions:" file-attr-restore -p findout echo "Results:" ls -l a?b ---------------------------------------- It is probably an easy fix, but I don't know any perl. (Maybe I'll try anyway) I was curious if this is a known bug... I couldn't find anything on rsync's bug list. But perhaps, there is a newer version out there. Best, Pat -------------- next part -------------- HTML attachment scrubbed and removed
On 8/31/06, Pat Hooper <wphooper@gmail.com> wrote:> Hi All, > > I've been using the great file-attr-restore script with rsync to get around > problems with uid's on a portable hard drive... It's the perfect solution > for me. > > (for those that haven't seen it,you can get it here: > http://samba.org/ftp/unpacked/rsync/support/file-attr-restore > ) > > Anyway, I found a small bug in the script. file-attr-restore fails for file > names with dollar signs. You might ask "why would you want to put a dollar > sign in a file name?" The answer is you wouldn't, but Java creates these > sorts of files when you compile a class that has inner classes (eg files > like "outer$inner.class") > > I created a little bash script that illustrates the problem: > ---------------------------------------- > #!/bin/bash > touch 'a$b' > chmod og-rw a?b > echo "State 0:" > ls -l a?b > > # save permissions state to file > echo `find . -name "a?b" -ls` > findout > # change permissions > chmod a+rw a?b > > echo "State 1:" > ls -l a?b > > # attempt to restore > echo "Attempting to restore original permissions:" > file-attr-restore -p findout > echo "Results:" > ls -l a?b > ---------------------------------------- > > It is probably an easy fix, but I don't know any perl. (Maybe I'll try > anyway) > > I was curious if this is a known bug... I couldn't find anything on rsync's > bug list. But perhaps, there is a newer version out there. > > Best, > Pat >I believe the problem you are having is not a bug with the script, but a problem with the way the shell script is being called. If you run: file-attr-restore foo$bar the shell will replace $bar with the contents of the $bar shell variable. If $bar is empty, it would run "file-attr-restore foo". To get around this you need to either enclose the filename in quotes so the shell does not glob it, or turn off globbing in the shell. ie file-attr-restore "foo$bar" or set -o noglob (this is for bash) -- Aaron W Morris (decep) <aaronwmorris@gmail.com>
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') {
Reasonably Related Threads
- Clarification on Linux CD or DVD Writing
- Problems accessing shares with dollar signs
- Huge number
- Useradd doesn't accept dollar sign ($) and "add machine script" doesn't work
- RAID, temperature and FAN status manage and monitoring tool for RHEL4 Update 4 ia64 AS Linux