jedrichards/rsyncwrapper

Order of include exclude

Opened this issue · 4 comments

I am having trouble using exclude and include. What I want to do is copy everything from the webroot folder except the webroot/scss folder.

I can do it from the commandline like

rsync . user@host:/path/to.files --rsh ssh --recursive --dry-run --verbose --exclude="webroot/scss" --include="webroot/***" --exclude="*"

But I cannot figure out how to do it using rsyncwrapper since include[] always comes before exclude[].
For now I am doing this as a workaround

options: {
    recursive: true,
    src: ".",
    args: ["--exclude=webroot/scss", "--include=webroot/***", "--exclude=*"],
    dryRun: true,
    dest: "/path/to/files",
    host: "user@host.com",
}

Would it make sense to allow something like

excludeFirst=[],
include=[].
exclude=[]

Or is there some clever way to write the include/exclude rules to make it work as is?

With rsync everything is included by default. You choose what to exclude from that, while overriding specific excludes with some includes. Afaiu this is the pattern that's enabled by having includes come before excludes when we build the rsync command.

There's been some discussion about this before #16

Not sure why you're setting the src directory to . when you only want to copy the contents of webroot? Could some variation on options like this do what you're after?

options: {
    recursive: true,
    src: "webroot/",
    exclude: ["scss"],
    dryRun: true,
    dest: "/path/to/files",
    host: "user@host.com",
}

I might be misunderstanding though! Let me know how you get on, will be happy to merge your PR if it genuinely scratches an itch.

So my real problem is that I have:

base 
 |-- bower_components
 |-- config
 |-- node_modules
 |-- tmp
 |-- vendor
 +-- webroot
      |-- scss
      +-- img

I want to copy config, webroot, and vendor folders but nothing else.

I could write this as

rsync base dest --exclude=tmp/ --exclude=node_modules/ --exclude=bower_components/  --exclude=webroot/scss/

But then I have to always maintain a list of what I don't want. If I add a secrets folder and forget about this it will be transferred by deafult.

I can do this as three separate rsync operations:

rsync base/config dest/config
rsync base/vendor dest/config
rsync base/webroot dest/webroot --exclude=scss/

which may be a fine solution in my case but doesn't scale.

I don't really understand all the intricacies of rsync patterns, but it seems like include is only useful if you also have exclude=*. And once you include something there is no way exclude it. So if I --include=webroot --exclude=*, I cannot get rid of webroot/scss. Which is how I got to the need to say --exclude=webroot/scss --include=webroot --exclude=*.

I understand the desire to keep the wrapper simple (and have the options map directly to real rsync options), but IMO this is a real itch if you want to do non-trivial rsync operations.

This would address #13 also.

Aha, ok. I think I see what you're saying now. You want to be able to define a whitelist of things to include, while excluding everything else, with the added complication of excluding some sub paths.

Have you looked into the --filter arg? I'm not sure, but it might provide a more idiomatic way of handling the above.

That said, your PR looks good (thanks for the docs and tests!), so I'll merge it right away. Cheers!