file-attr-restore and dollar signs

Aaron Morris aaronwmorris at gmail.com
Thu Aug 31 17:17:31 GMT 2006


On 8/31/06, Pat Hooper <wphooper at 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 at gmail.com>


More information about the rsync mailing list