Edwin Olson
2004-Apr-14 23:36 UTC
Another feature proposal and implementation plan: --strip-prefix
Here's another feature I'd like to have: Suppose you're copying a source file /a/b/c/d/e/f/g/h/myfile and you want it stored on some other filesystem /backup, but you want the source path to be truncated so that the file actually ends up as: /backup/h/myfile. This comes up (in particular) when doing backups of windows machines via cygwin; you end up with a phony base directory /cygdrive/. When users go to see their backups, they become confused! This option would eliminate this problem. I'd like to add this behavior, similar to the patch -p option. I'm uncertain whether the syntax should be --strip-prefix=/a/b/c/d/e/f/g, or --strip-prefix=7. The former would allow us to detect situations in which we were being asked to copy files that did not have the expected prefix and to complain loudly (or silently ignore the strip prefix directive for that file?) The latter would be more like patch -p, but I think it's less safe. Perhaps multiple --strip-prefix directives should be allowed so that a single invocation of rsync can handle more complicated situations. I think this can be relatively cleanly implemented in recv_files; in fact, the line "fnamecmp=fname;" in reciever.c seems to be exactly the hook required. Like my previous email, I would like to ask for advice and suggestions so that my implementation will be most useful! Thanks, -Ed
Jim Salter
2004-Apr-14 23:44 UTC
Another feature proposal and implementation plan: --strip-prefix
Wouldn't it be easier just to create a softlink on the cygwin machine so that you could access C: from /c ? Or for that matter, if these are easily-confused Windows users, just begin the Samba (or other SMB) share south of the cygwin/ on the rsync machine?> Here's another feature I'd like to have: > > Suppose you're copying a source file /a/b/c/d/e/f/g/h/myfile and you > want it stored on some other filesystem /backup, but you want the source > path to be truncated so that the file actually ends up as: > /backup/h/myfile. > > This comes up (in particular) when doing backups of windows machines via > cygwin; you end up with a phony base directory /cygdrive/. When users go > to see their backups, they become confused! This option would eliminate > this problem. > > I'd like to add this behavior, similar to the patch -p option. > > I'm uncertain whether the syntax should be > --strip-prefix=/a/b/c/d/e/f/g, or --strip-prefix=7. The former would > allow us to detect situations in which we were being asked to copy files > that did not have the expected prefix and to complain loudly (or > silently ignore the strip prefix directive for that file?) The latter > would be more like patch -p, but I think it's less safe. Perhaps > multiple --strip-prefix directives should be allowed so that a single > invocation of rsync can handle more complicated situations. > > I think this can be relatively cleanly implemented in recv_files; in > fact, the line "fnamecmp=fname;" in reciever.c seems to be exactly the > hook required. Like my previous email, I would like to ask for advice > and suggestions so that my implementation will be most useful! > > Thanks, > > -Ed >
Wayne Davison
2004-Apr-14 23:53 UTC
Another feature proposal and implementation plan: --strip-prefix
On Wed, Apr 14, 2004 at 07:36:23PM -0400, Edwin Olson wrote:> Suppose you're copying a source file /a/b/c/d/e/f/g/h/myfile and you > want it stored on some other filesystem /backup, but you want the source > path to be truncated so that the file actually ends up as: /backup/h/myfile.(I'm assuming that you're using the --relative option, or you wouldn't be having this issue.) If you're pushing dirs, do a chdir before calling rsync and then copy a relative path: cd /a/b/c/d/e/f/g rsync -avR h/myfile remote:/backup If you're pushing OR pulling, you can accomplish the same thing using --files-from: echo h/myfile | rsync -av --files-from=- remote:/a/b/c/d/e/f/g /backup With --files-from, the source path specifies the default dir, and the --relative option is on by default, so you'd end up with your desired result. ..wayne..